Blame view

include/linux/sem.h 5.17 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
  #ifndef _LINUX_SEM_H
  #define _LINUX_SEM_H
  
  #include <linux/ipc.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  
  /* semop flags */
  #define SEM_UNDO        0x1000  /* undo the operation on exit */
  
  /* semctl Command Definitions. */
  #define GETPID  11       /* get sempid */
  #define GETVAL  12       /* get semval */
  #define GETALL  13       /* get all semval's */
  #define GETNCNT 14       /* get semncnt */
  #define GETZCNT 15       /* get semzcnt */
  #define SETVAL  16       /* set semval */
  #define SETALL  17       /* set all semval's */
  
  /* ipcs ctl cmds */
  #define SEM_STAT 18
  #define SEM_INFO 19
  
  /* Obsolete, used only for backwards compatibility and libc5 compiles */
  struct semid_ds {
  	struct ipc_perm	sem_perm;		/* permissions .. see ipc.h */
  	__kernel_time_t	sem_otime;		/* last semop time */
  	__kernel_time_t	sem_ctime;		/* last change time */
  	struct sem	*sem_base;		/* ptr to first semaphore in array */
  	struct sem_queue *sem_pending;		/* pending operations to be processed */
  	struct sem_queue **sem_pending_last;	/* last pending operation */
  	struct sem_undo	*undo;			/* undo requests on this array */
  	unsigned short	sem_nsems;		/* no. of semaphores in array */
  };
  
  /* Include the definition of semid64_ds */
  #include <asm/sembuf.h>
  
  /* semop system calls takes an array of these. */
  struct sembuf {
  	unsigned short  sem_num;	/* semaphore index in array */
  	short		sem_op;		/* semaphore operation */
  	short		sem_flg;	/* operation flags */
  };
  
  /* arg for semctl system calls. */
  union semun {
  	int val;			/* value for SETVAL */
  	struct semid_ds __user *buf;	/* buffer for IPC_STAT & IPC_SET */
  	unsigned short __user *array;	/* array for GETALL & SETALL */
  	struct seminfo __user *__buf;	/* buffer for IPC_INFO */
  	void __user *__pad;
  };
  
  struct  seminfo {
  	int semmap;
  	int semmni;
  	int semmns;
  	int semmnu;
  	int semmsl;
  	int semopm;
  	int semume;
  	int semusz;
  	int semvmx;
  	int semaem;
  };
  
  #define SEMMNI  128             /* <= IPCMNI  max # of semaphore identifiers */
  #define SEMMSL  250             /* <= 8 000 max num of semaphores per id */
  #define SEMMNS  (SEMMNI*SEMMSL) /* <= INT_MAX max # of semaphores in system */
  #define SEMOPM  32	        /* <= 1 000 max num of ops per semop call */
  #define SEMVMX  32767           /* <= 32767 semaphore maximum value */
  #define SEMAEM  SEMVMX          /* adjust on exit max value */
  
  /* unused */
  #define SEMUME  SEMOPM          /* max num of undo entries per process */
  #define SEMMNU  SEMMNS          /* num of undo structures system wide */
  #define SEMMAP  SEMMNS          /* # of entries in semaphore map */
  #define SEMUSZ  20		/* sizeof struct sem_undo */
  
  #ifdef __KERNEL__
8ffbc759a   David Woodhouse   Don't include <as...
80
  #include <asm/atomic.h>
380af1b33   Manfred Spraul   ipc/sem.c: rewrit...
81
  #include <linux/rcupdate.h>
31a7c4746   Manfred Spraul   ipc/sem.c: cachel...
82
  #include <linux/cache.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83

8c65b4a60   Tim Schmielau   [PATCH] fix remai...
84
  struct task_struct;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
85
86
87
88
  /* One semaphore structure for each semaphore in the system. */
  struct sem {
  	int	semval;		/* current value */
  	int	sempid;		/* pid of last operation */
b97e820ff   Manfred Spraul   ipc/sem.c: add a ...
89
  	struct list_head sem_pending; /* pending single-sop operations */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
91
92
93
  };
  
  /* One sem_array data structure for each set of semaphores in the system. */
  struct sem_array {
31a7c4746   Manfred Spraul   ipc/sem.c: cachel...
94
95
  	struct kern_ipc_perm	____cacheline_aligned_in_smp
  				sem_perm;	/* permissions .. see ipc.h */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
96
97
98
  	time_t			sem_otime;	/* last semop time */
  	time_t			sem_ctime;	/* last change time */
  	struct sem		*sem_base;	/* ptr to first semaphore in array */
a1193f8ec   Manfred Spraul   ipc/sem.c: conver...
99
  	struct list_head	sem_pending;	/* pending operations to be processed */
4daa28f6d   Manfred Spraul   ipc/sem.c: conver...
100
  	struct list_head	list_id;	/* undo requests on this array */
b97e820ff   Manfred Spraul   ipc/sem.c: add a ...
101
102
  	int			sem_nsems;	/* no. of semaphores in array */
  	int			complex_count;	/* pending complex operations */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
103
104
105
106
  };
  
  /* One queue for each sleeping process in the system. */
  struct sem_queue {
b97e820ff   Manfred Spraul   ipc/sem.c: add a ...
107
  	struct list_head	simple_list; /* queue of pending operations */
a1193f8ec   Manfred Spraul   ipc/sem.c: conver...
108
109
110
  	struct list_head	list;	 /* queue of pending operations */
  	struct task_struct	*sleeper; /* this process */
  	struct sem_undo		*undo;	 /* undo structure */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111
112
  	int    			pid;	 /* process id of requesting process */
  	int    			status;	 /* completion status of operation */
a1193f8ec   Manfred Spraul   ipc/sem.c: conver...
113
  	struct sembuf		*sops;	 /* array of pending operations */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
114
115
116
117
118
119
120
121
  	int			nsops;	 /* number of operations */
  	int			alter;   /* does the operation alter the array? */
  };
  
  /* Each task has a list of undo requests. They are executed automatically
   * when the process exits.
   */
  struct sem_undo {
380af1b33   Manfred Spraul   ipc/sem.c: rewrit...
122
123
124
125
  	struct list_head	list_proc;	/* per-process list: all undos from one process. */
  						/* rcu protected */
  	struct rcu_head		rcu;		/* rcu struct for sem_undo() */
  	struct sem_undo_list	*ulp;		/* sem_undo_list for the process */
4daa28f6d   Manfred Spraul   ipc/sem.c: conver...
126
  	struct list_head	list_id;	/* per semaphore array list: all undos for one array */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
127
128
129
130
131
132
133
134
  	int			semid;		/* semaphore set identifier */
  	short *			semadj;		/* array of adjustments, one per semaphore */
  };
  
  /* sem_undo_list controls shared access to the list of sem_undo structures
   * that may be shared among all a CLONE_SYSVSEM task group.
   */ 
  struct sem_undo_list {
4daa28f6d   Manfred Spraul   ipc/sem.c: conver...
135
136
137
  	atomic_t		refcnt;
  	spinlock_t		lock;
  	struct list_head	list_proc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
  };
  
  struct sysv_sem {
  	struct sem_undo_list *undo_list;
  };
  
  #ifdef CONFIG_SYSVIPC
  
  extern int copy_semundo(unsigned long clone_flags, struct task_struct *tsk);
  extern void exit_sem(struct task_struct *tsk);
  
  #else
  static inline int copy_semundo(unsigned long clone_flags, struct task_struct *tsk)
  {
  	return 0;
  }
  
  static inline void exit_sem(struct task_struct *tsk)
  {
  	return;
  }
  #endif
  
  #endif /* __KERNEL__ */
  
  #endif /* _LINUX_SEM_H */