]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/sem.h
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* $NetBSD: sem.h,v 1.5 1994/06/29 06:45:15 cgd Exp $ */
33 * SVID compatible sem.h file
35 * Author: Daniel Boulet
36 * John Bellardo modified the implementation for Darwin. 12/2000
43 #include <sys/cdefs.h>
44 #include <sys/_types.h>
47 * [XSI] All of the symbols from <sys/ipc.h> SHALL be defined
48 * when this header is included
54 * [XSI] The pid_t, time_t, key_t, and size_t types shall be defined as
55 * described in <sys/types.h>.
57 * NOTE: The definition of the key_t type is implicit from the
58 * inclusion of <sys/ipc.h>
61 typedef __darwin_pid_t pid_t
;
67 typedef __darwin_time_t
time_t;
72 typedef __darwin_size_t
size_t;
76 * Technically, we should force all code references to the new structure
77 * definition, not in just the standards conformance case, and leave the
78 * legacy interface there for binary compatibility only. Currently, we
79 * are only forcing this for programs requesting standards conformance.
81 #if defined(__POSIX_C_SOURCE) || defined(kernel) || defined(__LP64__)
83 * Structure used internally.
85 * This structure is exposed because standards dictate that it is used as
86 * the semun union member 'buf' as the fourth argment to semctl() when the
87 * third argument is IPC_STAT or IPC_SET.
89 * Note: only the fields sem_perm, sem_nsems, sem_otime, and sem_ctime
90 * are meaningful in user space.
92 struct __semid_ds_new
{
93 struct __ipc_perm_new sem_perm
; /* [XSI] operation permission struct */
94 __int32_t sem_base
; /* 32 bit base ptr for semaphore set */
95 unsigned short sem_nsems
; /* [XSI] number of sems in set */
96 time_t sem_otime
; /* [XSI] last operation time */
97 __int32_t sem_pad1
; /* RESERVED: DO NOT USE! */
98 time_t sem_ctime
; /* [XSI] last change time */
99 /* Times measured in secs since */
100 /* 00:00:00 GMT, Jan. 1, 1970 */
101 __int32_t sem_pad2
; /* RESERVED: DO NOT USE! */
102 __int32_t sem_pad3
[4]; /* RESERVED: DO NOT USE! */
104 #define semid_ds __semid_ds_new
105 #else /* !_POSIX_C_SOURCE */
106 #define semid_ds __semid_ds_old
107 #endif /* !_POSIX_C_SOURCE */
109 #if !defined(__POSIX_C_SOURCE) && !defined(__LP64__)
110 struct __semid_ds_old
{
111 struct __ipc_perm_old sem_perm
; /* [XSI] operation permission struct */
112 __int32_t sem_base
; /* 32 bit base ptr for semaphore set */
113 unsigned short sem_nsems
; /* [XSI] number of sems in set */
114 time_t sem_otime
; /* [XSI] last operation time */
115 __int32_t sem_pad1
; /* RESERVED: DO NOT USE! */
116 time_t sem_ctime
; /* [XSI] last change time */
117 /* Times measured in secs since */
118 /* 00:00:00 GMT, Jan. 1, 1970 */
119 __int32_t sem_pad2
; /* RESERVED: DO NOT USE! */
120 __int32_t sem_pad3
[4]; /* RESERVED: DO NOT USE! */
122 #endif /* !_POSIX_C_SOURCE */
125 * Possible values for the third argument to semctl()
127 #define GETNCNT 3 /* [XSI] Return the value of semncnt {READ} */
128 #define GETPID 4 /* [XSI] Return the value of sempid {READ} */
129 #define GETVAL 5 /* [XSI] Return the value of semval {READ} */
130 #define GETALL 6 /* [XSI] Return semvals into arg.array {READ} */
131 #define GETZCNT 7 /* [XSI] Return the value of semzcnt {READ} */
132 #define SETVAL 8 /* [XSI] Set the value of semval to arg.val {ALTER} */
133 #define SETALL 9 /* [XSI] Set semvals from arg.array {ALTER} */
136 /* A semaphore; this is an anonymous structure, not for external use */
138 unsigned short semval
; /* semaphore value */
139 pid_t sempid
; /* pid of last operation */
140 unsigned short semncnt
; /* # awaiting semval > cval */
141 unsigned short semzcnt
; /* # awaiting semval == 0 */
146 * Structure of array element for second argument to semop()
149 unsigned short sem_num
; /* [XSI] semaphore # */
150 short sem_op
; /* [XSI] semaphore operation */
151 short sem_flg
; /* [XSI] operation flags */
155 * Possible flag values for sem_flg
157 #define SEM_UNDO 010000 /* [XSI] Set up adjust on exit entry */
160 #ifndef _POSIX_C_SOURCE
163 * System imposed limit on the value of the third parameter to semop().
164 * This is arbitrary, and the standards unfortunately do not provide a
165 * way for user applications to retrieve this value (e.g. via sysconf()
166 * or from a manifest value in <unistd.h>). The value shown here is
167 * informational, and subject to change in future revisions.
169 #define MAX_SOPS 5 /* maximum # of sembuf's per semop call */
173 * Union used as the fourth argment to semctl() in all cases. Specific
174 * member values are used for different values of the third parameter:
177 * ------------------------------------------- ------
178 * GETALL, SETALL array
180 * IPC_STAT, IPC_SET buf
182 * The union definition is intended to be defined by the user application
183 * in conforming applications; it is provided here for two reasons:
185 * 1) Historical source compatability for non-conforming applications
186 * expecting this header to declare the union type on their behalf
188 * 2) Documentation; specifically, 64 bit applications that do not pass
189 * this structure for 'val', or, alternately, a 64 bit type, will
190 * not function correctly
193 int val
; /* value for SETVAL */
194 struct semid_ds
*buf
; /* buffer for IPC_STAT & IPC_SET */
195 unsigned short *array
; /* array for GETALL & SETALL */
197 typedef union semun semun_t
;
203 #define SEM_A 0200 /* alter permission */
204 #define SEM_R 0400 /* read permission */
206 #endif /* !_POSIX_C_SOURCE */
213 #ifndef _POSIX_C_SOURCE
214 int semsys(int, ...);
215 #endif /* !_POSIX_C_SOURCE */
216 int semctl(int, int, int, ...) __DARWIN_ALIAS(semctl
);
217 int semget(key_t
, int, int);
218 int semop(int, struct sembuf
*, size_t);
223 #endif /* !_SEM_H_ */