sem.h revision 2729
1/* $Id$ */ 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 15struct 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 22struct 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 */ 38struct 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 */ 50union 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#ifdef KERNEL 68/* 69 * Kernel implementation stuff 70 */ 71#define SEMVMX 32767 /* semaphore maximum value */ 72#define SEMAEM 16384 /* adjust on exit max value */ 73 74/* 75 * Permissions 76 */ 77#define SEM_A 0200 /* alter permission */ 78#define SEM_R 0400 /* read permission */ 79 80/* 81 * Undo structure (one per process) 82 */ 83struct sem_undo { 84 struct sem_undo *un_next; /* ptr to next active undo structure */ 85 struct proc *un_proc; /* owner of this structure */ 86 short un_cnt; /* # of active entries */ 87 struct undo { 88 short un_adjval; /* adjust on exit values */ 89 short un_num; /* semaphore # */ 90 int un_id; /* semid */ 91 } un_ent[1]; /* undo entries */ 92}; 93 94/* 95 * semaphore info struct 96 */ 97struct seminfo { 98 int semmap, /* # of entries in semaphore map */ 99 semmni, /* # of semaphore identifiers */ 100 semmns, /* # of semaphores in system */ 101 semmnu, /* # of undo structures in system */ 102 semmsl, /* max # of semaphores per id */ 103 semopm, /* max # of operations per semop call */ 104 semume, /* max # of undo entries per process */ 105 semusz, /* size in bytes of undo structure */ 106 semvmx, /* semaphore maximum value */ 107 semaem; /* adjust on exit max value */ 108}; 109struct seminfo seminfo; 110 111/* internal "mode" bits */ 112#define SEM_ALLOC 01000 /* semaphore is allocated */ 113#define SEM_DEST 02000 /* semaphore will be destroyed on last detach */ 114 115/* 116 * Configuration parameters 117 */ 118#ifndef SEMMNI 119#define SEMMNI 10 /* # of semaphore identifiers */ 120#endif 121#ifndef SEMMNS 122#define SEMMNS 60 /* # of semaphores in system */ 123#endif 124#ifndef SEMUME 125#define SEMUME 10 /* max # of undo entries per process */ 126#endif 127#ifndef SEMMNU 128#define SEMMNU 30 /* # of undo structures in system */ 129#endif 130 131/* shouldn't need tuning */ 132#ifndef SEMMAP 133#define SEMMAP 30 /* # of entries in semaphore map */ 134#endif 135#ifndef SEMMSL 136#define SEMMSL SEMMNS /* max # of semaphores per id */ 137#endif 138#ifndef SEMOPM 139#define SEMOPM 100 /* max # of operations per semop call */ 140#endif 141 142/* actual size of an undo structure */ 143#define SEMUSZ (sizeof(struct sem_undo)+sizeof(struct undo)*SEMUME) 144 145/* 146 * Structures allocated in machdep.c 147 */ 148struct semid_ds *sema; /* semaphore id pool */ 149struct sem *sem; /* semaphore pool */ 150struct map *semmap; /* semaphore allocation map */ 151struct sem_undo *semu_list; /* list of active undo structures */ 152int *semu; /* undo structure pool */ 153 154/* 155 * Macro to find a particular sem_undo vector 156 */ 157#define SEMU(ix) ((struct sem_undo *)(((long)semu)+ix * SEMUSZ)) 158 159/* 160 * Parameters to the semconfig system call 161 */ 162typedef enum { 163 SEM_CONFIG_FREEZE, /* Freeze the semaphore facility. */ 164 SEM_CONFIG_THAW /* Thaw the semaphore facility. */ 165} semconfig_ctl_t; 166#endif /* KERNEL */ 167 168#ifndef KERNEL 169#include <sys/cdefs.h> 170 171__BEGIN_DECLS 172int semsys __P((int, ...)); 173int semctl __P((int, int, int, union semun)); 174int semget __P((key_t, int, int)); 175int semop __P((int, struct sembuf *,unsigned)); 176__END_DECLS 177#endif /* !KERNEL */ 178 179#endif /* !_SEM_H_ */ 180