Mstdlib-1.24.0
Thread Mutexes (Locks/Critical Sections)

Typedefs

typedef struct M_thread_mutex M_thread_mutex_t
 

Enumerations

enum  M_thread_mutexattr_t {
  M_THREAD_MUTEXATTR_NONE = 0 ,
  M_THREAD_MUTEXATTR_RECURSIVE = 1 << 0
}
 

Functions

M_thread_mutex_tM_thread_mutex_create (M_uint32 attr)
 
void M_thread_mutex_destroy (M_thread_mutex_t *mutex)
 
M_bool M_thread_mutex_lock (M_thread_mutex_t *mutex)
 
M_bool M_thread_mutex_trylock (M_thread_mutex_t *mutex)
 
M_bool M_thread_mutex_unlock (M_thread_mutex_t *mutex)
 

Detailed Description

Thread Mutexes (Locks/Critical Sections)

Typedef Documentation

◆ M_thread_mutex_t

typedef struct M_thread_mutex M_thread_mutex_t

Enumeration Type Documentation

◆ M_thread_mutexattr_t

Mutex attributes. Used for mutex creation.

Enumerator
M_THREAD_MUTEXATTR_NONE 

None.

M_THREAD_MUTEXATTR_RECURSIVE 

Mutex is recursive.

Function Documentation

◆ M_thread_mutex_create()

M_thread_mutex_t * M_thread_mutex_create ( M_uint32  attr)

Mutex create.

Parameters
[in]attrM_thread_mutexattr_t attributes which control how the mutex should behave.
Returns
Mutex on success otherwise NULL on error.

◆ M_thread_mutex_destroy()

void M_thread_mutex_destroy ( M_thread_mutex_t mutex)

Destroy a mutex.

Parameters
[in]mutexThe mutex.

◆ M_thread_mutex_lock()

M_bool M_thread_mutex_lock ( M_thread_mutex_t mutex)

Lock a mutex.

This will block until the mutex can be locked.

Parameters
[in]mutexThe mutex.
Returns
M_TRUE if the function returns due to a successful mutex lock. Otherwise M_FALSE on error. This can fail for a number of reasons, for example:
  • The mutex was already locked by this thread.
  • The mutex is invalid.
  • The mutex has exceeded the maximum number of recursive locks.

◆ M_thread_mutex_trylock()

M_bool M_thread_mutex_trylock ( M_thread_mutex_t mutex)

Try to lock the mutex.

Does not block waiting to lock the mutex.

Parameters
[in]mutexThe mutex.
Returns
M_TRUE if the mutex was locked. Otherwise M_FALSE.

◆ M_thread_mutex_unlock()

M_bool M_thread_mutex_unlock ( M_thread_mutex_t mutex)

Unlock a locked mutex.

Parameters
[in]mutexThe mutex.
Returns
M_TRUE if the mutex was unlocked. Otherwise M_FALSE.