]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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. | |
11 | * | |
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 | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* $NetBSD: sem.h,v 1.5 1994/06/29 06:45:15 cgd Exp $ */ | |
23 | ||
24 | /* | |
25 | * SVID compatible sem.h file | |
26 | * | |
27 | * Author: Daniel Boulet | |
28 | */ | |
29 | ||
30 | #ifndef _SYS_SEM_H_ | |
31 | #define _SYS_SEM_H_ | |
32 | ||
33 | #include <sys/ipc.h> | |
34 | ||
35 | struct sem { | |
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 */ | |
40 | }; | |
41 | ||
42 | struct semid_ds { | |
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 */ | |
53 | }; | |
54 | ||
55 | /* | |
56 | * semop's sops parameter structure | |
57 | */ | |
58 | struct sembuf { | |
59 | u_short sem_num; /* semaphore # */ | |
60 | short sem_op; /* semaphore operation */ | |
61 | short sem_flg; /* operation flags */ | |
62 | }; | |
63 | #define SEM_UNDO 010000 | |
64 | ||
65 | #define MAX_SOPS 5 /* maximum # of sembuf's per semop call */ | |
66 | ||
67 | /* | |
68 | * semctl's arg parameter structure | |
69 | */ | |
70 | union semun { | |
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 */ | |
74 | }; | |
75 | ||
76 | /* | |
77 | * commands for semctl | |
78 | */ | |
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} */ | |
86 | ||
87 | /* | |
88 | * Permissions | |
89 | */ | |
90 | #define SEM_A 0200 /* alter permission */ | |
91 | #define SEM_R 0400 /* read permission */ | |
92 | ||
93 | #ifdef KERNEL | |
94 | /* | |
95 | * Kernel implementation stuff | |
96 | */ | |
97 | #define SEMVMX 32767 /* semaphore maximum value */ | |
98 | #define SEMAEM 16384 /* adjust on exit max value */ | |
99 | ||
100 | ||
101 | /* | |
102 | * Undo structure (one per process) | |
103 | */ | |
104 | struct sem_undo { | |
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 */ | |
108 | struct undo { | |
109 | short un_adjval; /* adjust on exit values */ | |
110 | short un_num; /* semaphore # */ | |
111 | int un_id; /* semid */ | |
112 | } un_ent[1]; /* undo entries */ | |
113 | }; | |
114 | ||
115 | /* | |
116 | * semaphore info struct | |
117 | */ | |
118 | struct seminfo { | |
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 */ | |
129 | }; | |
130 | extern struct seminfo seminfo; | |
131 | ||
132 | /* internal "mode" bits */ | |
133 | #define SEM_ALLOC 01000 /* semaphore is allocated */ | |
134 | #define SEM_DEST 02000 /* semaphore will be destroyed on last detach */ | |
135 | ||
136 | /* | |
137 | * Configuration parameters | |
138 | */ | |
139 | #ifndef SEMMNI | |
140 | #define SEMMNI 10 /* # of semaphore identifiers */ | |
141 | #endif | |
142 | #ifndef SEMMNS | |
143 | #define SEMMNS 60 /* # of semaphores in system */ | |
144 | #endif | |
145 | #ifndef SEMUME | |
146 | #define SEMUME 10 /* max # of undo entries per process */ | |
147 | #endif | |
148 | #ifndef SEMMNU | |
149 | #define SEMMNU 30 /* # of undo structures in system */ | |
150 | #endif | |
151 | ||
152 | /* shouldn't need tuning */ | |
153 | #ifndef SEMMAP | |
154 | #define SEMMAP 30 /* # of entries in semaphore map */ | |
155 | #endif | |
156 | #ifndef SEMMSL | |
157 | #define SEMMSL SEMMNS /* max # of semaphores per id */ | |
158 | #endif | |
159 | #ifndef SEMOPM | |
160 | #define SEMOPM 100 /* max # of operations per semop call */ | |
161 | #endif | |
162 | ||
163 | /* | |
164 | * Due to the way semaphore memory is allocated, we have to ensure that | |
165 | * SEMUSZ is properly aligned. | |
166 | */ | |
167 | ||
168 | #define SEM_ALIGN(bytes) (((bytes) + (sizeof(long) - 1)) & ~(sizeof(long) - 1)) | |
169 | ||
170 | /* actual size of an undo structure */ | |
171 | #define SEMUSZ SEM_ALIGN(offsetof(struct sem_undo, un_ent[SEMUME])) | |
172 | ||
173 | extern struct semid_ds *sema; /* semaphore id pool */ | |
174 | extern struct sem *sem; /* semaphore pool */ | |
175 | extern int *semu; /* undo structure pool */ | |
176 | ||
177 | /* | |
178 | * Macro to find a particular sem_undo vector | |
179 | */ | |
180 | #define SEMU(ix) ((struct sem_undo *)(((intptr_t)semu)+ix * seminfo.semusz)) | |
181 | ||
182 | /* | |
183 | * Process sem_undo vectors at proc exit. | |
184 | */ | |
185 | void semexit __P((struct proc *p)); | |
186 | ||
187 | /* | |
188 | * Parameters to the semconfig system call | |
189 | */ | |
190 | typedef enum { | |
191 | SEM_CONFIG_FREEZE, /* Freeze the semaphore facility. */ | |
192 | SEM_CONFIG_THAW /* Thaw the semaphore facility. */ | |
193 | } semconfig_ctl_t; | |
194 | #endif /* KERNEL */ | |
195 | ||
196 | #ifndef KERNEL | |
197 | #include <sys/cdefs.h> | |
198 | ||
199 | __BEGIN_DECLS | |
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)); | |
204 | __END_DECLS | |
205 | #endif /* !KERNEL */ | |
206 | ||
207 | #endif /* !_SEM_H_ */ |