VLC 4.0.0-dev

The latch is a downward counter used to synchronise threads. More...

Collaboration diagram for Latches:

Data Structures

struct  vlc_latch_t
 Latch. More...
 

Functions

void vlc_latch_init (vlc_latch_t *, size_t value)
 Initializes a latch. More...
 
void vlc_latch_count_down (vlc_latch_t *, size_t n)
 Decrements the value of a latch. More...
 
void vlc_latch_count_down_and_wait (vlc_latch_t *, size_t n)
 Decrements the value of a latch and waits on it. More...
 
bool vlc_latch_is_ready (const vlc_latch_t *latch)
 Checks if a latch is ready. More...
 
void vlc_latch_wait (vlc_latch_t *)
 Waits on a latch. More...
 

Detailed Description

The latch is a downward counter used to synchronise threads.

Function Documentation

◆ vlc_latch_count_down()

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.

Warning
If the result is (arithmetically) strictly negative, the behaviour is undefined.
Parameters
nquantity to subtract from the latch value (typically 1)
Note
This function is not a cancellation point.

References vlc_latch_count_down_ready().

◆ vlc_latch_count_down_and_wait()

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.

Warning
If the result is strictly negative, the behaviour is undefined.
Parameters
nnumber of times to decrement the value (typically 1)
Note
This function may be a cancellation point.

References vlc_latch_count_down_ready(), and vlc_latch_wait().

◆ vlc_latch_init()

void vlc_latch_init ( vlc_latch_t latch,
size_t  value 
)

Initializes a latch.

Parameters
valueinitial latch value (typically 1)

References vlc_latch_t::ready, vlc_latch_t::value, vlc_cond_waiter::value, VLC_LATCH_PENDING, and VLC_LATCH_READY.

◆ vlc_latch_is_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.

Return values
falseif the latch value is non-zero
trueif the latch value equals zero

References vlc_latch_t::ready, and VLC_LATCH_READY.

Referenced by vlc_latch_wait().

◆ 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.

Note
This function may be a point of cancellation.

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().