VLC 4.0.0-dev
Loading...
Searching...
No Matches

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

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
latchan initialized latch
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
latchan initialized latch
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
latcha latch instance
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().