Typedefs | Functions
mutex.h File Reference

Mutex and condition variables. More...

Typedefs

typedef struct vtm_mutex vtm_mutex
 
typedef struct vtm_cond vtm_cond
 

Functions

VTM_API vtm_mutex * vtm_mutex_new (void)
 
VTM_API void vtm_mutex_free (vtm_mutex *mtx)
 
VTM_API void vtm_mutex_lock (vtm_mutex *mtx)
 
VTM_API void vtm_mutex_unlock (vtm_mutex *mtx)
 
VTM_API vtm_cond * vtm_cond_new (void)
 
VTM_API void vtm_cond_free (vtm_cond *cond)
 
VTM_API void vtm_cond_wait (vtm_cond *cond, vtm_mutex *mtx)
 
VTM_API void vtm_cond_signal (vtm_cond *cond)
 
VTM_API void vtm_cond_signal_all (vtm_cond *cond)
 

Function Documentation

VTM_API vtm_mutex* vtm_mutex_new ( void  )

Creates a new mutex.

Returns
a mutex handle
NULL if an error occured
VTM_API void vtm_mutex_free ( vtm_mutex *  mtx)

Releases the mutex handle and all allocates resources.

Parameters
mtxthe mutex which should be released
VTM_API void vtm_mutex_lock ( vtm_mutex *  mtx)

Locks the given mutex.

This call may block when the mutex is already locked by another thread.

Parameters
mtxthe mutex which should be locked
VTM_API void vtm_mutex_unlock ( vtm_mutex *  mtx)

Unlocks the given mutex.

Parameters
mtxthe mutex which should be unlocked
VTM_API vtm_cond* vtm_cond_new ( void  )

Creates a new condition variable.

Returns
a condition variable handle
NULL if an error occured
VTM_API void vtm_cond_free ( vtm_cond *  cond)

Releases the condition variable and all allocates resources.

Parameters
condthe condition variable which should be released
VTM_API void vtm_cond_wait ( vtm_cond *  cond,
vtm_mutex *  mtx 
)

Wait until given condition variable is signaled.

The mutex must be already locked by the current thread when this method is called. The mutex is unlocked while waiting and is re-locked when the call returns.

Due to spurious wakeups on some platforms, the condition should always be checked again after this call has returned.

Parameters
condthe condition variable on which the wait is performed
mtxthe mutex which is used
VTM_API void vtm_cond_signal ( vtm_cond *  cond)

Wakes up one thread that is waiting on this condition variable.

Parameters
condthe condition variable which should be signaled
VTM_API void vtm_cond_signal_all ( vtm_cond *  cond)

Wakes up all threads that are waiting on this condition.

Parameters
condthe condition variable which should be signaled