PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches

Recursive Mutex. More...

Collaboration diagram for Mutex:

Detailed Description

Recursive Mutex.

Data Structures

struct  mutex_t
 Mutex structure. More...
 

Macros

#define MUTEX_SCOPE(mutex)
 Acquires a mutex for the reminder of the current scope.
 
#define MUTEX_CREATE(name)    {.waitQueue = WAIT_QUEUE_CREATE(name.waitQueue), .owner = NULL, .depth = 0, .lock = LOCK_CREATE()}
 Create a mutex initializer.
 

Functions

void mutex_init (mutex_t *mtx)
 Initializes a mutex.
 
void mutex_deinit (mutex_t *mtx)
 Deinitializes a mutex.
 
void mutex_acquire (mutex_t *mtx)
 Acquires a mutex, blocking until it is available.
 
bool mutex_acquire_timeout (mutex_t *mtx, clock_t timeout)
 Acquires a mutex, blocking until it is available or the timeout is reached.
 
void mutex_release (mutex_t *mtx)
 Releases a mutex.
 
static void mutex_cleanup (mutex_t **mtx)
 

Macro Definition Documentation

◆ MUTEX_SCOPE

#define MUTEX_SCOPE (   mutex)
Value:
__attribute__((cleanup(mutex_cleanup))) mutex_t* CONCAT(m, __COUNTER__) = (mutex); \
mutex_acquire((mutex))
#define CONCAT(a, b)
Concatenates two tokens.
Definition defs.h:76
static void mutex_cleanup(mutex_t **mtx)
Definition mutex.h:91
static mtx_t mutex
Definition heap.c:35
Mutex structure.
Definition mutex.h:41

Acquires a mutex for the reminder of the current scope.

Parameters
mutexPointer to the mutex to acquire.

Definition at line 23 of file mutex.h.

◆ MUTEX_CREATE

#define MUTEX_CREATE (   name)     {.waitQueue = WAIT_QUEUE_CREATE(name.waitQueue), .owner = NULL, .depth = 0, .lock = LOCK_CREATE()}

Create a mutex initializer.

Parameters
nameName of the mutex variable.
Returns
A mutex initializer.

Definition at line 33 of file mutex.h.

Function Documentation

◆ mutex_init()

void mutex_init ( mutex_t mtx)

Initializes a mutex.

Parameters
mtxPointer to the mutex to initialize.

Definition at line 14 of file mutex.c.

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

◆ mutex_deinit()

void mutex_deinit ( mutex_t mtx)

Deinitializes a mutex.

Parameters
mtxPointer to the mutex to deinitialize.

Definition at line 22 of file mutex.c.

Here is the call graph for this function:

◆ mutex_acquire()

void mutex_acquire ( mutex_t mtx)

Acquires a mutex, blocking until it is available.

If the mutex is already owned by the current thread, this function will return immediately.

Parameters
mtxPointer to the mutex to acquire.

Definition at line 28 of file mutex.c.

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

◆ mutex_acquire_timeout()

bool mutex_acquire_timeout ( mutex_t mtx,
clock_t  timeout 
)

Acquires a mutex, blocking until it is available or the timeout is reached.

If the mutex is already owned by the current thread, this function will return immediately.

Parameters
mtxPointer to the mutex to acquire.
timeoutTimeout in clock ticks or CLOCKS_NEVER to wait indefinitely.
Returns
true if the mutex was acquired, false if the timeout was reached.

Definition at line 35 of file mutex.c.

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

◆ mutex_release()

void mutex_release ( mutex_t mtx)

Releases a mutex.

The mutex must be owned by the current thread.

Parameters
mtxPointer to the mutex to release.

Definition at line 105 of file mutex.c.

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

◆ mutex_cleanup()

static void mutex_cleanup ( mutex_t **  mtx)
inlinestatic

Definition at line 91 of file mutex.h.

Here is the call graph for this function: