]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/sem.h
caa9ed4915827aa1e97c724625a413f8a73f1e98
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
21 * @APPLE_LICENSE_HEADER_END@
23 /* $NetBSD: sem.h,v 1.5 1994/06/29 06:45:15 cgd Exp $ */
26 * SVID compatible sem.h file
28 * Author: Daniel Boulet
29 * John Bellardo modified the implementation for Darwin. 12/2000
36 #include <sys/cdefs.h>
37 #include <sys/_types.h>
40 * [XSI] All of the symbols from <sys/ipc.h> SHALL be defined
41 * when this header is included
47 * [XSI] The pid_t, time_t, key_t, and size_t types shall be defined as
48 * described in <sys/types.h>.
50 * NOTE: The definition of the key_t type is implicit from the
51 * inclusion of <sys/ipc.h>
54 typedef __darwin_pid_t pid_t
;
60 typedef __darwin_time_t
time_t;
65 typedef __darwin_size_t
size_t;
69 * Technically, we should force all code references to the new structure
70 * definition, not in just the standards conformance case, and leave the
71 * legacy interface there for binary compatibility only. Currently, we
72 * are only forcing this for programs requesting standards conformance.
74 #if defined(__POSIX_C_SOURCE) || defined(kernel) || defined(__LP64__)
76 * Structure used internally.
78 * This structure is exposed because standards dictate that it is used as
79 * the semun union member 'buf' as the fourth argment to semctl() when the
80 * third argument is IPC_STAT or IPC_SET.
82 * Note: only the fields sem_perm, sem_nsems, sem_otime, and sem_ctime
83 * are meaningful in user space.
85 struct __semid_ds_new
{
86 struct __ipc_perm_new sem_perm
; /* [XSI] operation permission struct */
87 __int32_t sem_base
; /* 32 bit base ptr for semaphore set */
88 unsigned short sem_nsems
; /* [XSI] number of sems in set */
89 time_t sem_otime
; /* [XSI] last operation time */
90 __int32_t sem_pad1
; /* RESERVED: DO NOT USE! */
91 time_t sem_ctime
; /* [XSI] last change time */
92 /* Times measured in secs since */
93 /* 00:00:00 GMT, Jan. 1, 1970 */
94 __int32_t sem_pad2
; /* RESERVED: DO NOT USE! */
95 __int32_t sem_pad3
[4]; /* RESERVED: DO NOT USE! */
97 #define semid_ds __semid_ds_new
98 #else /* !_POSIX_C_SOURCE */
99 #define semid_ds __semid_ds_old
100 #endif /* !_POSIX_C_SOURCE */
102 #if !defined(__POSIX_C_SOURCE) && !defined(__LP64__)
103 struct __semid_ds_old
{
104 struct __ipc_perm_old sem_perm
; /* [XSI] operation permission struct */
105 __int32_t sem_base
; /* 32 bit base ptr for semaphore set */
106 unsigned short sem_nsems
; /* [XSI] number of sems in set */
107 time_t sem_otime
; /* [XSI] last operation time */
108 __int32_t sem_pad1
; /* RESERVED: DO NOT USE! */
109 time_t sem_ctime
; /* [XSI] last change time */
110 /* Times measured in secs since */
111 /* 00:00:00 GMT, Jan. 1, 1970 */
112 __int32_t sem_pad2
; /* RESERVED: DO NOT USE! */
113 __int32_t sem_pad3
[4]; /* RESERVED: DO NOT USE! */
115 #endif /* !_POSIX_C_SOURCE */
118 * Possible values for the third argument to semctl()
120 #define GETNCNT 3 /* [XSI] Return the value of semncnt {READ} */
121 #define GETPID 4 /* [XSI] Return the value of sempid {READ} */
122 #define GETVAL 5 /* [XSI] Return the value of semval {READ} */
123 #define GETALL 6 /* [XSI] Return semvals into arg.array {READ} */
124 #define GETZCNT 7 /* [XSI] Return the value of semzcnt {READ} */
125 #define SETVAL 8 /* [XSI] Set the value of semval to arg.val {ALTER} */
126 #define SETALL 9 /* [XSI] Set semvals from arg.array {ALTER} */
129 /* A semaphore; this is an anonymous structure, not for external use */
131 unsigned short semval
; /* semaphore value */
132 pid_t sempid
; /* pid of last operation */
133 unsigned short semncnt
; /* # awaiting semval > cval */
134 unsigned short semzcnt
; /* # awaiting semval == 0 */
139 * Structure of array element for second argument to semop()
142 unsigned short sem_num
; /* [XSI] semaphore # */
143 short sem_op
; /* [XSI] semaphore operation */
144 short sem_flg
; /* [XSI] operation flags */
148 * Possible flag values for sem_flg
150 #define SEM_UNDO 010000 /* [XSI] Set up adjust on exit entry */
153 #ifndef _POSIX_C_SOURCE
156 * System imposed limit on the value of the third parameter to semop().
157 * This is arbitrary, and the standards unfortunately do not provide a
158 * way for user applications to retrieve this value (e.g. via sysconf()
159 * or from a manifest value in <unistd.h>). The value shown here is
160 * informational, and subject to change in future revisions.
162 #define MAX_SOPS 5 /* maximum # of sembuf's per semop call */
166 * Union used as the fourth argment to semctl() in all cases. Specific
167 * member values are used for different values of the third parameter:
170 * ------------------------------------------- ------
171 * GETALL, SETALL array
173 * IPC_STAT, IPC_SET buf
175 * The union definition is intended to be defined by the user application
176 * in conforming applications; it is provided here for two reasons:
178 * 1) Historical source compatability for non-conforming applications
179 * expecting this header to declare the union type on their behalf
181 * 2) Documentation; specifically, 64 bit applications that do not pass
182 * this structure for 'val', or, alternately, a 64 bit type, will
183 * not function correctly
186 int val
; /* value for SETVAL */
187 struct semid_ds
*buf
; /* buffer for IPC_STAT & IPC_SET */
188 unsigned short *array
; /* array for GETALL & SETALL */
190 typedef union semun semun_t
;
196 #define SEM_A 0200 /* alter permission */
197 #define SEM_R 0400 /* read permission */
199 #endif /* !_POSIX_C_SOURCE */
206 #ifndef _POSIX_C_SOURCE
207 int semsys(int, ...);
208 #endif /* !_POSIX_C_SOURCE */
209 int semctl(int, int, int, ...) __DARWIN_ALIAS(semctl
);
210 int semget(key_t
, int, int);
211 int semop(int, struct sembuf
*, size_t);
216 #endif /* !_SEM_H_ */