libgpac
Documentation of the core library of GPAC

Mutual exclusion. More...

+ Collaboration diagram for Mutex:

Typedefs

typedef struct __tag_mutex GF_Mutex
 abstracted mutex object
 

Functions

GF_Mutexgf_mx_new (const char *name)
 mutex constructor More...
 
void gf_mx_del (GF_Mutex *mx)
 mutex denstructor More...
 
u32 gf_mx_p (GF_Mutex *mx)
 mutex locking More...
 
void gf_mx_v (GF_Mutex *mx)
 mutex unlocking More...
 
Bool gf_mx_try_lock (GF_Mutex *mx)
 mutex non-blocking lock More...
 
s32 gf_mx_get_num_locks (GF_Mutex *mx)
 get mutex number of locks More...
 

Detailed Description

The mutex object allows ensuring that portions of the code (typically access to variables) cannot be executed by two threads (or a thread and the main process) at the same time.

Function Documentation

◆ gf_mx_new()

GF_Mutex* gf_mx_new ( const char *  name)

Contructs a new mutex object

Parameters
namelog name of the thread if any
Returns
new mutex

◆ gf_mx_del()

void gf_mx_del ( GF_Mutex mx)

Destroys a mutex object. This will wait for the mutex to be released if needed.

Parameters
mxthe mutex object, may be NULL

◆ gf_mx_p()

u32 gf_mx_p ( GF_Mutex mx)

Locks the mutex object, making sure that another thread locking this mutex cannot execute until the mutex is unlocked.

Parameters
mxthe mutex object, may be NULL
Returns
1 if success or mutex is NULL, 0 if error locking the mutex (which should never happen)

◆ gf_mx_v()

void gf_mx_v ( GF_Mutex mx)

Unlocks the mutex object, allowing other threads waiting on this mutex to continue their execution

Parameters
mxthe mutex object, may be NULL

◆ gf_mx_try_lock()

Bool gf_mx_try_lock ( GF_Mutex mx)

Attemps to lock the mutex object without blocking until the object is released.

Parameters
mxthe mutex object, may be NULL
Returns
GF_TRUE if the mutex has been successfully locked or if the mutex is NULL, in which case it shall then be unlocked, or GF_FALSE if the mutex is locked by another thread.

◆ gf_mx_get_num_locks()

s32 gf_mx_get_num_locks ( GF_Mutex mx)

Returns the number of locks on the mutex if the caller thread is holding the mutex.

Parameters
mxthe mutex object, may be NULL
Returns
-1 if the mutex is not hold by the calling thread, or the number of locks (possibly 0) otherwise. Returns 0 if mutex is NULL