Lines Matching defs:sem

42 xsem_init(xsem_t *sem, int pshared, unsigned int value)
47 pthread_mutex_init(&sem->semMutex, NULL);
48 pthread_cond_init(&sem->semCV, NULL);
49 sem->semaphore = value;
55 xsem_destroy(xsem_t *sem)
57 pthread_mutex_destroy(&sem->semMutex);
58 pthread_cond_destroy(&sem->semCV);
59 sem->semaphore = 0;
63 xsem_wait(xsem_t *sem)
65 pthread_mutex_lock(&sem->semMutex);
67 if (sem->semaphore < 0) {
68 sem->semaphore = 0;
69 pthread_mutex_unlock(&sem->semMutex);
73 if (sem->semaphore > 0) {
74 sem->semaphore--;
76 while (sem->semaphore == 0)
77 pthread_cond_wait(&sem->semCV, &sem->semMutex);
79 if (sem->semaphore != 0) {
80 sem->semaphore--;
82 pthread_mutex_unlock(&sem->semMutex);
87 pthread_mutex_unlock(&sem->semMutex);
93 xsem_trywait(xsem_t *sem)
95 pthread_mutex_lock(&sem->semMutex);
97 if (sem->semaphore < 0) {
98 sem->semaphore = 0;
99 pthread_mutex_unlock(&sem->semMutex);
103 if (sem->semaphore == 0) {
104 pthread_mutex_unlock(&sem->semMutex);
107 sem->semaphore--;
110 pthread_mutex_unlock(&sem->semMutex);
116 xsem_post(xsem_t *sem)
118 pthread_mutex_lock(&sem->semMutex);
119 sem->semaphore++;
120 pthread_cond_signal(&sem->semCV);
121 pthread_mutex_unlock(&sem->semMutex);
128 xsem_getvalue(xsem_t *sem, int *sval)
130 *sval = sem->semaphore;
136 xsem_xwait(xsem_t *sem, int timeout, timestruc_t *mytime)
142 return (xsem_wait(sem));
144 pthread_mutex_lock(&sem->semMutex);
146 if (sem->semaphore < 0) {
147 sem->semaphore = 0;
148 pthread_mutex_unlock(&sem->semMutex);
152 if (sem->semaphore > 0) {
153 sem->semaphore--;
159 while ((sem->semaphore == 0) && (status == 0)) {
160 status = pthread_cond_timedwait(&sem->semCV,
161 &sem->semMutex, &delay);
170 pthread_mutex_unlock(&sem->semMutex);
172 } else if (sem->semaphore != 0) {
173 sem->semaphore--;
175 pthread_mutex_unlock(&sem->semMutex);
180 pthread_mutex_unlock(&sem->semMutex);