2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 #ifndef _MACH_SEMAPHORE_H_
27 #define _MACH_SEMAPHORE_H_
29 #include <mach/port.h>
30 #include <mach/mach_types.h>
31 #include <mach/kern_return.h>
32 #include <mach/sync_policy.h>
35 * Forward Declarations
37 * The semaphore creation and deallocation routines are
38 * defined with the Mach task APIs in <mach/task.h>.
40 * kern_return_t semaphore_create(task_t task,
41 * semaphore_t *new_semaphore,
42 * sync_policy_t policy,
45 * kern_return_t semaphore_destroy(task_t task,
46 * semaphore_t semaphore);
49 extern kern_return_t
semaphore_signal (semaphore_t semaphore
);
50 extern kern_return_t
semaphore_signal_all (semaphore_t semaphore
);
51 extern kern_return_t
semaphore_signal_thread (semaphore_t semaphore
,
52 thread_act_t thread_act
);
54 extern kern_return_t
semaphore_wait (semaphore_t semaphore
);
55 extern kern_return_t
semaphore_timedwait (semaphore_t semaphore
,
56 mach_timespec_t wait_time
);
58 extern kern_return_t
semaphore_wait_signal (semaphore_t wait_semaphore
,
59 semaphore_t signal_semaphore
);
61 extern kern_return_t
semaphore_timedwait_signal(semaphore_t wait_semaphore
,
62 semaphore_t signal_semaphore
,
63 mach_timespec_t wait_time
);
65 #include <sys/appleapiopts.h>
67 #ifdef __APPLE_API_PRIVATE
68 #ifdef __APPLE_API_EVOLVING
70 #define SEMAPHORE_OPTION_NONE 0x00000000
72 #define SEMAPHORE_SIGNAL 0x00000001
73 #define SEMAPHORE_WAIT 0x00000002
74 #define SEMAPHORE_WAIT_ON_SIGNAL 0x00000008
76 #define SEMAPHORE_SIGNAL_TIMEOUT 0x00000010
77 #define SEMAPHORE_SIGNAL_ALL 0x00000020
78 #define SEMAPHORE_SIGNAL_INTERRUPT 0x00000040 /* libmach implements */
79 #define SEMAPHORE_SIGNAL_PREPOST 0x00000080
81 #define SEMAPHORE_WAIT_TIMEOUT 0x00000100
82 #define SEMAPHORE_WAIT_INTERRUPT 0x00000400 /* libmach implements */
84 #define SEMAPHORE_TIMEOUT_NOBLOCK 0x00100000
85 #define SEMAPHORE_TIMEOUT_RELATIVE 0x00200000
87 #define SEMAPHORE_USE_SAVED_RESULT 0x01000000 /* internal use only */
88 #define SEMAPHORE_SIGNAL_RELEASE 0x02000000 /* internal use only */
90 extern kern_return_t
semaphore_operator (int options
,
91 semaphore_t wait_semaphore
,
92 semaphore_t signal_semaphore
,
94 mach_timespec_t wait_time
);
96 #endif /* __APPLE_API_EVOLVING */
98 #endif /* __APPLE_API_PRIVATE */
100 #endif /* _MACH_SEMAPHORE_H_ */