]>
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
30 * John Bellardo modified the implementation for Darwin. 12/2000
36 #include <sys/appleapiopts.h>
40 u_short semval
; /* semaphore value */
41 pid_t sempid
; /* pid of last operation */
42 u_short semncnt
; /* # awaiting semval > cval */
43 u_short semzcnt
; /* # awaiting semval = 0 */
47 struct ipc_perm sem_perm
; /* operation permission struct */
48 struct sem
*sem_base
; /* pointer to first semaphore in set */
49 u_short sem_nsems
; /* number of sems in set */
50 time_t sem_otime
; /* last operation time */
51 long sem_pad1
; /* SVABI/386 says I need this here */
52 time_t sem_ctime
; /* last change time */
53 /* Times measured in secs since */
54 /* 00:00:00 GMT, Jan. 1, 1970 */
55 long sem_pad2
; /* SVABI/386 says I need this here */
56 long sem_pad3
[4]; /* SVABI/386 says I need this here */
60 * semop's sops parameter structure
63 u_short sem_num
; /* semaphore # */
64 short sem_op
; /* semaphore operation */
65 short sem_flg
; /* operation flags */
67 #define SEM_UNDO 010000
69 #define MAX_SOPS 5 /* maximum # of sembuf's per semop call */
72 * semctl's arg parameter structure
75 int val
; /* value for SETVAL */
76 struct semid_ds
*buf
; /* buffer for IPC_STAT & IPC_SET */
77 u_short
*array
; /* array for GETALL & SETALL */
83 #define GETNCNT 3 /* Return the value of semncnt {READ} */
84 #define GETPID 4 /* Return the value of sempid {READ} */
85 #define GETVAL 5 /* Return the value of semval {READ} */
86 #define GETALL 6 /* Return semvals into arg.array {READ} */
87 #define GETZCNT 7 /* Return the value of semzcnt {READ} */
88 #define SETVAL 8 /* Set the value of semval to arg.val {ALTER} */
89 #define SETALL 9 /* Set semvals from arg.array {ALTER} */
94 #define SEM_A 0200 /* alter permission */
95 #define SEM_R 0400 /* read permission */
98 #ifdef __APPLE_API_PRIVATE
100 * Kernel implementation stuff
102 #define SEMVMX 32767 /* semaphore maximum value */
103 #define SEMAEM 16384 /* adjust on exit max value */
106 * Configuration parameters. SEMMNI, SEMMNS, and SEMMNU are hard limits.
107 * The code dynamically allocates enough memory to satisfy the current
108 * demand in even increments of SEMMNI_INC, SEMMNS_INC, and SEMMNU_INC.
109 * The code will never allocate more than the hard limits. The *_INC's
110 * are defined in the kernel section of the header.
113 * Configuration parameters
115 #ifndef SEMMNS /* # of semaphores in system */
116 #define SEMMNS (1048576/sizeof(struct sem))
117 #endif /* no more than 1M of semaphore data */
118 #ifndef SEMMNI /* # of semaphore identifiers */
119 #define SEMMNI SEMMNS /* max of 1 for each semaphore */
122 #define SEMUME 10 /* max # of undo entries per process */
124 #ifndef SEMMNU /* # of undo structures in system */
125 #define SEMMNU SEMMNS /* 1 for each semaphore. This is quite large */
126 #endif /* This should be max 1 for each process */
128 /* shouldn't need tuning */
130 #define SEMMAP 30 /* # of entries in semaphore map */
133 #define SEMMSL SEMMNS /* max # of semaphores per id */
136 #define SEMOPM 100 /* max # of operations per semop call */
141 * Undo structure (one per process)
144 struct sem_undo
*un_next
; /* ptr to next active undo structure */
145 struct proc
*un_proc
; /* owner of this structure */
146 short un_cnt
; /* # of active entries */
148 short un_adjval
; /* adjust on exit values */
149 short un_num
; /* semaphore # */
150 int un_id
; /* semid */
151 } un_ent
[SEMUME
]; /* undo entries */
155 * semaphore info struct
158 int semmap
, /* # of entries in semaphore map */
159 semmni
, /* # of semaphore identifiers */
160 semmns
, /* # of semaphores in system */
161 semmnu
, /* # of undo structures in system */
162 semmsl
, /* max # of semaphores per id */
163 semopm
, /* max # of operations per semop call */
164 semume
, /* max # of undo entries per process */
165 semusz
, /* size in bytes of undo structure */
166 semvmx
, /* semaphore maximum value */
167 semaem
; /* adjust on exit max value */
169 extern struct seminfo seminfo
;
171 /* internal "mode" bits */
172 #define SEM_ALLOC 01000 /* semaphore is allocated */
173 #define SEM_DEST 02000 /* semaphore will be destroyed on last detach */
175 #define SEMMNI_INC 8 /* increment value for semaphore identifiers */
176 #define SEMMNS_INC 64 /* increment value for semaphores */
177 #define SEMMNU_INC 32 /* increment value for undo structures */
180 * Due to the way semaphore memory is allocated, we have to ensure that
181 * SEMUSZ is properly aligned.
183 * We are not doing strange semaphore memory allocation anymore, so
184 * these macros are no longer needed.
188 * #define SEM_ALIGN(bytes) (((bytes) + (sizeof(long) - 1)) & ~(sizeof(long) - 1))
191 /* actual size of an undo structure */
193 * #define SEMUSZ SEM_ALIGN(offsetof(struct sem_undo, un_ent[SEMUME]))
195 #define SEMUSZ sizeof(struct sem_undo)
197 extern struct semid_ds
*sema
; /* semaphore id pool */
198 extern struct sem
*sem
; /* semaphore pool */
199 /* This is now a struct sem_undo with the new memory allocation
200 * extern int *semu; /* undo structure pool
202 extern struct sem_undo
*semu
; /* undo structure pool */
205 * Macro to find a particular sem_undo vector
207 /* Until we can initialize seminfo.semusz to SEMUSZ, we hard code the size macro
208 * in SEMU. This should be fixed when (if) we implement dynamic pool sizes
210 * #define SEMU(ix) ((struct sem_undo *)(((intptr_t)semu)+ix * seminfo.semusz))
213 * This macro doesn't work because we are using a staticly allocated array
215 * #define SEMU(ix) ((struct sem_undo *)(((intptr_t)semu)+ix * SEMUSZ))
217 #define SEMU(ix) (&semu[ix])
221 * Process sem_undo vectors at proc exit.
223 void semexit
__P((struct proc
*p
));
226 * Parameters to the semconfig system call
229 SEM_CONFIG_FREEZE
, /* Freeze the semaphore facility. */
230 SEM_CONFIG_THAW
/* Thaw the semaphore facility. */
233 #endif /* __APPLE_API_PRIVATE */
238 #include <sys/cdefs.h>
241 int semsys
__P((int, ...));
242 int semctl
__P((int, int, int, union semun
));
243 int semget
__P((key_t
, int, int));
244 int semop
__P((int, struct sembuf
*,unsigned));
248 #endif /* !_SEM_H_ */