libgpac
Documentation of the core library of GPAC

Semaphore. More...

+ Collaboration diagram for Semaphore:

Typedefs

typedef struct __tag_semaphore GF_Semaphore
 abstracted semaphore object
 

Functions

GF_Semaphoregf_sema_new (u32 MaxCount, u32 InitCount)
 semaphore constructor More...
 
void gf_sema_del (GF_Semaphore *sm)
 semaphore destructor More...
 
Bool gf_sema_notify (GF_Semaphore *sm, u32 nb_rel)
 semaphore notification. More...
 
Bool gf_sema_wait (GF_Semaphore *sm)
 semaphore wait More...
 
Bool gf_sema_wait_for (GF_Semaphore *sm, u32 time_out)
 semaphore time wait More...
 

Detailed Description

The semaphore object allows controlling how portions of the code (typically access to variables) are executed by two threads (or a thread and the main process) at the same time. The best image for a semaphore is a limited set of money coins (always easy to understand hmm?). If no money is in the set, nobody can buy anything until a coin is put back in the set. When the set is full, the money is wasted (call it "the bank"...).

Function Documentation

◆ gf_sema_new()

GF_Semaphore* gf_sema_new ( u32  MaxCount,
u32  InitCount 
)

Constructs a new semaphore object

Parameters
MaxCountthe maximum notification count of this semaphore
InitCountthe initial notification count of this semaphore upon construction
Returns
the semaphore object

◆ gf_sema_del()

void gf_sema_del ( GF_Semaphore sm)

Destructs the semaphore object. This will wait for the semaphore to be released if needed.

Parameters
smthe semaphore object

◆ gf_sema_notify()

Bool gf_sema_notify ( GF_Semaphore sm,
u32  nb_rel 
)

Notifies the semaphore of a certain amount of releases.

Parameters
smthe semaphore object
nb_relsm the number of release to notify
Returns
GF_TRUE if success, GF_FALSE otherwise

◆ gf_sema_wait()

Bool gf_sema_wait ( GF_Semaphore sm)

Waits for the semaphore to be accessible (eg, may wait an infinite time).

Parameters
smthe semaphore object
Returns
GF_TRUE if successful wait, GF_FALSE if wait failed

◆ gf_sema_wait_for()

Bool gf_sema_wait_for ( GF_Semaphore sm,
u32  time_out 
)

Waits for a certain for the semaphore to be accessible, and returns when semaphore is accessible or wait time has passed.

Parameters
smthe semaphore object
time_outthe amount of time to wait for the release in milliseconds
Returns
returns 1 if the semaphore was released before the timeout, 0 if the semaphore is still not released after the timeout.