]>
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_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* $NetBSD: sem.h,v 1.5 1994/06/29 06:45:15 cgd Exp $ */
25 * SVID compatible sem.h file
27 * Author: Daniel Boulet
28 * John Bellardo modified the implementation for Darwin. 12/2000
35 #include <sys/cdefs.h>
36 #include <sys/_types.h>
39 * [XSI] All of the symbols from <sys/ipc.h> SHALL be defined
40 * when this header is included
46 * [XSI] The pid_t, time_t, key_t, and size_t types shall be defined as
47 * described in <sys/types.h>.
49 * NOTE: The definition of the key_t type is implicit from the
50 * inclusion of <sys/ipc.h>
53 typedef __darwin_pid_t pid_t
;
59 typedef __darwin_time_t
time_t;
64 typedef __darwin_size_t
size_t;
68 * Technically, we should force all code references to the new structure
69 * definition, not in just the standards conformance case, and leave the
70 * legacy interface there for binary compatibility only. Currently, we
71 * are only forcing this for programs requesting standards conformance.
73 #if defined(__POSIX_C_SOURCE) || defined(kernel) || defined(__LP64__)
75 * Structure used internally.
77 * This structure is exposed because standards dictate that it is used as
78 * the semun union member 'buf' as the fourth argment to semctl() when the
79 * third argument is IPC_STAT or IPC_SET.
81 * Note: only the fields sem_perm, sem_nsems, sem_otime, and sem_ctime
82 * are meaningful in user space.
84 struct __semid_ds_new
{
85 struct __ipc_perm_new sem_perm
; /* [XSI] operation permission struct */
86 __int32_t sem_base
; /* 32 bit base ptr for semaphore set */
87 unsigned short sem_nsems
; /* [XSI] number of sems in set */
88 time_t sem_otime
; /* [XSI] last operation time */
89 __int32_t sem_pad1
; /* RESERVED: DO NOT USE! */
90 time_t sem_ctime
; /* [XSI] last change time */
91 /* Times measured in secs since */
92 /* 00:00:00 GMT, Jan. 1, 1970 */
93 __int32_t sem_pad2
; /* RESERVED: DO NOT USE! */
94 __int32_t sem_pad3
[4]; /* RESERVED: DO NOT USE! */
96 #define semid_ds __semid_ds_new
97 #else /* !_POSIX_C_SOURCE */
98 #define semid_ds __semid_ds_old
99 #endif /* !_POSIX_C_SOURCE */
101 #if !defined(__POSIX_C_SOURCE) && !defined(__LP64__)
102 struct __semid_ds_old
{
103 struct __ipc_perm_old sem_perm
; /* [XSI] operation permission struct */
104 __int32_t sem_base
; /* 32 bit base ptr for semaphore set */
105 unsigned short sem_nsems
; /* [XSI] number of sems in set */
106 time_t sem_otime
; /* [XSI] last operation time */
107 __int32_t sem_pad1
; /* RESERVED: DO NOT USE! */
108 time_t sem_ctime
; /* [XSI] last change time */
109 /* Times measured in secs since */
110 /* 00:00:00 GMT, Jan. 1, 1970 */
111 __int32_t sem_pad2
; /* RESERVED: DO NOT USE! */
112 __int32_t sem_pad3
[4]; /* RESERVED: DO NOT USE! */
114 #endif /* !_POSIX_C_SOURCE */
117 * Possible values for the third argument to semctl()
119 #define GETNCNT 3 /* [XSI] Return the value of semncnt {READ} */
120 #define GETPID 4 /* [XSI] Return the value of sempid {READ} */
121 #define GETVAL 5 /* [XSI] Return the value of semval {READ} */
122 #define GETALL 6 /* [XSI] Return semvals into arg.array {READ} */
123 #define GETZCNT 7 /* [XSI] Return the value of semzcnt {READ} */
124 #define SETVAL 8 /* [XSI] Set the value of semval to arg.val {ALTER} */
125 #define SETALL 9 /* [XSI] Set semvals from arg.array {ALTER} */
128 /* A semaphore; this is an anonymous structure, not for external use */
130 unsigned short semval
; /* semaphore value */
131 pid_t sempid
; /* pid of last operation */
132 unsigned short semncnt
; /* # awaiting semval > cval */
133 unsigned short semzcnt
; /* # awaiting semval == 0 */
138 * Structure of array element for second argument to semop()
141 unsigned short sem_num
; /* [XSI] semaphore # */
142 short sem_op
; /* [XSI] semaphore operation */
143 short sem_flg
; /* [XSI] operation flags */
147 * Possible flag values for sem_flg
149 #define SEM_UNDO 010000 /* [XSI] Set up adjust on exit entry */
152 #ifndef _POSIX_C_SOURCE
155 * System imposed limit on the value of the third parameter to semop().
156 * This is arbitrary, and the standards unfortunately do not provide a
157 * way for user applications to retrieve this value (e.g. via sysconf()
158 * or from a manifest value in <unistd.h>). The value shown here is
159 * informational, and subject to change in future revisions.
161 #define MAX_SOPS 5 /* maximum # of sembuf's per semop call */
165 * Union used as the fourth argment to semctl() in all cases. Specific
166 * member values are used for different values of the third parameter:
169 * ------------------------------------------- ------
170 * GETALL, SETALL array
172 * IPC_STAT, IPC_SET buf
174 * The union definition is intended to be defined by the user application
175 * in conforming applications; it is provided here for two reasons:
177 * 1) Historical source compatability for non-conforming applications
178 * expecting this header to declare the union type on their behalf
180 * 2) Documentation; specifically, 64 bit applications that do not pass
181 * this structure for 'val', or, alternately, a 64 bit type, will
182 * not function correctly
185 int val
; /* value for SETVAL */
186 struct semid_ds
*buf
; /* buffer for IPC_STAT & IPC_SET */
187 unsigned short *array
; /* array for GETALL & SETALL */
189 typedef union semun semun_t
;
195 #define SEM_A 0200 /* alter permission */
196 #define SEM_R 0400 /* read permission */
198 #endif /* !_POSIX_C_SOURCE */
205 #ifndef _POSIX_C_SOURCE
206 int semsys(int, ...);
207 #endif /* !_POSIX_C_SOURCE */
208 int semctl(int, int, int, ...) __DARWIN_ALIAS(semctl
);
209 int semget(key_t
, int, int);
210 int semop(int, struct sembuf
*, size_t);
215 #endif /* !_SEM_H_ */