Lines Matching defs:semaphore

36  *	Contains RT distributed semaphore synchronization services.
42 #include <mach/semaphore.h>
103 semaphore_t semaphore,
138 * Initialize the semaphore mechanisms.
139 * Right now, we only need to initialize the semaphore zone.
144 semaphore_zone = zinit(sizeof(struct semaphore),
145 semaphore_max * sizeof(struct semaphore),
146 sizeof(struct semaphore),
154 * Creates a semaphore.
155 * The port representing the semaphore is returned as a parameter.
192 * Create and initialize the semaphore port
203 * Associate the new semaphore with the task by adding
204 * the new semaphore to the task's semaphore list.
206 * Associate the task with the new semaphore by having the
224 * Destroys a semaphore. This call will only succeed if the
225 * specified task is the SAME task name specified at the semaphore's
228 * All threads currently blocked on the semaphore are awoken. These
234 semaphore_t semaphore)
240 if (task == TASK_NULL || semaphore == SEMAPHORE_NULL)
244 * Disown semaphore
247 if (semaphore->owner != task) {
251 remqueue((queue_entry_t) semaphore);
252 semaphore->owner = TASK_NULL;
257 semaphore_lock(semaphore);
260 * Deactivate semaphore
262 assert(semaphore->active);
263 semaphore->active = FALSE;
268 old_count = semaphore->count;
269 semaphore->count = 0;
272 wait_queue_wakeup64_all_locked(&semaphore->wait_queue,
277 semaphore_unlock(semaphore);
284 * Drop the task's semaphore reference, which in turn deallocates
285 * the semaphore structure if the reference count goes to zero.
287 semaphore_dereference(semaphore);
294 * Signals the semaphore as direct.
300 semaphore_t semaphore,
308 semaphore_lock(semaphore);
310 if (!semaphore->active) {
311 semaphore_unlock(semaphore);
317 if (semaphore->count < 0) {
319 &semaphore->wait_queue,
325 semaphore_unlock(semaphore);
333 int old_count = semaphore->count;
336 semaphore->count = 0; /* always reset */
338 &semaphore->wait_queue,
344 semaphore->count++;
345 semaphore_unlock(semaphore);
352 if (semaphore->count < 0) {
354 &semaphore->wait_queue,
358 semaphore_unlock(semaphore);
362 semaphore->count = 0; /* all waiters gone */
366 semaphore->count++;
369 semaphore_unlock(semaphore);
377 * If the specified thread is blocked on the semaphore, it is
380 * and the semaphore is unchanged.
384 semaphore_t semaphore,
389 if (semaphore == SEMAPHORE_NULL)
392 ret = semaphore_signal_internal(semaphore,
409 semaphore_t semaphore;
416 * pre-post the semaphore.
425 kr = port_name_to_semaphore(sema_name, &semaphore);
427 kr = semaphore_signal_internal(semaphore,
430 semaphore_dereference(semaphore);
443 * Traditional (in-kernel client and MIG interface) semaphore
453 semaphore_t semaphore)
457 if (semaphore == SEMAPHORE_NULL)
460 kr = semaphore_signal_internal(semaphore,
485 semaphore_t semaphore;
488 kr = port_name_to_semaphore(sema_name, &semaphore);
490 kr = semaphore_signal_internal(semaphore,
493 semaphore_dereference(semaphore);
503 * Awakens ALL threads currently blocked on the semaphore.
504 * The semaphore count returns to zero.
508 semaphore_t semaphore)
512 if (semaphore == SEMAPHORE_NULL)
515 kr = semaphore_signal_internal(semaphore,
533 semaphore_t semaphore;
536 kr = port_name_to_semaphore(sema_name, &semaphore);
538 kr = semaphore_signal_internal(semaphore,
541 semaphore_dereference(semaphore);
551 * Generate the return code after a semaphore wait/block. It
602 * Decrements the semaphore count by one. If the count is
608 * A reference is held on the signal semaphore.
655 * lock the signal semaphore reference we got and signal it.
667 * Uh!Oh! The semaphore we were to signal died.
670 * that the semaphore we were posting is gating
672 * semaphore we are waiting on). People will
673 * discover the other dead semaphore soon enough.
690 * return now that we have signalled the signal semaphore.
698 * appropriate semaphore continuation. Thiswill gather the
699 * semaphore results, release references on the semaphore(s),
722 * in-kernel clients to wait on a semaphore.
726 semaphore_t semaphore)
729 if (semaphore == SEMAPHORE_NULL)
732 return(semaphore_wait_internal(semaphore,
740 semaphore_t semaphore)
743 if (semaphore == SEMAPHORE_NULL)
746 return(semaphore_wait_internal(semaphore,
754 semaphore_t semaphore,
758 if (semaphore == SEMAPHORE_NULL)
761 return(semaphore_wait_internal(semaphore,
770 * Trap version of semaphore wait. Called on behalf of user-level
788 semaphore_t semaphore;
791 kr = port_name_to_semaphore(name, &semaphore);
793 kr = semaphore_wait_internal(semaphore,
797 semaphore_dereference(semaphore);
806 * in-kernel clients to wait on a semaphore with a timeout.
812 semaphore_t semaphore,
818 if (semaphore == SEMAPHORE_NULL)
829 return (semaphore_wait_internal(semaphore,
863 semaphore_t semaphore;
872 kr = port_name_to_semaphore(name, &semaphore);
882 kr = semaphore_wait_internal(semaphore,
886 semaphore_dereference(semaphore);
894 * Atomically register a wait on a semaphore and THEN signal
916 * Atomically register a wait on a semaphore and THEN signal
955 * Atomically register a wait on a semaphore and THEN signal
990 * Atomically register a timed wait on a semaphore and THEN signal
1045 * Take out a reference on a semaphore. This keeps the data structure
1046 * in existence (but the semaphore may be deactivated).
1050 semaphore_t semaphore)
1052 (void)hw_atomic_add(&semaphore->ref_count, 1);
1058 * Release a reference on a semaphore. If this is the last reference,
1059 * the semaphore data structure is deallocated.
1063 semaphore_t semaphore)
1067 if (semaphore != NULL) {
1068 ref_count = hw_atomic_sub(&semaphore->ref_count, 1);
1071 ipc_port_t port = semaphore->port;
1074 OSCompareAndSwapPtr(port, IP_NULL, &semaphore->port)) {
1080 ref_count = hw_atomic_sub(&semaphore->ref_count, 1);
1084 assert(wait_queue_empty(&semaphore->wait_queue));
1085 zfree(semaphore_zone, semaphore);