VLC 4.0.0-dev

The semaphore is the simplest thread synchronization primitive, consisting of a simple counter. More...

Collaboration diagram for Semaphores:

Data Structures

struct  vlc_sem_t
 Semaphore. More...
 

Functions

void vlc_sem_init (vlc_sem_t *, unsigned count)
 Initializes a semaphore. More...
 
int vlc_sem_post (vlc_sem_t *)
 Increments the value of a semaphore. More...
 
void vlc_sem_wait (vlc_sem_t *)
 Waits on a semaphore. More...
 
int vlc_sem_trywait (vlc_sem_t *sem)
 Tries to decrement a semaphore. More...
 
int vlc_sem_timedwait (vlc_sem_t *sem, vlc_tick_t deadline)
 Waits on a semaphore within a deadline. More...
 

Detailed Description

The semaphore is the simplest thread synchronization primitive, consisting of a simple counter.

See also POSIX sem_t .

Function Documentation

◆ vlc_sem_init()

void vlc_sem_init ( vlc_sem_t sem,
unsigned  count 
)

Initializes a semaphore.

Parameters
countinitial semaphore value (typically 0)

References vlc_sem_t::value, and vlc_cond_waiter::value.

Referenced by TaskNew(), TsStart(), vlc_getaddrinfo_i11e(), and vlc_mta_acquire().

◆ vlc_sem_post()

int vlc_sem_post ( vlc_sem_t sem)

Increments the value of a semaphore.

Note
This function is not a cancellation point.
Returns
0 on success, EOVERFLOW in case of integer overflow.

References unlikely, vlc_sem_t::value, and vlc_atomic_notify_one().

Referenced by Interrupt(), MtaMainLoop(), OnParserEnded(), TsStop(), vlc_gai_thread(), vlc_getaddrinfo_notify(), vlc_interrupt_sem(), and vlc_mta_release().

◆ vlc_sem_timedwait()

int vlc_sem_timedwait ( vlc_sem_t sem,
vlc_tick_t  deadline 
)

Waits on a semaphore within a deadline.

This function waits for the semaphore just like vlc_sem_wait(), but only up to a given deadline.

Parameters
semsemaphore to wait for
deadlinedeadline to wait until
Return values
0the semaphore was decremented
ETIMEDOUTthe deadline was reached

References likely, vlc_sem_t::value, and vlc_atomic_timedwait().

Referenced by Parse(), and TsRun().

◆ vlc_sem_trywait()

int vlc_sem_trywait ( vlc_sem_t sem)

Tries to decrement a semaphore.

This function decrements the semaphore if its value is not zero.

Parameters
semsemaphore to decrement
Return values
0the semaphore was decremented
EAGAINthe semaphore was zero and could not be decremented

References vlc_sem_t::value.

Referenced by TsRun().

◆ vlc_sem_wait()

void vlc_sem_wait ( vlc_sem_t sem)

Waits on a semaphore.

This function atomically waits for the semaphore to become non-zero then decrements it, and returns. If the semaphore is non-zero on entry, it is immediately decremented.

Note
This function may be a point of cancellation.

References likely, vlc_sem_t::value, and vlc_atomic_wait().

Referenced by MtaMainLoop(), Parse(), vlc_getaddrinfo_i11e(), vlc_mta_acquire(), and vlc_sem_wait_i11e().