Lines Matching refs:sema
158 static void DRD_(sema_init)(DrdSema* sema);
159 static void DRD_(sema_destroy)(DrdSema* sema);
160 static void DRD_(sema_down)(DrdSema* sema);
161 static void DRD_(sema_up)(DrdSema* sema);
182 static void DRD_(sema_init)(DrdSema* sema)
184 DRD_IGNORE_VAR(sema->counter);
185 pthread_mutex_init(&sema->mutex, NULL);
186 sema->counter = 0;
187 sema->waiters = 0;
190 static void DRD_(sema_destroy)(DrdSema* sema)
192 pthread_mutex_destroy(&sema->mutex);
195 static void DRD_(sema_down)(DrdSema* sema)
199 pthread_mutex_lock(&sema->mutex);
200 if (sema->counter == 0) {
201 sema->waiters++;
202 while (sema->counter == 0) {
203 pthread_mutex_unlock(&sema->mutex);
205 if (syscall(__NR_futex, (UWord)&sema->counter,
219 pthread_mutex_lock(&sema->mutex);
221 sema->waiters--;
223 sema->counter--;
224 pthread_mutex_unlock(&sema->mutex);
227 static void DRD_(sema_up)(DrdSema* sema)
229 pthread_mutex_lock(&sema->mutex);
230 sema->counter++;
232 if (sema->waiters > 0)
233 syscall(__NR_futex, (UWord)&sema->counter,
236 pthread_mutex_unlock(&sema->mutex);