]>
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 | #include <sys/_types/_pid_t.h> | |
59 | #include <sys/_types/_time_t.h> | |
60 | #include <sys/_types/_size_t.h> | |
61 | ||
62 | /* | |
63 | * Technically, we should force all code references to the new structure | |
64 | * definition, not in just the standards conformance case, and leave the | |
65 | * legacy interface there for binary compatibility only. Currently, we | |
66 | * are only forcing this for programs requesting standards conformance. | |
67 | */ | |
68 | #if __DARWIN_UNIX03 || defined(KERNEL) | |
69 | #pragma pack(4) | |
70 | /* | |
71 | * Structure used internally. | |
72 | * | |
73 | * This structure is exposed because standards dictate that it is used as | |
74 | * the semun union member 'buf' as the fourth argment to semctl() when the | |
75 | * third argument is IPC_STAT or IPC_SET. | |
76 | * | |
77 | * Note: only the fields sem_perm, sem_nsems, sem_otime, and sem_ctime | |
78 | * are meaningful in user space. | |
79 | */ | |
80 | #if (defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE)) | |
81 | struct semid_ds | |
82 | #else | |
83 | #define semid_ds __semid_ds_new | |
84 | struct __semid_ds_new | |
85 | #endif | |
86 | { | |
87 | struct __ipc_perm_new sem_perm; /* [XSI] operation permission struct */ | |
88 | __int32_t sem_base; /* 32 bit base ptr for semaphore set */ | |
89 | unsigned short sem_nsems; /* [XSI] number of sems in set */ | |
90 | time_t sem_otime; /* [XSI] last operation time */ | |
91 | __int32_t sem_pad1; /* RESERVED: DO NOT USE! */ | |
92 | time_t sem_ctime; /* [XSI] last change time */ | |
93 | /* Times measured in secs since */ | |
94 | /* 00:00:00 GMT, Jan. 1, 1970 */ | |
95 | __int32_t sem_pad2; /* RESERVED: DO NOT USE! */ | |
96 | __int32_t sem_pad3[4]; /* RESERVED: DO NOT USE! */ | |
97 | }; | |
98 | #pragma pack() | |
99 | #else /* !__DARWIN_UNIX03 */ | |
100 | #define semid_ds __semid_ds_old | |
101 | #endif /* __DARWIN_UNIX03 */ | |
102 | ||
103 | #if !__DARWIN_UNIX03 | |
104 | struct __semid_ds_old { | |
105 | struct __ipc_perm_old sem_perm; /* [XSI] operation permission struct */ | |
106 | __int32_t sem_base; /* 32 bit base ptr for semaphore set */ | |
107 | unsigned short sem_nsems; /* [XSI] number of sems in set */ | |
108 | time_t sem_otime; /* [XSI] last operation time */ | |
109 | __int32_t sem_pad1; /* RESERVED: DO NOT USE! */ | |
110 | time_t sem_ctime; /* [XSI] last change time */ | |
111 | /* Times measured in secs since */ | |
112 | /* 00:00:00 GMT, Jan. 1, 1970 */ | |
113 | __int32_t sem_pad2; /* RESERVED: DO NOT USE! */ | |
114 | __int32_t sem_pad3[4]; /* RESERVED: DO NOT USE! */ | |
115 | }; | |
116 | #endif /* !__DARWIN_UNIX03 */ | |
117 | ||
118 | /* | |
119 | * Possible values for the third argument to semctl() | |
120 | */ | |
121 | #define GETNCNT 3 /* [XSI] Return the value of semncnt {READ} */ | |
122 | #define GETPID 4 /* [XSI] Return the value of sempid {READ} */ | |
123 | #define GETVAL 5 /* [XSI] Return the value of semval {READ} */ | |
124 | #define GETALL 6 /* [XSI] Return semvals into arg.array {READ} */ | |
125 | #define GETZCNT 7 /* [XSI] Return the value of semzcnt {READ} */ | |
126 | #define SETVAL 8 /* [XSI] Set the value of semval to arg.val {ALTER} */ | |
127 | #define SETALL 9 /* [XSI] Set semvals from arg.array {ALTER} */ | |
128 | ||
129 | ||
130 | /* A semaphore; this is an anonymous structure, not for external use */ | |
131 | struct sem { | |
132 | unsigned short semval; /* semaphore value */ | |
133 | pid_t sempid; /* pid of last operation */ | |
134 | unsigned short semncnt; /* # awaiting semval > cval */ | |
135 | unsigned short semzcnt; /* # awaiting semval == 0 */ | |
136 | }; | |
137 | ||
138 | ||
139 | /* | |
140 | * Structure of array element for second argument to semop() | |
141 | */ | |
142 | struct sembuf { | |
143 | unsigned short sem_num; /* [XSI] semaphore # */ | |
144 | short sem_op; /* [XSI] semaphore operation */ | |
145 | short sem_flg; /* [XSI] operation flags */ | |
146 | }; | |
147 | ||
148 | /* | |
149 | * Possible flag values for sem_flg | |
150 | */ | |
151 | #define SEM_UNDO 010000 /* [XSI] Set up adjust on exit entry */ | |
152 | ||
153 | ||
154 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) | |
155 | ||
156 | /* | |
157 | * Union used as the fourth argment to semctl() in all cases. Specific | |
158 | * member values are used for different values of the third parameter: | |
159 | * | |
160 | * Command Member | |
161 | * ------------------------------------------- ------ | |
162 | * GETALL, SETALL array | |
163 | * SETVAL val | |
164 | * IPC_STAT, IPC_SET buf | |
165 | * | |
166 | * The union definition is intended to be defined by the user application | |
167 | * in conforming applications; it is provided here for two reasons: | |
168 | * | |
169 | * 1) Historical source compatability for non-conforming applications | |
170 | * expecting this header to declare the union type on their behalf | |
171 | * | |
172 | * 2) Documentation; specifically, 64 bit applications that do not pass | |
173 | * this structure for 'val', or, alternately, a 64 bit type, will | |
174 | * not function correctly | |
175 | */ | |
176 | union semun { | |
177 | int val; /* value for SETVAL */ | |
178 | struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ | |
179 | unsigned short *array; /* array for GETALL & SETALL */ | |
180 | }; | |
181 | typedef union semun semun_t; | |
182 | ||
183 | ||
184 | /* | |
185 | * Permissions | |
186 | */ | |
187 | #define SEM_A 0200 /* alter permission */ | |
188 | #define SEM_R 0400 /* read permission */ | |
189 | ||
190 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ | |
191 | ||
192 | ||
193 | ||
194 | #ifndef KERNEL | |
195 | ||
196 | __BEGIN_DECLS | |
197 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) | |
198 | int semsys(int, ...); | |
199 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ | |
200 | int semctl(int, int, int, ...) __DARWIN_ALIAS(semctl); | |
201 | int semget(key_t, int, int); | |
202 | int semop(int, struct sembuf *, size_t); | |
203 | __END_DECLS | |
204 | ||
205 | #endif /* !KERNEL */ | |
206 | ||
207 | #endif /* !_SEM_H_ */ |