]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/sync_sema.h
737edfd476b824b5a7f2a8aba5dd6e289e97bf3f
[apple/xnu.git] / osfmk / kern / sync_sema.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * @OSF_COPYRIGHT@
25 *
26 */
27 /*
28 * File: kern/sync_sema.h
29 * Author: Joseph CaraDonna
30 *
31 * Contains RT distributed semaphore synchronization service definitions.
32 */
33
34 #ifndef _KERN_SYNC_SEMA_H_
35 #define _KERN_SYNC_SEMA_H_
36
37 #include <kern/kern_types.h>
38 #include <mach/sync_policy.h>
39
40 #ifdef MACH_KERNEL_PRIVATE
41
42 #include <kern/queue.h>
43 #include <kern/lock.h>
44 #include <kern/wait_queue.h>
45
46 typedef struct semaphore {
47 queue_chain_t task_link; /* chain of semaphores owned by a task */
48 struct wait_queue wait_queue; /* queue of blocked threads & lock */
49 task_t owner; /* task that owns semaphore */
50 ipc_port_t port; /* semaphore port */
51 int ref_count; /* reference count */
52 int count; /* current count value */
53 boolean_t active; /* active status */
54 } Semaphore;
55
56 #define semaphore_lock(semaphore) wait_queue_lock(&(semaphore)->wait_queue)
57 #define semaphore_unlock(semaphore) wait_queue_unlock(&(semaphore)->wait_queue)
58
59 extern void semaphore_init(void);
60
61 extern void semaphore_reference (semaphore_t semaphore);
62 extern void semaphore_dereference (semaphore_t semaphore);
63
64 #endif /* MACH_KERNEL_PRIVATE */
65
66 #endif /* _KERN_SYNC_SEMA_H_ */