]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/sem.h
2 * Copyright (c) 2000 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
36 u_short semval
; /* semaphore value */
37 pid_t sempid
; /* pid of last operation */
38 u_short semncnt
; /* # awaiting semval > cval */
39 u_short semzcnt
; /* # awaiting semval = 0 */
43 struct ipc_perm sem_perm
; /* operation permission struct */
44 struct sem
*sem_base
; /* pointer to first semaphore in set */
45 u_short sem_nsems
; /* number of sems in set */
46 time_t sem_otime
; /* last operation time */
47 long sem_pad1
; /* SVABI/386 says I need this here */
48 time_t sem_ctime
; /* last change time */
49 /* Times measured in secs since */
50 /* 00:00:00 GMT, Jan. 1, 1970 */
51 long sem_pad2
; /* SVABI/386 says I need this here */
52 long sem_pad3
[4]; /* SVABI/386 says I need this here */
56 * semop's sops parameter structure
59 u_short sem_num
; /* semaphore # */
60 short sem_op
; /* semaphore operation */
61 short sem_flg
; /* operation flags */
63 #define SEM_UNDO 010000
65 #define MAX_SOPS 5 /* maximum # of sembuf's per semop call */
68 * semctl's arg parameter structure
71 int val
; /* value for SETVAL */
72 struct semid_ds
*buf
; /* buffer for IPC_STAT & IPC_SET */
73 u_short
*array
; /* array for GETALL & SETALL */
79 #define GETNCNT 3 /* Return the value of semncnt {READ} */
80 #define GETPID 4 /* Return the value of sempid {READ} */
81 #define GETVAL 5 /* Return the value of semval {READ} */
82 #define GETALL 6 /* Return semvals into arg.array {READ} */
83 #define GETZCNT 7 /* Return the value of semzcnt {READ} */
84 #define SETVAL 8 /* Set the value of semval to arg.val {ALTER} */
85 #define SETALL 9 /* Set semvals from arg.array {ALTER} */
90 #define SEM_A 0200 /* alter permission */
91 #define SEM_R 0400 /* read permission */
95 * Kernel implementation stuff
97 #define SEMVMX 32767 /* semaphore maximum value */
98 #define SEMAEM 16384 /* adjust on exit max value */
102 * Undo structure (one per process)
105 struct sem_undo
*un_next
; /* ptr to next active undo structure */
106 struct proc
*un_proc
; /* owner of this structure */
107 short un_cnt
; /* # of active entries */
109 short un_adjval
; /* adjust on exit values */
110 short un_num
; /* semaphore # */
111 int un_id
; /* semid */
112 } un_ent
[1]; /* undo entries */
116 * semaphore info struct
119 int semmap
, /* # of entries in semaphore map */
120 semmni
, /* # of semaphore identifiers */
121 semmns
, /* # of semaphores in system */
122 semmnu
, /* # of undo structures in system */
123 semmsl
, /* max # of semaphores per id */
124 semopm
, /* max # of operations per semop call */
125 semume
, /* max # of undo entries per process */
126 semusz
, /* size in bytes of undo structure */
127 semvmx
, /* semaphore maximum value */
128 semaem
; /* adjust on exit max value */
130 extern struct seminfo seminfo
;
132 /* internal "mode" bits */
133 #define SEM_ALLOC 01000 /* semaphore is allocated */
134 #define SEM_DEST 02000 /* semaphore will be destroyed on last detach */
137 * Configuration parameters
140 #define SEMMNI 10 /* # of semaphore identifiers */
143 #define SEMMNS 60 /* # of semaphores in system */
146 #define SEMUME 10 /* max # of undo entries per process */
149 #define SEMMNU 30 /* # of undo structures in system */
152 /* shouldn't need tuning */
154 #define SEMMAP 30 /* # of entries in semaphore map */
157 #define SEMMSL SEMMNS /* max # of semaphores per id */
160 #define SEMOPM 100 /* max # of operations per semop call */
164 * Due to the way semaphore memory is allocated, we have to ensure that
165 * SEMUSZ is properly aligned.
168 #define SEM_ALIGN(bytes) (((bytes) + (sizeof(long) - 1)) & ~(sizeof(long) - 1))
170 /* actual size of an undo structure */
171 #define SEMUSZ SEM_ALIGN(offsetof(struct sem_undo, un_ent[SEMUME]))
173 extern struct semid_ds
*sema
; /* semaphore id pool */
174 extern struct sem
*sem
; /* semaphore pool */
175 extern int *semu
; /* undo structure pool */
178 * Macro to find a particular sem_undo vector
180 #define SEMU(ix) ((struct sem_undo *)(((intptr_t)semu)+ix * seminfo.semusz))
183 * Process sem_undo vectors at proc exit.
185 void semexit
__P((struct proc
*p
));
188 * Parameters to the semconfig system call
191 SEM_CONFIG_FREEZE
, /* Freeze the semaphore facility. */
192 SEM_CONFIG_THAW
/* Thaw the semaphore facility. */
197 #include <sys/cdefs.h>
200 int semsys
__P((int, ...));
201 int semctl
__P((int, int, int, ...));
202 int semget
__P((key_t
, int, int));
203 int semop
__P((int, struct sembuf
*,unsigned));
207 #endif /* !_SEM_H_ */