1 /* $FreeBSD$ */ 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 17 struct semid_ds { 18 struct ipc_perm sem_perm; /* operation permission struct */ 19 struct sem *sem_base; /* pointer to first semaphore in set */ 20 unsigned short sem_nsems; /* number of sems in set */ 21 time_t sem_otime; /* last operation time */ 22 long sem_pad1; /* SVABI/386 says I need this here */ 23 time_t sem_ctime; /* last change time */ 24 /* Times measured in secs since */ 25 /* 00:00:00 GMT, Jan. 1, 1970 */ 26 long sem_pad2; /* SVABI/386 says I need this here */ 27 long sem_pad3[4]; /* SVABI/386 says I need this here */ 28 }; 29 30 /* 31 * semop's sops parameter structure 32 */ 33 struct sembuf { 34 unsigned short sem_num; /* semaphore # */ 35 short sem_op; /* semaphore operation */ 36 short sem_flg; /* operation flags */ 37 }; 38 #define SEM_UNDO 010000 39 40 /* 41 * semctl's arg parameter structure 42 */ 43 union semun { 44 int val; /* value for SETVAL */ 45 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ 46 unsigned short *array; /* array for GETALL & SETALL */ 47 }; 48 49 /* 50 * commands for semctl 51 */ 52 #define GETNCNT 3 /* Return the value of semncnt {READ} */ 53 #define GETPID 4 /* Return the value of sempid {READ} */ 54 #define GETVAL 5 /* Return the value of semval {READ} */ 55 #define GETALL 6 /* Return semvals into arg.array {READ} */ 56 #define GETZCNT 7 /* Return the value of semzcnt {READ} */ 57 #define SETVAL 8 /* Set the value of semval to arg.val {ALTER} */ 58 #define SETALL 9 /* Set semvals from arg.array {ALTER} */ 59 #define SEM_STAT 10 /* Like IPC_STAT but treats semid as sema-index */ 60 #define SEM_INFO 11 /* Like IPC_INFO but treats semid as sema-index */ 61 62 /* 63 * Permissions 64 */ 65 #define SEM_A IPC_W /* alter permission */ 66 #define SEM_R IPC_R /* read permission */ 67 68 #ifdef _KERNEL 69 70 /* 71 * semaphore info struct 72 */ 73 struct seminfo { 74 int semmap, /* # of entries in semaphore map */ 75 semmni, /* # of semaphore identifiers */ 76 semmns, /* # of semaphores in system */ 77 semmnu, /* # of undo structures in system */ 78 semmsl, /* max # of semaphores per id */ 79 semopm, /* max # of operations per semop call */ 80 semume, /* max # of undo entries per process */ 81 semusz, /* size in bytes of undo structure */ 82 semvmx, /* semaphore maximum value */ 83 semaem; /* adjust on exit max value */ 84 }; 85 extern struct seminfo seminfo; 86 87 /* internal "mode" bits */ 88 #define SEM_ALLOC 01000 /* semaphore is allocated */ 89 #define SEM_DEST 02000 /* semaphore will be destroyed on last detach */ 90 91 /* 92 * Process sem_undo vectors at proc exit. 93 */ 94 void semexit(struct proc *p); 95 #endif /* _KERNEL */ 96 97 #ifndef _KERNEL 98 #include <sys/cdefs.h> 99 #include <sys/_types.h> 100 101 #ifndef _SIZE_T_DECLARED 102 typedef __size_t size_t; 103 #define _SIZE_T_DECLARED 104 #endif 105 106 #ifndef _PID_T_DECLARED 107 typedef __pid_t pid_t; 108 #define _PID_T_DECLARED 109 #endif 110 111 __BEGIN_DECLS 112 int semsys(int, ...); 113 int semctl(int, int, int, ...); 114 int semget(key_t, int, int); 115 int semop(int, struct sembuf *, size_t); 116 __END_DECLS 117 #endif /* !_KERNEL */ 118 119 #endif /* !_SYS_SEM_H_ */ 120