DPDK  24.11.0-rc3
Macros | Functions
rte_rwlock.h File Reference
#include <errno.h>
#include <rte_branch_prediction.h>
#include <rte_common.h>
#include <rte_lock_annotations.h>
#include <rte_pause.h>
#include <rte_stdatomic.h>

Go to the source code of this file.

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_analysis
 
static int rte_rwlock_read_trylock (rte_rwlock_t *rwl) rwl) __rte_no_thread_safety_analysis
 
static void rte_rwlock_read_unlock (rte_rwlock_t *rwl) __rte_no_thread_safety_analysis
 
static int rte_rwlock_write_trylock (rte_rwlock_t *rwl) rwl) __rte_no_thread_safety_analysis
 
static void rte_rwlock_write_lock (rte_rwlock_t *rwl) __rte_no_thread_safety_analysis
 
static void rte_rwlock_write_unlock (rte_rwlock_t *rwl) __rte_no_thread_safety_analysis
 
static 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

This file defines an API for read-write locks. The lock is used to protect data that allows multiple readers in parallel, but only one writer. All readers are blocked until the writer is finished writing.

This version does not give preference to readers or writers and does not starve either readers or writers.

See also: https://locklessinc.com/articles/locks/

Definition in file rte_rwlock.h.

Macro Definition Documentation

◆ RTE_RWLOCK_WAIT

#define RTE_RWLOCK_WAIT   0x1 /* Writer is waiting */

The rte_rwlock_t type.

Readers increment the counter by RTE_RWLOCK_READ (4) Writers set the RTE_RWLOCK_WRITE bit when lock is held and set the RTE_RWLOCK_WAIT bit while waiting.

31 2 1 0 +----------------—+-+-+ | readers | | | +----------------—+-+-+ ^ ^ | | WRITE: lock held -—/ | WAIT: writer pending –/

Definition at line 54 of file rte_rwlock.h.

◆ RTE_RWLOCK_INITIALIZER

#define RTE_RWLOCK_INITIALIZER   { 0 }

A static rwlock initializer.

Definition at line 67 of file rte_rwlock.h.

Function Documentation

◆ rte_rwlock_init()

static void rte_rwlock_init ( rte_rwlock_t *  rwl)
inlinestatic

Initialize the rwlock to an unlocked state.

Parameters
rwlA pointer to the rwlock structure.

Definition at line 76 of file rte_rwlock.h.

◆ rte_rwlock_read_lock()

static void rte_rwlock_read_lock ( rte_rwlock_t *  rwl)
inlinestatic

Take a read lock. Loop until the lock is held.

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.
Parameters
rwlA pointer to a rwlock structure.

Definition at line 92 of file rte_rwlock.h.

◆ rte_rwlock_read_trylock()

static int rte_rwlock_read_trylock ( rte_rwlock_t *  rwl)
inlinestatic

Try to take a read lock.

Parameters
rwlA pointer to a rwlock structure.
Returns
  • zero if the lock is successfully taken
  • -EBUSY if lock could not be acquired for reading because a writer holds the lock

Definition at line 129 of file rte_rwlock.h.

◆ rte_rwlock_read_unlock()

static void rte_rwlock_read_unlock ( rte_rwlock_t *  rwl)
inlinestatic

Release a read lock.

Parameters
rwlA pointer to the rwlock structure.

Definition at line 162 of file rte_rwlock.h.

◆ rte_rwlock_write_trylock()

static int rte_rwlock_write_trylock ( rte_rwlock_t *  rwl)
inlinestatic

Try to take a write lock.

Parameters
rwlA pointer to a rwlock structure.
Returns
  • zero if the lock is successfully taken
  • -EBUSY if lock could not be acquired for writing because it was already locked for reading or writing

Definition at line 180 of file rte_rwlock.h.

◆ rte_rwlock_write_lock()

static void rte_rwlock_write_lock ( rte_rwlock_t *  rwl)
inlinestatic

Take a write lock. Loop until the lock is held.

Parameters
rwlA pointer to a rwlock structure.

Definition at line 202 of file rte_rwlock.h.

◆ rte_rwlock_write_unlock()

static void rte_rwlock_write_unlock ( rte_rwlock_t *  rwl)
inlinestatic

Release a write lock.

Parameters
rwlA pointer to a rwlock structure.

Definition at line 240 of file rte_rwlock.h.

◆ rte_rwlock_write_is_locked()

static int rte_rwlock_write_is_locked ( rte_rwlock_t *  rwl)
inlinestatic

Test if the write lock is taken.

Parameters
rwlA pointer to a rwlock structure.
Returns
1 if the write lock is currently taken; 0 otherwise.

Definition at line 256 of file rte_rwlock.h.

◆ rte_rwlock_read_lock_tm()

static void rte_rwlock_read_lock_tm ( rte_rwlock_t *  rwl)
inlinestatic

Try to execute critical section in a hardware memory transaction, if it fails or not available take a 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 around rte_eth_rx_burst() and rte_eth_tx_burst() calls.

Parameters
rwlA pointer to a rwlock structure.

◆ rte_rwlock_read_unlock_tm()

static void rte_rwlock_read_unlock_tm ( rte_rwlock_t *  rwl)
inlinestatic

Commit hardware memory transaction or release the read lock if the lock is used as a fall-back

Parameters
rwlA pointer to the rwlock structure.

◆ rte_rwlock_write_lock_tm()

static void rte_rwlock_write_lock_tm ( rte_rwlock_t *  rwl)
inlinestatic

Try to execute critical section in a hardware memory transaction, if it fails or not available take a write 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 around rte_eth_rx_burst() and rte_eth_tx_burst() calls.

Parameters
rwlA pointer to a rwlock structure.

◆ rte_rwlock_write_unlock_tm()

static void rte_rwlock_write_unlock_tm ( rte_rwlock_t *  rwl)
inlinestatic

Commit hardware memory transaction or release the write lock if the lock is used as a fall-back

Parameters
rwlA pointer to a rwlock structure.