Import 2.1.55pre1
[davej-history.git] / include / linux / sem.h
bloba5b3134bfaf607c013681e6e5c268085f14901ae
1 #ifndef _LINUX_SEM_H
2 #define _LINUX_SEM_H
4 #include <linux/ipc.h>
6 /* semop flags */
7 #define SEM_UNDO 0x1000 /* undo the operation on exit */
9 /* semctl Command Definitions. */
10 #define GETPID 11 /* get sempid */
11 #define GETVAL 12 /* get semval */
12 #define GETALL 13 /* get all semval's */
13 #define GETNCNT 14 /* get semncnt */
14 #define GETZCNT 15 /* get semzcnt */
15 #define SETVAL 16 /* set semval */
16 #define SETALL 17 /* set all semval's */
18 /* ipcs ctl cmds */
19 #define SEM_STAT 18
20 #define SEM_INFO 19
22 /* One semid data structure for each set of semaphores in the system. */
23 struct semid_ds {
24 struct ipc_perm sem_perm; /* permissions .. see ipc.h */
25 __kernel_time_t sem_otime; /* last semop time */
26 __kernel_time_t sem_ctime; /* last change time */
27 struct sem *sem_base; /* ptr to first semaphore in array */
28 struct sem_queue *sem_pending; /* pending operations to be processed */
29 struct sem_queue **sem_pending_last; /* last pending operation */
30 struct sem_undo *undo; /* undo requests on this array */
31 unsigned short sem_nsems; /* no. of semaphores in array */
34 /* semop system calls takes an array of these. */
35 struct sembuf {
36 unsigned short sem_num; /* semaphore index in array */
37 short sem_op; /* semaphore operation */
38 short sem_flg; /* operation flags */
41 /* arg for semctl system calls. */
42 union semun {
43 int val; /* value for SETVAL */
44 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
45 unsigned short *array; /* array for GETALL & SETALL */
46 struct seminfo *__buf; /* buffer for IPC_INFO */
47 void *__pad;
50 struct seminfo {
51 int semmap;
52 int semmni;
53 int semmns;
54 int semmnu;
55 int semmsl;
56 int semopm;
57 int semume;
58 int semusz;
59 int semvmx;
60 int semaem;
63 #define SEMMNI 128 /* ? max # of semaphore identifiers */
64 #define SEMMSL 32 /* <= 512 max num of semaphores per id */
65 #define SEMMNS (SEMMNI*SEMMSL) /* ? max # of semaphores in system */
66 #define SEMOPM 32 /* ~ 100 max num of ops per semop call */
67 #define SEMVMX 32767 /* semaphore maximum value */
69 /* unused */
70 #define SEMUME SEMOPM /* max num of undo entries per process */
71 #define SEMMNU SEMMNS /* num of undo structures system wide */
72 #define SEMAEM (SEMVMX >> 1) /* adjust on exit max value */
73 #define SEMMAP SEMMNS /* # of entries in semaphore map */
74 #define SEMUSZ 20 /* sizeof struct sem_undo */
76 #ifdef __KERNEL__
78 /* One semaphore structure for each semaphore in the system. */
79 struct sem {
80 int semval; /* current value */
81 int sempid; /* pid of last operation */
84 /* One queue for each semaphore set in the system. */
85 struct sem_queue {
86 struct sem_queue * next; /* next entry in the queue */
87 struct sem_queue ** prev; /* previous entry in the queue, *(q->prev) == q */
88 struct wait_queue * sleeper; /* sleeping process */
89 struct sem_undo * undo; /* undo structure */
90 int pid; /* process id of requesting process */
91 int status; /* completion status of operation */
92 struct semid_ds * sma; /* semaphore array for operations */
93 struct sembuf * sops; /* array of pending operations */
94 int nsops; /* number of operations */
97 /* Each task has a list of undo requests. They are executed automatically
98 * when the process exits.
100 struct sem_undo {
101 struct sem_undo * proc_next; /* next entry on this process */
102 struct sem_undo * id_next; /* next entry on this semaphore set */
103 int semid; /* semaphore set identifier */
104 short * semadj; /* array of adjustments, one per semaphore */
107 asmlinkage int sys_semget (key_t key, int nsems, int semflg);
108 asmlinkage int sys_semop (int semid, struct sembuf *sops, unsigned nsops);
109 asmlinkage int sys_semctl (int semid, int semnum, int cmd, union semun arg);
111 #endif /* __KERNEL__ */
113 #endif /* _LINUX_SEM_H */