]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/sem.h
9aa6bd8efcf02f439a053e056ebb1546673ded4a
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* $NetBSD: sem.h,v 1.5 1994/06/29 06:45:15 cgd Exp $ */
28 * SVID compatible sem.h file
30 * Author: Daniel Boulet
33 * John Bellardo modified the implementation for Darwin. 12/2000
39 #include <sys/appleapiopts.h>
43 u_short semval
; /* semaphore value */
44 pid_t sempid
; /* pid of last operation */
45 u_short semncnt
; /* # awaiting semval > cval */
46 u_short semzcnt
; /* # awaiting semval = 0 */
50 struct ipc_perm sem_perm
; /* operation permission struct */
51 struct sem
*sem_base
; /* pointer to first semaphore in set */
52 u_short sem_nsems
; /* number of sems in set */
53 time_t sem_otime
; /* last operation time */
54 long sem_pad1
; /* SVABI/386 says I need this here */
55 time_t sem_ctime
; /* last change time */
56 /* Times measured in secs since */
57 /* 00:00:00 GMT, Jan. 1, 1970 */
58 long sem_pad2
; /* SVABI/386 says I need this here */
59 long sem_pad3
[4]; /* SVABI/386 says I need this here */
63 * semop's sops parameter structure
66 u_short sem_num
; /* semaphore # */
67 short sem_op
; /* semaphore operation */
68 short sem_flg
; /* operation flags */
70 #define SEM_UNDO 010000
72 #define MAX_SOPS 5 /* maximum # of sembuf's per semop call */
75 * semctl's arg parameter structure
78 int val
; /* value for SETVAL */
79 struct semid_ds
*buf
; /* buffer for IPC_STAT & IPC_SET */
80 u_short
*array
; /* array for GETALL & SETALL */
86 #define GETNCNT 3 /* Return the value of semncnt {READ} */
87 #define GETPID 4 /* Return the value of sempid {READ} */
88 #define GETVAL 5 /* Return the value of semval {READ} */
89 #define GETALL 6 /* Return semvals into arg.array {READ} */
90 #define GETZCNT 7 /* Return the value of semzcnt {READ} */
91 #define SETVAL 8 /* Set the value of semval to arg.val {ALTER} */
92 #define SETALL 9 /* Set semvals from arg.array {ALTER} */
97 #define SEM_A 0200 /* alter permission */
98 #define SEM_R 0400 /* read permission */
101 #ifdef __APPLE_API_PRIVATE
103 * Kernel implementation stuff
105 #define SEMVMX 32767 /* semaphore maximum value */
106 #define SEMAEM 16384 /* adjust on exit max value */
109 * Configuration parameters. SEMMNI, SEMMNS, and SEMMNU are hard limits.
110 * The code dynamically allocates enough memory to satisfy the current
111 * demand in even increments of SEMMNI_INC, SEMMNS_INC, and SEMMNU_INC.
112 * The code will never allocate more than the hard limits. The *_INC's
113 * are defined in the kernel section of the header.
116 * Configuration parameters
118 #ifndef SEMMNS /* # of semaphores in system */
119 #define SEMMNS (1048576/sizeof(struct sem))
120 #endif /* no more than 1M of semaphore data */
121 #ifndef SEMMNI /* # of semaphore identifiers */
122 #define SEMMNI SEMMNS /* max of 1 for each semaphore */
125 #define SEMUME 10 /* max # of undo entries per process */
127 #ifndef SEMMNU /* # of undo structures in system */
128 #define SEMMNU SEMMNS /* 1 for each semaphore. This is quite large */
129 #endif /* This should be max 1 for each process */
131 /* shouldn't need tuning */
133 #define SEMMAP 30 /* # of entries in semaphore map */
136 #define SEMMSL SEMMNS /* max # of semaphores per id */
139 #define SEMOPM 100 /* max # of operations per semop call */
144 * Undo structure (one per process)
147 struct sem_undo
*un_next
; /* ptr to next active undo structure */
148 struct proc
*un_proc
; /* owner of this structure */
149 short un_cnt
; /* # of active entries */
151 short un_adjval
; /* adjust on exit values */
152 short un_num
; /* semaphore # */
153 int un_id
; /* semid */
154 } un_ent
[SEMUME
]; /* undo entries */
158 * semaphore info struct
161 int semmap
, /* # of entries in semaphore map */
162 semmni
, /* # of semaphore identifiers */
163 semmns
, /* # of semaphores in system */
164 semmnu
, /* # of undo structures in system */
165 semmsl
, /* max # of semaphores per id */
166 semopm
, /* max # of operations per semop call */
167 semume
, /* max # of undo entries per process */
168 semusz
, /* size in bytes of undo structure */
169 semvmx
, /* semaphore maximum value */
170 semaem
; /* adjust on exit max value */
172 extern struct seminfo seminfo
;
174 /* internal "mode" bits */
175 #define SEM_ALLOC 01000 /* semaphore is allocated */
176 #define SEM_DEST 02000 /* semaphore will be destroyed on last detach */
178 #define SEMMNI_INC 8 /* increment value for semaphore identifiers */
179 #define SEMMNS_INC 64 /* increment value for semaphores */
180 #define SEMMNU_INC 32 /* increment value for undo structures */
183 * Due to the way semaphore memory is allocated, we have to ensure that
184 * SEMUSZ is properly aligned.
186 * We are not doing strange semaphore memory allocation anymore, so
187 * these macros are no longer needed.
191 * #define SEM_ALIGN(bytes) (((bytes) + (sizeof(long) - 1)) & ~(sizeof(long) - 1))
194 /* actual size of an undo structure */
196 * #define SEMUSZ SEM_ALIGN(offsetof(struct sem_undo, un_ent[SEMUME]))
198 #define SEMUSZ sizeof(struct sem_undo)
200 extern struct semid_ds
*sema
; /* semaphore id pool */
201 extern struct sem
*sem
; /* semaphore pool */
202 /* This is now a struct sem_undo with the new memory allocation
203 * extern int *semu; /* undo structure pool
205 extern struct sem_undo
*semu
; /* undo structure pool */
208 * Macro to find a particular sem_undo vector
210 /* Until we can initialize seminfo.semusz to SEMUSZ, we hard code the size macro
211 * in SEMU. This should be fixed when (if) we implement dynamic pool sizes
213 * #define SEMU(ix) ((struct sem_undo *)(((intptr_t)semu)+ix * seminfo.semusz))
216 * This macro doesn't work because we are using a staticly allocated array
218 * #define SEMU(ix) ((struct sem_undo *)(((intptr_t)semu)+ix * SEMUSZ))
220 #define SEMU(ix) (&semu[ix])
224 * Process sem_undo vectors at proc exit.
226 void semexit
__P((struct proc
*p
));
229 * Parameters to the semconfig system call
232 SEM_CONFIG_FREEZE
, /* Freeze the semaphore facility. */
233 SEM_CONFIG_THAW
/* Thaw the semaphore facility. */
236 #endif /* __APPLE_API_PRIVATE */
241 #include <sys/cdefs.h>
244 int semsys
__P((int, ...));
245 int semctl
__P((int, int, int, union semun
));
246 int semget
__P((key_t
, int, int));
247 int semop
__P((int, struct sembuf
*,unsigned));
251 #endif /* !_SEM_H_ */