blob: de2deb8676bd6c39c55a439b5df98715915eb9c9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_SEM_H
2#define _LINUX_SEM_H
3
Arun Sharma600634972011-07-26 16:09:06 -07004#include <linux/atomic.h>
Manfred Spraul380af1b2008-07-25 01:48:06 -07005#include <linux/rcupdate.h>
Manfred Spraul31a7c472010-05-26 14:43:42 -07006#include <linux/cache.h>
David Howells607ca462012-10-13 10:46:48 +01007#include <uapi/linux/sem.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
Tim Schmielau8c65b4a2005-11-07 00:59:43 -08009struct task_struct;
10
Manfred Spraul1a233952017-07-12 14:34:38 -070011/* One semaphore structure for each semaphore in the system. */
12struct sem {
13 int semval; /* current value */
14 /*
15 * PID of the process that last modified the semaphore. For
16 * Linux, specifically these are:
17 * - semop
18 * - semctl, via SETVAL and SETALL.
19 * - at task exit when performing undo adjustments (see exit_sem).
20 */
21 int sempid;
22 spinlock_t lock; /* spinlock for fine-grained semtimedop */
23 struct list_head pending_alter; /* pending single-sop operations */
24 /* that alter the semaphore */
25 struct list_head pending_const; /* pending single-sop operations */
26 /* that do not alter the semaphore*/
27 time_t sem_otime; /* candidate for sem_otime */
28} ____cacheline_aligned_in_smp;
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030/* One sem_array data structure for each set of semaphores in the system. */
31struct sem_array {
Davidlohr Bueso60f3e002017-05-08 15:57:06 -070032 struct kern_ipc_perm sem_perm; /* permissions .. see ipc.h */
Manfred Spraul2cd648c2017-07-12 14:34:44 -070033 time_t sem_ctime; /* create/last semctl() time */
Manfred Spraul1a82e9e2013-07-08 16:01:23 -070034 struct list_head pending_alter; /* pending operations */
35 /* that alter the array */
36 struct list_head pending_const; /* pending complex operations */
37 /* that do not alter semvals */
Manfred Spraul4daa28f2008-07-25 01:48:04 -070038 struct list_head list_id; /* undo requests on this array */
Manfred Spraulb97e8202009-12-15 16:47:32 -080039 int sem_nsems; /* no. of semaphores in array */
40 int complex_count; /* pending complex operations */
Manfred Spraul9de5ab82017-02-27 14:28:18 -080041 unsigned int use_global_lock;/* >0: global lock required */
Manfred Spraul1a233952017-07-12 14:34:38 -070042
43 struct sem sems[];
Kees Cook3859a272016-10-28 01:22:25 -070044} __randomize_layout;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Manfred Spraulf567a182011-11-02 13:38:56 -070046#ifdef CONFIG_SYSVIPC
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048struct sysv_sem {
49 struct sem_undo_list *undo_list;
50};
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052extern int copy_semundo(unsigned long clone_flags, struct task_struct *tsk);
53extern void exit_sem(struct task_struct *tsk);
54
55#else
Manfred Spraulf567a182011-11-02 13:38:56 -070056
57struct sysv_sem {
58 /* empty */
59};
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061static inline int copy_semundo(unsigned long clone_flags, struct task_struct *tsk)
62{
63 return 0;
64}
65
66static inline void exit_sem(struct task_struct *tsk)
67{
68 return;
69}
70#endif
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#endif /* _LINUX_SEM_H */