Semaphore.
More...
|
typedef struct __tag_semaphore | GF_Semaphore |
| abstracted semaphore object
|
|
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"...).
◆ gf_sema_new()
Constructs a new semaphore object
- Parameters
-
MaxCount | the maximum notification count of this semaphore |
InitCount | the initial notification count of this semaphore upon construction |
- Returns
- the semaphore object
◆ gf_sema_del()
Destructs the semaphore object. This will wait for the semaphore to be released if needed.
- Parameters
-
◆ gf_sema_notify()
Notifies the semaphore of a certain amount of releases.
- Parameters
-
sm | the semaphore object |
nb_rel | sm the number of release to notify |
- Returns
- GF_TRUE if success, GF_FALSE otherwise
◆ gf_sema_wait()
Waits for the semaphore to be accessible (eg, may wait an infinite time).
- Parameters
-
- Returns
- GF_TRUE if successful wait, GF_FALSE if wait failed
◆ gf_sema_wait_for()
Waits for a certain for the semaphore to be accessible, and returns when semaphore is accessible or wait time has passed.
- Parameters
-
sm | the semaphore object |
time_out | the 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.