Data Structures | Functions
latch.h File Reference

Thread synchronisation helper. More...

Data Structures

struct  vtm_latch
 

Functions

VTM_API int vtm_latch_init (struct vtm_latch *latch, unsigned int count)
 
VTM_API void vtm_latch_release (struct vtm_latch *latch)
 
VTM_API void vtm_latch_count (struct vtm_latch *latch)
 
VTM_API void vtm_latch_await (struct vtm_latch *latch)
 

Function Documentation

VTM_API int vtm_latch_init ( struct vtm_latch latch,
unsigned int  count 
)

Initializes a new latch.

Parameters
latchpointer to the latch, can be on stack or heap
countinitial counter of the latch
Returns
VTM_OK when the latch was successfully initialized
VTM_ERROR when the latch could not be initialized
VTM_API void vtm_latch_release ( struct vtm_latch latch)

Releases all resources of the given latch

Parameters
latchthe latch which should be released
VTM_API void vtm_latch_count ( struct vtm_latch latch)

Decrements the latch counter by one.

If the counter reaches zero, all threads waiting in vtm_latch_await() are released and continue their execution.

Parameters
latchthe target latch
VTM_API void vtm_latch_await ( struct vtm_latch latch)

Waits until the latch counter reaches zero.

Parameters
latchthe target latch