rte_rwlock.h(3)
π rte_rwlock.h π
okay so bestie, welcome to the read-write lock era of DPDK π this one lives in the Library Functions Manual (section 3), so buckle up, we're doing library functions today π
πΈ NAME πΈ
rte_rwlock.h β no cap, that's the whole name, she's just out here being a header file and slaying π¦
β¨ SYNOPSIS β¨
First things first, you gotta invite the whole friend group in:
#include <errno.h>
#include <stdbool.h>
#include <rte_branch_prediction.h>
#include <rte_common.h>
#include <rte_lock_annotations.h>
#include <rte_pause.h>
#include <rte_stdatomic.h>
π Macros
#define RTE_RWLOCK_WAIT 0x1 /* Writer is waiting */#define RTE_RWLOCK_INITIALIZER { 0 }
π«Ά Functions
static void rte_rwlock_init (rte_rwlock_t *rwl)static void rte_rwlock_read_lock (rte_rwlock_t *rwl)β__rte_no_thread_safety_analysisstatic int rte_rwlock_read_trylock (rte_rwlock_t *rwl) rwl)β__rte_no_thread_safety_analysisstatic void rte_rwlock_read_unlock (rte_rwlock_t *rwl)β__rte_no_thread_safety_analysisstatic int rte_rwlock_write_trylock (rte_rwlock_t *rwl) rwl)β__rte_no_thread_safety_analysisstatic void rte_rwlock_write_lock (rte_rwlock_t *rwl)β__rte_no_thread_safety_analysisstatic void rte_rwlock_write_unlock (rte_rwlock_t *rwl)β__rte_no_thread_safety_analysisstatic int rte_rwlock_write_is_locked (rte_rwlock_t *rwl)static void rte_rwlock_read_lock_tm (rte_rwlock_t *rwl)static void rte_rwlock_read_unlock_tm (rte_rwlock_t *rwl)static void rte_rwlock_write_lock_tm (rte_rwlock_t *rwl)static void rte_rwlock_write_unlock_tm (rte_rwlock_t *rwl)
π Detailed Description π
RTE Read-Write Locks
So this file defines an API for read-write locks πβοΈ The lock protects data that lets multiple readers go in parallel, but only one writer at a time. All the readers get blocked until the writer is done writing. It's giving "everybody can look, but only one person gets to touch the whiteboard marker" energy π
This version does not give preference to readers or writers, and it doesn't starve either readers or writers. Truly egalitarian, truly fair, truly main character π
Also see: https://locklessinc.com/articles/locks/ π
Definition in file rte_rwlock.h.
π Macro Definition Documentation π
π #define RTE_RWLOCK_WAIT 0x1 /* Writer is waiting */
This is the rte_rwlock_t type, bestie.
Readers increment the counter by RTE_RWLOCK_READ (4). Writers set the RTE_RWLOCK_WRITE bit when the lock is held, and set the RTE_RWLOCK_WAIT bit while waiting.
Look at this little bit layout, she's so organized:
31 2 1 0
+-------------------+-+-+
| readers | | |
+-------------------+-+-+
^ ^
| |
WRITE: lock held |
WAIT: writer pending
(iykyk β that's the WRITE bit pointing at slot 1 and the WAIT bit pointing at slot 0, with readers holding down the rest of the byte π§)
Definition at line 55 of file rte_rwlock.h.
β¨ #define RTE_RWLOCK_INITIALIZER { 0 }
A static rwlock initializer. Set it and forget it, no function call needed π
Definition at line 68 of file rte_rwlock.h.
π Function Documentation π
π¦ void rte_rwlock_init (rte_rwlock_t * rwl) [inline], [static]
Initialize the rwlock to an unlocked state. Fresh start, clean slate, new semester energy β¨
Parameters
rwlβ A pointer to the rwlock structure.
Definition at line 77 of file rte_rwlock.h.
πΈ void rte_rwlock_read_lock (rte_rwlock_t * rwl) [inline], [static]
Take a read lock. Loop until the lock is held. She will wait for you, she's patient like that π«Ά
Note: The RW lock isn't recursive, so calling this function on the same lock twice without releasing it could potentially result in a deadlock scenario when a write lock is involved. π So like, don't do that. Not twice on the same lock without unlocking. That's the rule fr fr.
Parameters
rwlβ A pointer to a rwlock structure.
Definition at line 93 of file rte_rwlock.h.
π
int rte_rwlock_read_trylock (rte_rwlock_t * rwl) [inline], [static]
Try to take a read lock. Try being the key word, bestie β she's not gonna wait around π
Parameters
rwlβ A pointer to a rwlock structure.
Returns
- zero if the lock is successfully taken π
-EBUSYif lock could not be acquired for reading because a writer holds the lock π
Definition at line 130 of file rte_rwlock.h.
π void rte_rwlock_read_unlock (rte_rwlock_t * rwl) [inline], [static]
Release a read lock. Let her go, she's free π
Parameters
rwlβ A pointer to the rwlock structure.
Definition at line 163 of file rte_rwlock.h.
β int rte_rwlock_write_trylock (rte_rwlock_t * rwl) [inline], [static]
Try to take a write lock. Shoot your shot, but she might say no β
Parameters
rwlβ A pointer to a rwlock structure.
Returns
- zero if the lock is successfully taken π
-EBUSYif lock could not be acquired for writing because it was already locked for reading or writing π₯²
Definition at line 181 of file rte_rwlock.h.
π void rte_rwlock_write_lock (rte_rwlock_t * rwl) [inline], [static]
Take a write lock. Loop until the lock is held. Committed. Devoted. Will not leave until she's got it π
Parameters
rwlβ A pointer to a rwlock structure.
Definition at line 203 of file rte_rwlock.h.
π§ void rte_rwlock_write_unlock (rte_rwlock_t * rwl) [inline], [static]
Release a write lock. Hand the marker back, someone else's turn π§
Parameters
rwlβ A pointer to a rwlock structure.
Definition at line 241 of file rte_rwlock.h.
π int rte_rwlock_write_is_locked (rte_rwlock_t * rwl) [inline], [static]
Test if the write lock is taken. Just a little vibe check, no commitment π
Parameters
rwlβ A pointer to a rwlock structure.
Returns
1 if the write lock is currently taken; 0 otherwise.
Definition at line 257 of file rte_rwlock.h.
π₯ void rte_rwlock_read_lock_tm (rte_rwlock_t * rwl) [inline], [static]
Try to execute the critical section in a hardware memory transaction, and if it fails or isn't available, take a read lock. Plan A is the fancy hardware thing, plan B is the regular read lock π₯
NOTE: An attempt to perform a HW I/O operation inside a hardware memory transaction always aborts the transaction, since the CPU is not able to roll-back should the transaction fail. Therefore, hardware transactional locks are not advised to be used aroundrte_eth_rx_burst()andrte_eth_tx_burst()calls. β οΈ Seriously, don't. She said what she said.
Parameters
rwlβ A pointer to a rwlock structure.
π void rte_rwlock_read_unlock_tm (rte_rwlock_t * rwl) [inline], [static]
Commit the hardware memory transaction, or release the read lock if the lock is being used as a fall-back. Two paths, one function, iconic behavior π
Parameters
rwlβ A pointer to the rwlock structure.
π void rte_rwlock_write_lock_tm (rte_rwlock_t * rwl) [inline], [static]
Try to execute the critical section in a hardware memory transaction, and if it fails or isn't available, take a write lock. Same deal as her read-lock twin, just with write energy π
NOTE: An attempt to perform a HW I/O operation inside a hardware memory transaction always aborts the transaction, since the CPU is not able to roll-back should the transaction fail. Therefore, hardware transactional locks are not advised to be used aroundrte_eth_rx_burst()andrte_eth_tx_burst()calls. β οΈ Yes, again. It's that serious.
Parameters
rwlβ A pointer to a rwlock structure.
π void rte_rwlock_write_unlock_tm (rte_rwlock_t * rwl) [inline], [static]
Commit the hardware memory transaction, or release the write lock if the lock is being used as a fall-back. Same vibe, write edition π
Parameters
rwlβ A pointer to a rwlock structure.
π Author π
Generated automatically by Doxygen for DPDK from the source code. (Not a human, just a very diligent little robot. Respect the hustle π€π«Ά)
and that's the whole page bestie!! πβ¨ this was DPDK, Version 25.11.3, dated on the page as rte_rwlock.h(3) β periodt π
π
π¦ where this page comes from
- ubuntu resolute: dpdk-doc 25.11.3-0ubuntu0.26.04.1 Β· BSD-3-Clause
- ubuntu stonking: dpdk-doc 25.11.3-1 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms