CNDP  22.08.0
cne_rwlock.h File Reference
#include <cne_branch_prediction.h>
#include <cne_spinlock.h>
#include <cne_common.h>
#include <cne_pause.h>

Go to the source code of this file.

Data Structures

struct  cne_rwlock_t
 

Macros

#define CNE_RWLOCK_INITIALIZER
 

Functions

static void cne_rwlock_init (cne_rwlock_t *rwl)
 
static void cne_rwlock_read_lock (cne_rwlock_t *rwl)
 
static int cne_rwlock_read_trylock (cne_rwlock_t *rwl)
 
static void cne_rwlock_read_unlock (cne_rwlock_t *rwl)
 
static int cne_rwlock_write_trylock (cne_rwlock_t *rwl)
 
static void cne_rwlock_write_lock (cne_rwlock_t *rwl)
 
static void cne_rwlock_write_unlock (cne_rwlock_t *rwl)
 
static void cne_rwlock_read_lock_tm (cne_rwlock_t *rwl)
 
static void cne_rwlock_read_unlock_tm (cne_rwlock_t *rwl)
 
static void cne_rwlock_write_lock_tm (cne_rwlock_t *rwl)
 
static void cne_rwlock_write_unlock_tm (cne_rwlock_t *rwl)
 

Detailed Description

CNE 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.

Definition in file cne_rwlock.h.

Macro Definition Documentation

◆ CNE_RWLOCK_INITIALIZER

#define CNE_RWLOCK_INITIALIZER
Value:
{ \
0 \
}

A static rwlock initializer.

Definition at line 41 of file cne_rwlock.h.

Function Documentation

◆ cne_rwlock_init()

static void cne_rwlock_init ( cne_rwlock_t rwl)
inlinestatic

Initialize the rwlock to an unlocked state.

Parameters
rwlA pointer to the rwlock structure.

Definition at line 53 of file cne_rwlock.h.

◆ cne_rwlock_read_lock()

static void cne_rwlock_read_lock ( cne_rwlock_t rwl)
inlinestatic

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

Parameters
rwlA pointer to a rwlock structure.

Definition at line 65 of file cne_rwlock.h.

◆ cne_rwlock_read_trylock()

static int cne_rwlock_read_trylock ( cne_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 93 of file cne_rwlock.h.

◆ cne_rwlock_read_unlock()

static void cne_rwlock_read_unlock ( cne_rwlock_t rwl)
inlinestatic

Release a read lock.

Parameters
rwlA pointer to the rwlock structure.

Definition at line 117 of file cne_rwlock.h.

◆ cne_rwlock_write_trylock()

static int cne_rwlock_write_trylock ( cne_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 133 of file cne_rwlock.h.

◆ cne_rwlock_write_lock()

static void cne_rwlock_write_lock ( cne_rwlock_t rwl)
inlinestatic

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

Parameters
rwlA pointer to a rwlock structure.

Definition at line 152 of file cne_rwlock.h.

◆ cne_rwlock_write_unlock()

static void cne_rwlock_write_unlock ( cne_rwlock_t rwl)
inlinestatic

Release a write lock.

Parameters
rwlA pointer to a rwlock structure.

Definition at line 176 of file cne_rwlock.h.

◆ cne_rwlock_read_lock_tm()

static void cne_rwlock_read_lock_tm ( cne_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 cne_eth_rx_burst() and cne_eth_tx_burst() calls.

Parameters
rwlA pointer to a rwlock structure.

Definition at line 195 of file cne_rwlock.h.

◆ cne_rwlock_read_unlock_tm()

static void cne_rwlock_read_unlock_tm ( cne_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.

Definition at line 209 of file cne_rwlock.h.

◆ cne_rwlock_write_lock_tm()

static void cne_rwlock_write_lock_tm ( cne_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 cne_eth_rx_burst() and cne_eth_tx_burst() calls.

Parameters
rwlA pointer to a rwlock structure.

Definition at line 231 of file cne_rwlock.h.

◆ cne_rwlock_write_unlock_tm()

static void cne_rwlock_write_unlock_tm ( cne_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.

Definition at line 245 of file cne_rwlock.h.