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