VLC 4.0.0-dev
No Matches

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


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

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.

sema semaphore to initialize
countinitial semaphore value (typically 0)

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

Referenced by vlc::threads::semaphore::semaphore(), vlc::threads::semaphore::semaphore(), 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.

This function is not a cancellation point.
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(), vlc::threads::semaphore::post(), 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.

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.

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.

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(), vlc_sem_wait_i11e(), and vlc::threads::semaphore::wait().