PatchworkOS
Loading...
Searching...
No Matches

Ticket spinlock. More...

Data Structures

struct  lock_t
 A simple ticket lock implementation. More...
 

Macros

#define LOCK_DEADLOCK_ITERATIONS   1000000
 Number of iterations before we consider a deadlock has occurred in lock_acquire. This is only used in debug builds.
 
#define LOCK_CANARY   0xDEADBEEF
 Lock canary value to detect memory corruption.
 
#define LOCK_SCOPE(lock)
 Acquires a lock for the reminder of the current scope.
 
#define LOCK_CREATE   (lock_t){.nextTicket = ATOMIC_VAR_INIT(0), .nowServing = ATOMIC_VAR_INIT(0), .canary = 0xDEADBEEF}
 Create a lock initializer. @macro LOCK_CREATE.
 

Functions

static void lock_init (lock_t *lock)
 Initializes a lock.
 
static void lock_acquire (lock_t *lock)
 Acquires a lock, blocking until it is available.
 
static void lock_release (lock_t *lock)
 Releases a lock.
 
static void lock_cleanup (lock_t **lock)
 

Detailed Description

Ticket spinlock.

Macro Definition Documentation

◆ LOCK_CANARY

#define LOCK_CANARY   0xDEADBEEF

Lock canary value to detect memory corruption.

Definition at line 30 of file lock.h.

◆ LOCK_CREATE

#define LOCK_CREATE   (lock_t){.nextTicket = ATOMIC_VAR_INIT(0), .nowServing = ATOMIC_VAR_INIT(0), .canary = 0xDEADBEEF}

Create a lock initializer. @macro LOCK_CREATE.

Definition at line 66 of file lock.h.

◆ LOCK_DEADLOCK_ITERATIONS

#define LOCK_DEADLOCK_ITERATIONS   1000000

Number of iterations before we consider a deadlock has occurred in lock_acquire. This is only used in debug builds.

Definition at line 25 of file lock.h.

◆ LOCK_SCOPE

#define LOCK_SCOPE (   lock)
Value:
__attribute__((cleanup(lock_cleanup))) lock_t* CONCAT(l, __COUNTER__) = (lock); \
lock_acquire((lock))
#define CONCAT(a, b)
Concatenates two tokens.
Definition defs.h:76
static void lock_cleanup(lock_t **lock)
Definition lock.h:153
static rwlock_t lock
Definition irq.c:10
A simple ticket lock implementation.
Definition lock.h:43

Acquires a lock for the reminder of the current scope.

Parameters
lockPointer to the lock to acquire.

Definition at line 57 of file lock.h.

Function Documentation

◆ lock_acquire()

static void lock_acquire ( lock_t lock)
inlinestatic

◆ lock_cleanup()

static void lock_cleanup ( lock_t **  lock)
inlinestatic

Definition at line 153 of file lock.h.

References lock, and lock_release().

◆ lock_init()

◆ lock_release()