xref: /xnu-11215.61.5/osfmk/mach/semaphore.h (revision 4f1223e81cd707a65cc109d0b8ad6653699da3c4)
1*4f1223e8SApple OSS Distributions /*
2*4f1223e8SApple OSS Distributions  * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
3*4f1223e8SApple OSS Distributions  *
4*4f1223e8SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*4f1223e8SApple OSS Distributions  *
6*4f1223e8SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*4f1223e8SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*4f1223e8SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*4f1223e8SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*4f1223e8SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*4f1223e8SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*4f1223e8SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*4f1223e8SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*4f1223e8SApple OSS Distributions  *
15*4f1223e8SApple OSS Distributions  * Please obtain a copy of the License at
16*4f1223e8SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*4f1223e8SApple OSS Distributions  *
18*4f1223e8SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*4f1223e8SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*4f1223e8SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*4f1223e8SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*4f1223e8SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*4f1223e8SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*4f1223e8SApple OSS Distributions  * limitations under the License.
25*4f1223e8SApple OSS Distributions  *
26*4f1223e8SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*4f1223e8SApple OSS Distributions  */
28*4f1223e8SApple OSS Distributions 
29*4f1223e8SApple OSS Distributions #ifndef _MACH_SEMAPHORE_H_
30*4f1223e8SApple OSS Distributions #define _MACH_SEMAPHORE_H_
31*4f1223e8SApple OSS Distributions 
32*4f1223e8SApple OSS Distributions #include <mach/port.h>
33*4f1223e8SApple OSS Distributions #include <mach/mach_types.h>
34*4f1223e8SApple OSS Distributions #include <mach/kern_return.h>
35*4f1223e8SApple OSS Distributions #include <mach/sync_policy.h>
36*4f1223e8SApple OSS Distributions 
37*4f1223e8SApple OSS Distributions /*
38*4f1223e8SApple OSS Distributions  *	Forward Declarations
39*4f1223e8SApple OSS Distributions  *
40*4f1223e8SApple OSS Distributions  *	The semaphore creation and deallocation routines are
41*4f1223e8SApple OSS Distributions  *	defined with the Mach task APIs in <mach/task.h>.
42*4f1223e8SApple OSS Distributions  *
43*4f1223e8SApple OSS Distributions  *      kern_return_t	semaphore_create(task_t task,
44*4f1223e8SApple OSS Distributions  *                                       semaphore_t *new_semaphore,
45*4f1223e8SApple OSS Distributions  *					 sync_policy_t policy,
46*4f1223e8SApple OSS Distributions  *					 int value);
47*4f1223e8SApple OSS Distributions  *
48*4f1223e8SApple OSS Distributions  *	kern_return_t	semaphore_destroy(task_t task,
49*4f1223e8SApple OSS Distributions  *					  semaphore_t semaphore);
50*4f1223e8SApple OSS Distributions  */
51*4f1223e8SApple OSS Distributions 
52*4f1223e8SApple OSS Distributions #include <sys/cdefs.h>
53*4f1223e8SApple OSS Distributions __BEGIN_DECLS
54*4f1223e8SApple OSS Distributions 
55*4f1223e8SApple OSS Distributions extern  kern_return_t   semaphore_signal(semaphore_t semaphore);
56*4f1223e8SApple OSS Distributions extern  kern_return_t   semaphore_signal_all(semaphore_t semaphore);
57*4f1223e8SApple OSS Distributions 
58*4f1223e8SApple OSS Distributions extern  kern_return_t   semaphore_wait(semaphore_t semaphore);
59*4f1223e8SApple OSS Distributions 
60*4f1223e8SApple OSS Distributions #ifdef  KERNEL
61*4f1223e8SApple OSS Distributions 
62*4f1223e8SApple OSS Distributions #ifdef  __LP64__
63*4f1223e8SApple OSS Distributions 
64*4f1223e8SApple OSS Distributions #ifdef  KERNEL_PRIVATE
65*4f1223e8SApple OSS Distributions 
66*4f1223e8SApple OSS Distributions extern  kern_return_t   semaphore_timedwait(semaphore_t semaphore,
67*4f1223e8SApple OSS Distributions     mach_timespec_t wait_time);
68*4f1223e8SApple OSS Distributions 
69*4f1223e8SApple OSS Distributions #endif  /* KERNEL_PRIVATE */
70*4f1223e8SApple OSS Distributions 
71*4f1223e8SApple OSS Distributions #else   /* __LP64__ */
72*4f1223e8SApple OSS Distributions 
73*4f1223e8SApple OSS Distributions extern  kern_return_t   semaphore_timedwait(semaphore_t semaphore,
74*4f1223e8SApple OSS Distributions     mach_timespec_t wait_time);
75*4f1223e8SApple OSS Distributions 
76*4f1223e8SApple OSS Distributions #endif  /* __LP64__ */
77*4f1223e8SApple OSS Distributions 
78*4f1223e8SApple OSS Distributions extern  kern_return_t   semaphore_wait_deadline(semaphore_t semaphore,
79*4f1223e8SApple OSS Distributions     uint64_t deadline);
80*4f1223e8SApple OSS Distributions extern  kern_return_t   semaphore_wait_noblock(semaphore_t semaphore);
81*4f1223e8SApple OSS Distributions 
82*4f1223e8SApple OSS Distributions #ifdef  XNU_KERNEL_PRIVATE
83*4f1223e8SApple OSS Distributions 
84*4f1223e8SApple OSS Distributions extern  kern_return_t   semaphore_wait_signal(semaphore_t wait_semaphore,
85*4f1223e8SApple OSS Distributions     semaphore_t signal_semaphore);
86*4f1223e8SApple OSS Distributions 
87*4f1223e8SApple OSS Distributions extern  kern_return_t   semaphore_timedwait_signal(semaphore_t wait_semaphore,
88*4f1223e8SApple OSS Distributions     semaphore_t signal_semaphore,
89*4f1223e8SApple OSS Distributions     mach_timespec_t wait_time);
90*4f1223e8SApple OSS Distributions 
91*4f1223e8SApple OSS Distributions extern  kern_return_t   semaphore_signal_thread(semaphore_t semaphore,
92*4f1223e8SApple OSS Distributions     thread_t thread);
93*4f1223e8SApple OSS Distributions 
94*4f1223e8SApple OSS Distributions #endif  /* XNU_KERNEL_PRIVATE */
95*4f1223e8SApple OSS Distributions 
96*4f1223e8SApple OSS Distributions #else   /* KERNEL */
97*4f1223e8SApple OSS Distributions 
98*4f1223e8SApple OSS Distributions extern  kern_return_t   semaphore_timedwait(semaphore_t semaphore,
99*4f1223e8SApple OSS Distributions     mach_timespec_t wait_time);
100*4f1223e8SApple OSS Distributions 
101*4f1223e8SApple OSS Distributions extern  kern_return_t   semaphore_timedwait_signal(semaphore_t wait_semaphore,
102*4f1223e8SApple OSS Distributions     semaphore_t signal_semaphore,
103*4f1223e8SApple OSS Distributions     mach_timespec_t wait_time);
104*4f1223e8SApple OSS Distributions 
105*4f1223e8SApple OSS Distributions extern  kern_return_t   semaphore_wait_signal(semaphore_t wait_semaphore,
106*4f1223e8SApple OSS Distributions     semaphore_t signal_semaphore);
107*4f1223e8SApple OSS Distributions 
108*4f1223e8SApple OSS Distributions extern  kern_return_t   semaphore_signal_thread(semaphore_t semaphore,
109*4f1223e8SApple OSS Distributions     thread_t thread);
110*4f1223e8SApple OSS Distributions 
111*4f1223e8SApple OSS Distributions #endif  /* KERNEL */
112*4f1223e8SApple OSS Distributions 
113*4f1223e8SApple OSS Distributions __END_DECLS
114*4f1223e8SApple OSS Distributions 
115*4f1223e8SApple OSS Distributions #ifdef  PRIVATE
116*4f1223e8SApple OSS Distributions 
117*4f1223e8SApple OSS Distributions #define SEMAPHORE_OPTION_NONE           0x00000000
118*4f1223e8SApple OSS Distributions 
119*4f1223e8SApple OSS Distributions #define SEMAPHORE_SIGNAL                0x00000001
120*4f1223e8SApple OSS Distributions #define SEMAPHORE_WAIT                  0x00000002
121*4f1223e8SApple OSS Distributions #define SEMAPHORE_WAIT_ON_SIGNAL        0x00000008
122*4f1223e8SApple OSS Distributions 
123*4f1223e8SApple OSS Distributions #define SEMAPHORE_SIGNAL_TIMEOUT        0x00000010
124*4f1223e8SApple OSS Distributions #define SEMAPHORE_SIGNAL_ALL            0x00000020
125*4f1223e8SApple OSS Distributions #define SEMAPHORE_SIGNAL_INTERRUPT      0x00000040      /* libmach implements */
126*4f1223e8SApple OSS Distributions #define SEMAPHORE_SIGNAL_PREPOST        0x00000080
127*4f1223e8SApple OSS Distributions 
128*4f1223e8SApple OSS Distributions #define SEMAPHORE_WAIT_TIMEOUT          0x00000100
129*4f1223e8SApple OSS Distributions #define SEMAPHORE_WAIT_INTERRUPT        0x00000400      /* libmach implements */
130*4f1223e8SApple OSS Distributions 
131*4f1223e8SApple OSS Distributions #define SEMAPHORE_TIMEOUT_NOBLOCK       0x00100000
132*4f1223e8SApple OSS Distributions #define SEMAPHORE_TIMEOUT_RELATIVE      0x00200000
133*4f1223e8SApple OSS Distributions 
134*4f1223e8SApple OSS Distributions #define SEMAPHORE_USE_SAVED_RESULT      0x01000000      /* internal use only */
135*4f1223e8SApple OSS Distributions #define SEMAPHORE_SIGNAL_RELEASE        0x02000000      /* internal use only */
136*4f1223e8SApple OSS Distributions #define SEMAPHORE_THREAD_HANDOFF        0x04000000
137*4f1223e8SApple OSS Distributions 
138*4f1223e8SApple OSS Distributions #endif  /* PRIVATE */
139*4f1223e8SApple OSS Distributions 
140*4f1223e8SApple OSS Distributions #endif  /* _MACH_SEMAPHORE_H_ */
141