defs/si_sys/pthrdsem.h File Reference

A portable counting semaphore for pthreads. More...

#include <pthread.h>
#include <si_sys/defs.h>

Go to the source code of this file.

Classes

struct  sc_sem
 A portable counting semaphore for pthreads. More...

Functions

sc_status sc_sem_construct (sc_sem *s, s_int32 initialCount, s_int32 maxCount)
sc_status sc_sem_wait (sc_sem *s)
sc_status sc_sem_trywait (sc_sem *s, s_bool *gotit)
sc_status sc_sem_post (sc_sem *s)
sc_status sc_sem_destruct (sc_sem *s)


Detailed Description

A portable counting semaphore for pthreads.

Lightweight, portable simple counting semaphore for use with pthreads. This exists because Mac OS X does not support anonymous semaphores (sem_init).


Function Documentation

sc_status sc_sem_construct ( sc_sem s,
s_int32  initialCount,
s_int32  maxCount 
)

Constructs semaphore s with a count of initialCount, and a maximum of maxCount.

Note:
To create the semphore initially unavailble, set initialCount to 0.

To create a binary semaphore set maxCount to 1.

sc_status sc_sem_destruct ( sc_sem s  ) 

Destructs the semaphore s.

sc_status sc_sem_post ( sc_sem s  ) 

Releases the semaphore s, incrementing its count, and potentially unblocking a thread waiting in sc_sem_wait.

Parameters:
[in,out] s The semaphore to post (release).

sc_status sc_sem_trywait ( sc_sem s,
s_bool *  gotit 
)

Attempts to acquire semaphore s, but does not block if the semaphore count is 0, returning immediately instead. If the semaphore has been acquired, *gotit is set to seTrue, and seFalse otherwise.

Parameters:
[in,out] s The semaphore to try to acquire.
[out] gotit On exit, seTrue if the semaphore was acquired, seFalse otherwise.

sc_status sc_sem_wait ( sc_sem s  ) 

Attempts to acquire semaphore s, and blocks the calling thread if the semaphore is not available (count is 0).

Parameters:
[in,out] s The semaphore to wait for (acquire).


doxygen