Veritable Lasagna
An Allocator & Data Structure Library for C.
Loading...
Searching...
No Matches
vl_mutex.h File Reference
#include "vl_numtypes.h"
+ Include dependency graph for vl_mutex.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define VL_MUTEX_NULL   0
 
#define vlMutexObtain(mutex)   vlMutexObtainExclusive(mutex)
 
#define vlMutexRelease(mutex)   vlMutexReleaseExclusive(mutex)
 Releases an exclusive lock on the specified mutex.
 

Typedefs

typedef vl_uintptr_t vl_mutex
 Mutex handle.
 

Functions

vl_mutex vlMutexNew ()
 Creates a new instance of a mutex.
 
void vlMutexDelete (vl_mutex mutex)
 Deletes the specified mutex.
 
void vlMutexObtainShared (vl_mutex mutex)
 Obtain a shared lock on the specified mutex.
 
vl_bool_t vlMutexTryObtainShared (vl_mutex mutex)
 Attempts to obtain a shared lock from the specified mutex.
 
void vlMutexReleaseShared (vl_mutex mutex)
 Releases a shared lock on the specified mutex.
 
void vlMutexObtainExclusive (vl_mutex mutex)
 Obtains an exclusive lock on the specified mutex.
 
vl_bool_t vlMutexTryObtainExclusive (vl_mutex mutex)
 Attempts to obtain an exclusive lock on the specified mutex.
 
void vlMutexReleaseExclusive (vl_mutex mutex)
 Releases an exclusive lock on the specified mutex.
 

Macro Definition Documentation

◆ VL_MUTEX_NULL

#define VL_MUTEX_NULL   0

◆ vlMutexObtain

#define vlMutexObtain ( mutex)    vlMutexObtainExclusive(mutex)

◆ vlMutexRelease

#define vlMutexRelease ( mutex)    vlMutexReleaseExclusive(mutex)

Releases an exclusive lock on the specified mutex.

Parameters
mutex

Typedef Documentation

◆ vl_mutex

Mutex handle.

In Veritable Lasagna, Mutexes are defined as Read-Write locks. They offer both "shared" and "exclusive" modes; the former is usable for read operations, while the latter is suitable for write operations.

If the mutex is locked in "shared" mode, other areas of code are permitted to read whatever shared resource. In "exclusive" mode, the behavior is identical to that of a typical mutex: anything trying to obtain the lock in either shared or exclusive mode must wait for its availability.

If trying to obtain an exclusive lock while other thread(s) have already obtained shared locks, the exclusive lock must wait until all other shared locks are released.

Function Documentation

◆ vlMutexDelete()

void vlMutexDelete ( vl_mutex mutex)

Deletes the specified mutex.

Warning
Be certain the mutex is no longer obtained by the time this function is called.

◆ vlMutexNew()

vl_mutex vlMutexNew ( )

Creates a new instance of a mutex.

Note
May return VL_MUTEX_NULL on failure.
Returns
mutex handle

◆ vlMutexObtainExclusive()

void vlMutexObtainExclusive ( vl_mutex mutex)

Obtains an exclusive lock on the specified mutex.

Only a single thread may obtain an exclusive lock at any given time. This is more suitable for write operations.

Parameters
mutex

◆ vlMutexObtainShared()

void vlMutexObtainShared ( vl_mutex mutex)

Obtain a shared lock on the specified mutex.

Multiple threads may obtain a shared lock at any given time. This is more suitable for concurrent read operations.

Parameters
mutex

◆ vlMutexReleaseExclusive()

void vlMutexReleaseExclusive ( vl_mutex mutex)

Releases an exclusive lock on the specified mutex.

Parameters
mutex

◆ vlMutexReleaseShared()

void vlMutexReleaseShared ( vl_mutex mutex)

Releases a shared lock on the specified mutex.

Parameters
mutex

◆ vlMutexTryObtainExclusive()

vl_bool_t vlMutexTryObtainExclusive ( vl_mutex mutex)

Attempts to obtain an exclusive lock on the specified mutex.

Note
This function is non-blocking.
Parameters
mutex
Returns
a boolean indicating whether or not the lock was obtained.

◆ vlMutexTryObtainShared()

vl_bool_t vlMutexTryObtainShared ( vl_mutex mutex)

Attempts to obtain a shared lock from the specified mutex.

Note
This function is non-blocking.
Parameters
mutex
Returns
a boolean indicating whether or not the shared lock was obtained