blob: 0083128318f6da53dc1d29cecb3145096bd22a9a [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>
Deepa Dinamanie54d02b2017-08-02 19:51:13 -07007#include <linux/time64.h>
David Howells607ca462012-10-13 10:46:48 +01008#include <uapi/linux/sem.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Tim Schmielau8c65b4a2005-11-07 00:59:43 -080010struct task_struct;
11
Manfred Spraul1a233952017-07-12 14:34:38 -070012/* One semaphore structure for each semaphore in the system. */
13struct sem {
14 int semval; /* current value */
15 /*
16 * PID of the process that last modified the semaphore. For
17 * Linux, specifically these are:
18 * - semop
19 * - semctl, via SETVAL and SETALL.
20 * - at task exit when performing undo adjustments (see exit_sem).
21 */
22 int sempid;
23 spinlock_t lock; /* spinlock for fine-grained semtimedop */
24 struct list_head pending_alter; /* pending single-sop operations */
25 /* that alter the semaphore */
26 struct list_head pending_const; /* pending single-sop operations */
27 /* that do not alter the semaphore*/
28 time_t sem_otime; /* candidate for sem_otime */
29} ____cacheline_aligned_in_smp;
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031/* One sem_array data structure for each set of semaphores in the system. */
32struct sem_array {
Davidlohr Bueso60f3e002017-05-08 15:57:06 -070033 struct kern_ipc_perm sem_perm; /* permissions .. see ipc.h */
Deepa Dinamanie54d02b2017-08-02 19:51:13 -070034 time64_t sem_ctime; /* create/last semctl() time */
Manfred Spraul1a82e9e2013-07-08 16:01:23 -070035 struct list_head pending_alter; /* pending operations */
36 /* that alter the array */
37 struct list_head pending_const; /* pending complex operations */
38 /* that do not alter semvals */
Manfred Spraul4daa28f2008-07-25 01:48:04 -070039 struct list_head list_id; /* undo requests on this array */
Manfred Spraulb97e8202009-12-15 16:47:32 -080040 int sem_nsems; /* no. of semaphores in array */
41 int complex_count; /* pending complex operations */
Manfred Spraul9de5ab82017-02-27 14:28:18 -080042 unsigned int use_global_lock;/* >0: global lock required */
Manfred Spraul1a233952017-07-12 14:34:38 -070043
44 struct sem sems[];
Kees Cook3859a272016-10-28 01:22:25 -070045} __randomize_layout;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Manfred Spraulf567a182011-11-02 13:38:56 -070047#ifdef CONFIG_SYSVIPC
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049struct sysv_sem {
50 struct sem_undo_list *undo_list;
51};
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053extern int copy_semundo(unsigned long clone_flags, struct task_struct *tsk);
54extern void exit_sem(struct task_struct *tsk);
55
56#else
Manfred Spraulf567a182011-11-02 13:38:56 -070057
58struct sysv_sem {
59 /* empty */
60};
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062static inline int copy_semundo(unsigned long clone_flags, struct task_struct *tsk)
63{
64 return 0;
65}
66
67static inline void exit_sem(struct task_struct *tsk)
68{
69 return;
70}
71#endif
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#endif /* _LINUX_SEM_H */