Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_SEM_H |
| 2 | #define _LINUX_SEM_H |
| 3 | |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 4 | #include <linux/atomic.h> |
Manfred Spraul | 380af1b | 2008-07-25 01:48:06 -0700 | [diff] [blame] | 5 | #include <linux/rcupdate.h> |
Manfred Spraul | 31a7c47 | 2010-05-26 14:43:42 -0700 | [diff] [blame] | 6 | #include <linux/cache.h> |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 7 | #include <uapi/linux/sem.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
Tim Schmielau | 8c65b4a | 2005-11-07 00:59:43 -0800 | [diff] [blame] | 9 | struct task_struct; |
| 10 | |
Manfred Spraul | 1a23395 | 2017-07-12 14:34:38 -0700 | [diff] [blame] | 11 | /* One semaphore structure for each semaphore in the system. */ |
| 12 | struct 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | /* One sem_array data structure for each set of semaphores in the system. */ |
| 31 | struct sem_array { |
Davidlohr Bueso | 60f3e00 | 2017-05-08 15:57:06 -0700 | [diff] [blame] | 32 | struct kern_ipc_perm sem_perm; /* permissions .. see ipc.h */ |
Manfred Spraul | 2cd648c | 2017-07-12 14:34:44 -0700 | [diff] [blame] | 33 | time_t sem_ctime; /* create/last semctl() time */ |
Manfred Spraul | 1a82e9e | 2013-07-08 16:01:23 -0700 | [diff] [blame] | 34 | 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 Spraul | 4daa28f | 2008-07-25 01:48:04 -0700 | [diff] [blame] | 38 | struct list_head list_id; /* undo requests on this array */ |
Manfred Spraul | b97e820 | 2009-12-15 16:47:32 -0800 | [diff] [blame] | 39 | int sem_nsems; /* no. of semaphores in array */ |
| 40 | int complex_count; /* pending complex operations */ |
Manfred Spraul | 9de5ab8 | 2017-02-27 14:28:18 -0800 | [diff] [blame] | 41 | unsigned int use_global_lock;/* >0: global lock required */ |
Manfred Spraul | 1a23395 | 2017-07-12 14:34:38 -0700 | [diff] [blame] | 42 | |
| 43 | struct sem sems[]; |
Kees Cook | 3859a27 | 2016-10-28 01:22:25 -0700 | [diff] [blame] | 44 | } __randomize_layout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Manfred Spraul | f567a18 | 2011-11-02 13:38:56 -0700 | [diff] [blame] | 46 | #ifdef CONFIG_SYSVIPC |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | struct sysv_sem { |
| 49 | struct sem_undo_list *undo_list; |
| 50 | }; |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | extern int copy_semundo(unsigned long clone_flags, struct task_struct *tsk); |
| 53 | extern void exit_sem(struct task_struct *tsk); |
| 54 | |
| 55 | #else |
Manfred Spraul | f567a18 | 2011-11-02 13:38:56 -0700 | [diff] [blame] | 56 | |
| 57 | struct sysv_sem { |
| 58 | /* empty */ |
| 59 | }; |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | static inline int copy_semundo(unsigned long clone_flags, struct task_struct *tsk) |
| 62 | { |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | static inline void exit_sem(struct task_struct *tsk) |
| 67 | { |
| 68 | return; |
| 69 | } |
| 70 | #endif |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #endif /* _LINUX_SEM_H */ |