1 /* $Id: sem.h,v 1.9 1996/12/18 13:18:57 jkh Exp $ */ 2 /* $NetBSD: sem.h,v 1.5 1994/06/29 06:45:15 cgd Exp $ */ 3 4 /* 5 * SVID compatible sem.h file 6 * 7 * Author: Daniel Boulet 8 */ 9 10 #ifndef _SYS_SEM_H_ 11 #define _SYS_SEM_H_ 12 13 #include <sys/ipc.h> 14 15 struct sem { 16 u_short semval; /* semaphore value */ 17 pid_t sempid; /* pid of last operation */ 18 u_short semncnt; /* # awaiting semval > cval */ 19 u_short semzcnt; /* # awaiting semval = 0 */ 20 }; 21 22 struct semid_ds { 23 struct ipc_perm sem_perm; /* operation permission struct */ 24 struct sem *sem_base; /* pointer to first semaphore in set */ 25 u_short sem_nsems; /* number of sems in set */ 26 time_t sem_otime; /* last operation time */ 27 long sem_pad1; /* SVABI/386 says I need this here */ 28 time_t sem_ctime; /* last change time */ 29 /* Times measured in secs since */ 30 /* 00:00:00 GMT, Jan. 1, 1970 */ 31 long sem_pad2; /* SVABI/386 says I need this here */ 32 long sem_pad3[4]; /* SVABI/386 says I need this here */ 33 }; 34 35 /* 36 * semop's sops parameter structure 37 */ 38 struct sembuf { 39 u_short sem_num; /* semaphore # */ 40 short sem_op; /* semaphore operation */ 41 short sem_flg; /* operation flags */ 42 }; 43 #define SEM_UNDO 010000 44 45 #define MAX_SOPS 5 /* maximum # of sembuf's per semop call */ 46 47 /* 48 * semctl's arg parameter structure 49 */ 50 union semun { 51 int val; /* value for SETVAL */ 52 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ 53 u_short *array; /* array for GETALL & SETALL */ 54 }; 55 56 /* 57 * commands for semctl 58 */ 59 #define GETNCNT 3 /* Return the value of semncnt {READ} */ 60 #define GETPID 4 /* Return the value of sempid {READ} */ 61 #define GETVAL 5 /* Return the value of semval {READ} */ 62 #define GETALL 6 /* Return semvals into arg.array {READ} */ 63 #define GETZCNT 7 /* Return the value of semzcnt {READ} */ 64 #define SETVAL 8 /* Set the value of semval to arg.val {ALTER} */ 65 #define SETALL 9 /* Set semvals from arg.array {ALTER} */ 66 67 /* 68 * Permissions 69 */ 70 #define SEM_A 0200 /* alter permission */ 71 #define SEM_R 0400 /* read permission */ 72 73 #ifdef KERNEL 74 /* 75 * Kernel implementation stuff 76 */ 77 #define SEMVMX 32767 /* semaphore maximum value */ 78 #define SEMAEM 16384 /* adjust on exit max value */ 79 80 81 /* 82 * Undo structure (one per process) 83 */ 84 struct sem_undo { 85 struct sem_undo *un_next; /* ptr to next active undo structure */ 86 struct proc *un_proc; /* owner of this structure */ 87 short un_cnt; /* # of active entries */ 88 struct undo { 89 short un_adjval; /* adjust on exit values */ 90 short un_num; /* semaphore # */ 91 int un_id; /* semid */ 92 } un_ent[1]; /* undo entries */ 93 }; 94 95 /* 96 * semaphore info struct 97 */ 98 struct seminfo { 99 int semmap, /* # of entries in semaphore map */ 100 semmni, /* # of semaphore identifiers */ 101 semmns, /* # of semaphores in system */ 102 semmnu, /* # of undo structures in system */ 103 semmsl, /* max # of semaphores per id */ 104 semopm, /* max # of operations per semop call */ 105 semume, /* max # of undo entries per process */ 106 semusz, /* size in bytes of undo structure */ 107 semvmx, /* semaphore maximum value */ 108 semaem; /* adjust on exit max value */ 109 }; 110 extern struct seminfo seminfo; 111 112 /* internal "mode" bits */ 113 #define SEM_ALLOC 01000 /* semaphore is allocated */ 114 #define SEM_DEST 02000 /* semaphore will be destroyed on last detach */ 115 116 /* 117 * Configuration parameters 118 */ 119 #ifndef SEMMNI 120 #define SEMMNI 10 /* # of semaphore identifiers */ 121 #endif 122 #ifndef SEMMNS 123 #define SEMMNS 60 /* # of semaphores in system */ 124 #endif 125 #ifndef SEMUME 126 #define SEMUME 10 /* max # of undo entries per process */ 127 #endif 128 #ifndef SEMMNU 129 #define SEMMNU 30 /* # of undo structures in system */ 130 #endif 131 132 /* shouldn't need tuning */ 133 #ifndef SEMMAP 134 #define SEMMAP 30 /* # of entries in semaphore map */ 135 #endif 136 #ifndef SEMMSL 137 #define SEMMSL SEMMNS /* max # of semaphores per id */ 138 #endif 139 #ifndef SEMOPM 140 #define SEMOPM 100 /* max # of operations per semop call */ 141 #endif 142 143 /* actual size of an undo structure */ 144 #define SEMUSZ (sizeof(struct sem_undo)+sizeof(struct undo)*SEMUME) 145 146 extern struct semid_ds *sema; /* semaphore id pool */ 147 extern struct sem *sem; /* semaphore pool */ 148 extern struct sem_undo *semu_list; /* list of active undo structures */ 149 extern int *semu; /* undo structure pool */ 150 151 /* 152 * Macro to find a particular sem_undo vector 153 */ 154 #define SEMU(ix) ((struct sem_undo *)(((long)semu)+ix * SEMUSZ)) 155 156 /* 157 * Process sem_undo vectors at proc exit. 158 */ 159 void semexit __P((struct proc *p)); 160 161 /* 162 * Parameters to the semconfig system call 163 */ 164 typedef enum { 165 SEM_CONFIG_FREEZE, /* Freeze the semaphore facility. */ 166 SEM_CONFIG_THAW /* Thaw the semaphore facility. */ 167 } semconfig_ctl_t; 168 #endif /* KERNEL */ 169 170 #ifndef KERNEL 171 #include <sys/cdefs.h> 172 173 __BEGIN_DECLS 174 int semsys __P((int, ...)); 175 int semctl __P((int, int, int, union semun)); 176 int semget __P((key_t, int, int)); 177 int semop __P((int, struct sembuf *,unsigned)); 178 __END_DECLS 179 #endif /* !KERNEL */ 180 181 #endif /* !_SEM_H_ */ 182