PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
Read-Write Ticket Lock

Read-Write Ticket Lock. More...

Collaboration diagram for Read-Write Ticket Lock:

Detailed Description

Read-Write Ticket Lock.

Data Structures

struct  rwlock_t
 Read-Write Ticket Lock structure. More...
 

Macros

#define RWLOCK_DEADLOCK_ITERATIONS   10000000
 Number of iterations before we consider a deadlock to have occurred in a rwlock operation. This is only used in debug builds.
 
#define RWLOCK_READ_SCOPE(lock)
 Acquires a rwlock for reading for the reminder of the current scope.
 
#define RWLOCK_WRITE_SCOPE(lock)
 Acquires a rwlock for writing for the reminder of the current scope.
 
#define RWLOCK_CREATE()
 Create a rwlock initializer.
 

Functions

void rwlock_init (rwlock_t *lock)
 Initializes a rwlock.
 
void rwlock_read_acquire (rwlock_t *lock)
 Acquires a rwlock for reading, blocking until it is available.
 
void rwlock_read_release (rwlock_t *lock)
 Releases a rwlock from reading.
 
void rwlock_write_acquire (rwlock_t *lock)
 Acquires a rwlock for writing, blocking until it is available.
 
void rwlock_write_release (rwlock_t *lock)
 Releases a rwlock from writing.
 
static void rwlock_read_cleanup (rwlock_t **lock)
 
static void rwlock_write_cleanup (rwlock_t **lock)
 

Macro Definition Documentation

◆ RWLOCK_DEADLOCK_ITERATIONS

#define RWLOCK_DEADLOCK_ITERATIONS   10000000

Number of iterations before we consider a deadlock to have occurred in a rwlock operation. This is only used in debug builds.

Definition at line 22 of file rwlock.h.

◆ RWLOCK_READ_SCOPE

#define RWLOCK_READ_SCOPE (   lock)
Value:
__attribute__((cleanup(rwlock_read_cleanup))) rwlock_t* CONCAT(rl, __COUNTER__) = (lock); \
rwlock_read_acquire((lock))
#define CONCAT(a, b)
Concatenates two tokens.
Definition defs.h:76
static void rwlock_read_cleanup(rwlock_t **lock)
Definition rwlock.h:105
static lock_t lock
Definition io.c:13
Read-Write Ticket Lock structure.
Definition rwlock.h:61

Acquires a rwlock for reading for the reminder of the current scope.

Parameters
lockPointer to the rwlock to acquire.

Definition at line 29 of file rwlock.h.

◆ RWLOCK_WRITE_SCOPE

#define RWLOCK_WRITE_SCOPE (   lock)
Value:
__attribute__((cleanup(rwlock_write_cleanup))) rwlock_t* CONCAT(wl, __COUNTER__) = (lock); \
rwlock_write_acquire((lock))
static void rwlock_write_cleanup(rwlock_t **lock)
Definition rwlock.h:110

Acquires a rwlock for writing for the reminder of the current scope.

Parameters
lockPointer to the rwlock to acquire.

Definition at line 38 of file rwlock.h.

◆ RWLOCK_CREATE

#define RWLOCK_CREATE ( )
Value:
{ \
.readTicket = ATOMIC_VAR_INIT(0), .readServe = ATOMIC_VAR_INIT(0), .writeTicket = ATOMIC_VAR_INIT(0), \
.writeServe = ATOMIC_VAR_INIT(0), .activeReaders = ATOMIC_VAR_INIT(0), .activeWriter = ATOMIC_VAR_INIT(false) \
}
#define ATOMIC_VAR_INIT(value)
Definition stdatomic.h:74

Create a rwlock initializer.

Returns
A rwlock_t initializer.

Definition at line 47 of file rwlock.h.

Function Documentation

◆ rwlock_init()

void rwlock_init ( rwlock_t lock)

Initializes a rwlock.

Parameters
lockPointer to the rwlock to initialize.

Definition at line 8 of file rwlock.c.

Here is the caller graph for this function:

◆ rwlock_read_acquire()

void rwlock_read_acquire ( rwlock_t lock)

Acquires a rwlock for reading, blocking until it is available.

Parameters
lockPointer to the rwlock to acquire.

Definition at line 18 of file rwlock.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rwlock_read_release()

void rwlock_read_release ( rwlock_t lock)

Releases a rwlock from reading.

Parameters
lockPointer to the rwlock to release.

Definition at line 54 of file rwlock.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rwlock_write_acquire()

void rwlock_write_acquire ( rwlock_t lock)

Acquires a rwlock for writing, blocking until it is available.

Parameters
lockPointer to the rwlock to acquire.

Definition at line 62 of file rwlock.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rwlock_write_release()

void rwlock_write_release ( rwlock_t lock)

Releases a rwlock from writing.

Parameters
lockPointer to the rwlock to release.

Definition at line 109 of file rwlock.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rwlock_read_cleanup()

static void rwlock_read_cleanup ( rwlock_t **  lock)
inlinestatic

Definition at line 105 of file rwlock.h.

Here is the call graph for this function:

◆ rwlock_write_cleanup()

static void rwlock_write_cleanup ( rwlock_t **  lock)
inlinestatic

Definition at line 110 of file rwlock.h.

Here is the call graph for this function: