VLC 4.0.0-dev
|
The latch is a downward counter used to synchronise threads. More...
Data Structures | |
struct | vlc_latch_t |
Latch. More... | |
Functions | |
void | vlc_latch_init (vlc_latch_t *latch, size_t value) |
Initializes a latch. | |
void | vlc_latch_count_down (vlc_latch_t *latch, size_t n) |
Decrements the value of a latch. | |
void | vlc_latch_count_down_and_wait (vlc_latch_t *latch, size_t n) |
Decrements the value of a latch and waits on it. | |
bool | vlc_latch_is_ready (const vlc_latch_t *latch) |
Checks if a latch is ready. | |
void | vlc_latch_wait (vlc_latch_t *) |
Waits on a latch. | |
The latch is a downward counter used to synchronise threads.
void vlc_latch_count_down | ( | vlc_latch_t * | latch, |
size_t | n | ||
) |
Decrements the value of a latch.
This function atomically decrements the value of a latch by the given quantity. If the result is zero, then any thread waiting on the latch is woken up.
latch | an initialized latch |
n | quantity to subtract from the latch value (typically 1) |
References vlc_latch_count_down_ready().
void vlc_latch_count_down_and_wait | ( | vlc_latch_t * | latch, |
size_t | n | ||
) |
Decrements the value of a latch and waits on it.
This function atomically decrements the value of a latch by the given quantity. Then, if the result of the subtraction is strictly positive, it waits until the value reaches zero.
This function is equivalent to the succession of vlc_latch_count_down() then vlc_latch_wait(), and is only an optimisation to combine the two.
latch | an initialized latch |
n | number of times to decrement the value (typically 1) |
References vlc_latch_count_down_ready(), and vlc_latch_wait().
void vlc_latch_init | ( | vlc_latch_t * | latch, |
size_t | value | ||
) |
Initializes a latch.
latch | a latch instance |
value | initial latch value (typically 1) |
References vlc_latch_t::ready, vlc_latch_t::value, vlc_cond_waiter::value, VLC_LATCH_PENDING, and VLC_LATCH_READY.
bool vlc_latch_is_ready | ( | const vlc_latch_t * | latch | ) |
Checks if a latch is ready.
This function compares the value of a latch with zero.
false | if the latch value is non-zero |
true | if the latch value equals zero |
References vlc_latch_t::ready, and VLC_LATCH_READY.
Referenced by vlc_latch_wait().
void vlc_latch_wait | ( | vlc_latch_t * | latch | ) |
Waits on a latch.
This function waits until the value of the latch reaches zero.
References vlc_latch_t::ready, vlc_atomic_wait(), VLC_LATCH_CONTEND, vlc_latch_is_ready(), VLC_LATCH_PENDING, and VLC_LATCH_READY.
Referenced by vlc_latch_count_down_and_wait().