CNDP  22.08.0
cne_spinlock.h File Reference
#include <unistd.h>
#include <cne_cpuflags.h>
#include <cne_cycles.h>
#include <cne_branch_prediction.h>
#include <cne_common.h>
#include <cne_gettid.h>
#include <cne_system.h>
#include <cne_pause.h>
#include <cne_rtm.h>

Go to the source code of this file.

Data Structures

struct  cne_spinlock_t
 
struct  cne_spinlock_recursive_t
 

Macros

#define CNE_SPINLOCK_INITIALIZER
 
#define CNE_SPINLOCK_RECURSIVE_INITIALIZER
 

Functions

static void cne_spinlock_init (cne_spinlock_t *sl)
 
static int cne_spinlock_is_locked (cne_spinlock_t *sl)
 
static void cne_spinlock_recursive_init (cne_spinlock_recursive_t *slr)
 
static void cne_spinlock_recursive_lock (cne_spinlock_recursive_t *slr)
 
static void cne_spinlock_recursive_unlock (cne_spinlock_recursive_t *slr)
 
static int cne_spinlock_recursive_trylock (cne_spinlock_recursive_t *slr)
 

Detailed Description

CNE Spinlocks

This file defines an API for read-write locks, which are implemented in an architecture-specific way. This kind of lock simply waits in a loop repeatedly checking until the lock becomes available.

All locks must be initialised before use, and only initialised once.

Definition in file cne_spinlock.h.

Macro Definition Documentation

◆ CNE_SPINLOCK_INITIALIZER

#define CNE_SPINLOCK_INITIALIZER
Value:
{ \
0 \
}

A static spinlock initializer.

Definition at line 50 of file cne_spinlock.h.

◆ CNE_SPINLOCK_RECURSIVE_INITIALIZER

#define CNE_SPINLOCK_RECURSIVE_INITIALIZER
Value:
{ \
CNE_SPINLOCK_INITIALIZER, -1, 0 \
}

A static recursive spinlock initializer.

Definition at line 192 of file cne_spinlock.h.

Function Documentation

◆ cne_spinlock_init()

static void cne_spinlock_init ( cne_spinlock_t sl)
inlinestatic

Initialize the spinlock to an unlocked state.

Parameters
slA pointer to the spinlock.

Definition at line 62 of file cne_spinlock.h.

◆ cne_spinlock_is_locked()

static int cne_spinlock_is_locked ( cne_spinlock_t sl)
inlinestatic

Test if the lock is taken.

Parameters
slA pointer to the spinlock.
Returns
1 if the lock is currently taken; 0 otherwise.

Definition at line 175 of file cne_spinlock.h.

◆ cne_spinlock_recursive_init()

static void cne_spinlock_recursive_init ( cne_spinlock_recursive_t slr)
inlinestatic

Initialize the recursive spinlock to an unlocked state.

Parameters
slrA pointer to the recursive spinlock.

Definition at line 204 of file cne_spinlock.h.

◆ cne_spinlock_recursive_lock()

static void cne_spinlock_recursive_lock ( cne_spinlock_recursive_t slr)
inlinestatic

Take the recursive spinlock.

Parameters
slrA pointer to the recursive spinlock.

Definition at line 218 of file cne_spinlock.h.

◆ cne_spinlock_recursive_unlock()

static void cne_spinlock_recursive_unlock ( cne_spinlock_recursive_t slr)
inlinestatic

Release the recursive spinlock.

Parameters
slrA pointer to the recursive spinlock.

Definition at line 235 of file cne_spinlock.h.

◆ cne_spinlock_recursive_trylock()

static int cne_spinlock_recursive_trylock ( cne_spinlock_recursive_t slr)
inlinestatic

Try to take the recursive lock.

Parameters
slrA pointer to the recursive spinlock.
Returns
1 if the lock is successfully taken; 0 otherwise.

Definition at line 252 of file cne_spinlock.h.