1 #ifndef _LINUX_SEM_H 2 #define _LINUX_SEM_H 3 #include <linux/ipc.h> 4 5 /* semop flags */ 6 #define SEM_UNDO 010000 /* undo the operation on exit */ 7 8 /* semctl Command Definitions. */ 9 #define GETPID 11 /* get sempid */ 10 #define GETVAL 12 /* get semval */ 11 #define GETALL 13 /* get all semval's */ 12 #define GETNCNT 14 /* get semncnt */ 13 #define GETZCNT 15 /* get semzcnt */ 14 #define SETVAL 16 /* set semval */ 15 #define SETALL 17 /* set all semval's */ 16 17 /* One semid data structure for each set of semaphores in the system. */ 18 struct semid_ds { 19 struct ipc_perm sem_perm; /* permissions .. see ipc.h */ 20 time_t sem_otime; /* last semop time */ 21 time_t sem_ctime; /* last change time */ 22 struct sem *sem_base; /* ptr to first semaphore in array */ 23 struct wait_queue *eventn; 24 struct wait_queue *eventz; 25 struct sem_undo *undo; /* undo requests on this array */ 26 ushort sem_nsems; /* no. of semaphores in array */ 27 }; 28 29 30 /* One semaphore structure for each semaphore in the system. */ 31 struct sem { 32 short sempid; /* pid of last operation */ 33 ushort semval; /* current value */ 34 ushort semncnt; /* num procs awaiting increase in semval */ 35 ushort semzcnt; /* num procs awaiting semval = 0 */ 36 }; 37 38 /* semop system calls takes an array of these.*/ 39 struct sembuf { 40 ushort sem_num; /* semaphore index in array */ 41 short sem_op; /* semaphore operation */ 42 short sem_flg; /* operation flags */ 43 }; 44 45 /* arg for semctl system calls. */ 46 union semun { 47 int val; /* value for SETVAL */ 48 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ 49 ushort *array; /* array for GETALL & SETALL */ 50 }; 51 52 53 struct seminfo { 54 int semmap; 55 int semmni; 56 int semmns; 57 int semmnu; 58 int semmsl; 59 int semopm; 60 int semume; 61 int semusz; 62 int semvmx; 63 int semaem; 64 }; 65 66 #define SEMMNI 128 /* ? max # of semaphore identifiers */ 67 #define SEMMSL 32 /* <= 512 max num of semaphores per id */ 68 #define SEMMNS (SEMMNI*SEMMSL) /* ? max # of semaphores in system */ 69 #define SEMOPM 32 /* ~ 100 max num of ops per semop call */ 70 #define SEMVMX 32767 /* semaphore maximum value */ 71 72 /* unused */ 73 #define SEMUME SEMOPM /* max num of undo entries per process */ 74 #define SEMMNU SEMMNS /* num of undo structures system wide */ 75 #define SEMAEM (SEMVMX >> 1) /* adjust on exit max value */ 76 #define SEMMAP SEMMNS /* # of entries in semaphore map */ 77 #define SEMUSZ 20 /* sizeof struct sem_undo */ 78 79 #ifdef __KERNEL__ 80 /* ipcs ctl cmds */ 81 #define SEM_STAT 18 82 #define SEM_INFO 19 83 84 /* per process undo requests */ 85 /* this gets linked into the task_struct */ 86 struct sem_undo { 87 struct sem_undo *proc_next; 88 struct sem_undo *id_next; 89 int semid; 90 short semadj; /* semval adjusted by exit */ 91 ushort sem_num; /* semaphore index in array semid */ 92 }; 93 94 #endif /* __KERNEL__ */ 95 96 #endif /* _LINUX_SEM_H */