VLC  4.0.0-dev
Data Structures | Functions

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

VLC_EXPORT void vlc_sem_init (vlc_sem_t *, unsigned count)
 Initializes a semaphore. More...
 
VLC_EXPORT int vlc_sem_post (vlc_sem_t *)
 Increments the value of a semaphore. More...
 
VLC_EXPORT void vlc_sem_wait (vlc_sem_t *)
 Waits on a semaphore. More...
 
VLC_EXPORT int vlc_sem_trywait (vlc_sem_t *sem)
 Tries to decrement a semaphore. More...
 
VLC_EXPORT 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()

VLC_EXPORT void vlc_sem_init ( vlc_sem_t ,
unsigned  count 
)

Initializes a semaphore.

Parameters
countinitial semaphore value (typically 0)

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

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

◆ vlc_sem_post()

VLC_EXPORT int vlc_sem_post ( vlc_sem_t )

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 MtaMainLoop(), TsStop(), vlc_gai_thread(), vlc_getaddrinfo_notify(), vlc_interrupt_sem(), and vlc_mta_release().

◆ vlc_sem_timedwait()

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

◆ vlc_sem_trywait()

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

VLC_EXPORT void vlc_sem_wait ( vlc_sem_t )

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(), vlc_getaddrinfo_i11e(), vlc_mta_acquire(), and vlc_sem_wait_i11e().