00001 /* $FreeBSD: src/sys/sys/sem.h,v 1.29 2004/11/17 13:12:06 rwatson Exp $ */ 00002 /* $NetBSD: sem.h,v 1.5 1994/06/29 06:45:15 cgd Exp $ */ 00003 00004 /* 00005 *© Portions copyright (c) 2006 Nokia Corporation. All rights reserved. 00006 *© Portions copyright (c) 2006 Symbian Software Ltd. All rights reserved. 00007 * SVID compatible sem.h file 00008 * 00009 * Author: Daniel Boulet 00010 */ 00011 00012 #ifndef _SYS_SEM_H_ 00013 #define _SYS_SEM_H_ 00014 00015 #include <sys/ipc.h> 00016 00017 00018 struct sem { 00019 u_short semval; /* semaphore value */ 00020 pid_t sempid; /* process ID of last operation */ 00021 u_short semncnt; /* number of processes waiting for semval 00022 to become greater than current value */ 00023 u_short semzcnt; /* number of processes waiting for semval 00024 to become 0 */ 00025 }; 00026 00027 struct semid_ds { 00028 struct ipc_perm sem_perm; /* operation permission struct */ 00029 struct sem *sem_base; /* pointer to first semaphore in set */ 00030 unsigned short sem_nsems; /* number of sems in set */ 00031 time_t sem_otime; /* last operation time */ 00032 long sem_pad1; /* SVABI/386 says I need this here */ 00033 time_t sem_ctime; /* last change time */ 00034 /* Times measured in secs since */ 00035 /* 00:00:00 GMT, Jan. 1, 1970 */ 00036 long sem_pad2; /* SVABI/386 says I need this here */ 00037 long sem_pad3[4]; /* SVABI/386 says I need this here */ 00038 }; 00039 00040 /* 00041 * semop's sops parameter structure 00042 */ 00043 struct sembuf { 00044 unsigned short sem_num; /* semaphore # */ 00045 short sem_op; /* semaphore operation */ 00046 short sem_flg; /* operation flags */ 00047 }; 00048 #define SEM_UNDO 010000 00049 00050 /* 00051 * semctl's arg parameter structure 00052 */ 00053 union semun { 00054 int val; /* value for SETVAL */ 00055 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ 00056 unsigned short *array; /* array for GETALL & SETALL */ 00057 }; 00058 00059 /* 00060 * commands for semctl 00061 */ 00062 #define GETNCNT 3 /* Return the value of semncnt {READ} */ 00063 #define GETPID 4 /* Return the value of sempid {READ} */ 00064 #define GETVAL 5 /* Return the value of semval {READ} */ 00065 #define GETALL 6 /* Return semvals into arg.array {READ} */ 00066 #define GETZCNT 7 /* Return the value of semzcnt {READ} */ 00067 #define SETVAL 8 /* Set the value of semval to arg.val {ALTER} */ 00068 #define SETALL 9 /* Set semvals from arg.array {ALTER} */ 00069 #define SEM_STAT 10 /* Like IPC_STAT but treats semid as sema-index */ 00070 #define SEM_INFO 11 /* Like IPC_INFO but treats semid as sema-index */ 00071 00072 /* 00073 * Permissions 00074 */ 00075 #define SEM_A IPC_W /* alter permission */ 00076 #define SEM_R IPC_R /* read permission */ 00077 00078 #ifdef _KERNEL 00079 00080 /* 00081 * semaphore info struct 00082 */ 00083 struct seminfo { 00084 int semmap, /* # of entries in semaphore map */ 00085 semmni, /* # of semaphore identifiers */ 00086 semmns, /* # of semaphores in system */ 00087 semmnu, /* # of undo structures in system */ 00088 semmsl, /* max # of semaphores per id */ 00089 semopm, /* max # of operations per semop call */ 00090 semume, /* max # of undo entries per process */ 00091 semusz, /* size in bytes of undo structure */ 00092 semvmx, /* semaphore maximum value */ 00093 semaem; /* adjust on exit max value */ 00094 }; 00095 extern struct seminfo seminfo; 00096 00097 /* 00098 * Kernel wrapper for the user-level structure 00099 */ 00100 struct semid_kernel { 00101 struct semid_ds u; 00102 struct label *label; /* MAC framework label */ 00103 }; 00104 00105 /* internal "mode" bits */ 00106 #define SEM_ALLOC 01000 /* semaphore is allocated */ 00107 #define SEM_DEST 02000 /* semaphore will be destroyed on last detach */ 00108 00109 /* 00110 * Process sem_undo vectors at proc exit. 00111 */ 00112 void semexit(struct proc *p); 00113 #endif /* _KERNEL */ 00114 00115 #ifndef _KERNEL 00116 #include <sys/cdefs.h> 00117 #include <sys/_types.h> 00118 00119 #ifndef _SIZE_T_DECLARED 00120 typedef __size_t size_t; 00121 #define _SIZE_T_DECLARED 00122 #endif 00123 00124 #ifndef _PID_T_DECLARED 00125 typedef __pid_t pid_t; 00126 #define _PID_T_DECLARED 00127 #endif 00128 00129 // FUNCTION PROTOTYPES 00130 00131 00132 // FORWARD DECLARATIONS 00133 00134 00135 // CLASS/STRUCT/FUNCTION DECLARATION 00136 00137 __BEGIN_DECLS 00138 00139 /* 00140 * Get semaphore identifier using the IPC key generated by ftok. 00141 */ 00142 00143 IMPORT_C int semget(key_t key, int nsems, int semflg); 00144 00145 00146 /* 00147 * Perform atomically a user-defined array of semaphore operations on the set of 00148 * semaphores associated with the semaphore identifier specified by the argument semid. 00149 */ 00150 00151 IMPORT_C int semop(int semid, struct sembuf *sops, unsigned nsops); 00152 00153 00154 /* 00155 * Provides a variety of semaphore control operations as specified by cmd. 00156 */ 00157 IMPORT_C int semctl(int semid, int semnum, int cmd, ...); 00158 00159 00160 __END_DECLS 00161 // #ifndef _KERNEL 00162 #endif 00163 00164 // _SYS_SEM_H_ 00165 #endif 00166 00167 // End of File