sem.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef _LINUX_SEM_H
  2. #define _LINUX_SEM_H
  3. #include <linux/atomic.h>
  4. #include <linux/rcupdate.h>
  5. #include <linux/cache.h>
  6. #include <linux/time64.h>
  7. #include <uapi/linux/sem.h>
  8. struct task_struct;
  9. /* One semaphore structure for each semaphore in the system. */
  10. struct sem {
  11. int semval; /* current value */
  12. /*
  13. * PID of the process that last modified the semaphore. For
  14. * Linux, specifically these are:
  15. * - semop
  16. * - semctl, via SETVAL and SETALL.
  17. * - at task exit when performing undo adjustments (see exit_sem).
  18. */
  19. int sempid;
  20. spinlock_t lock; /* spinlock for fine-grained semtimedop */
  21. struct list_head pending_alter; /* pending single-sop operations */
  22. /* that alter the semaphore */
  23. struct list_head pending_const; /* pending single-sop operations */
  24. /* that do not alter the semaphore*/
  25. time_t sem_otime; /* candidate for sem_otime */
  26. } ____cacheline_aligned_in_smp;
  27. /* One sem_array data structure for each set of semaphores in the system. */
  28. struct sem_array {
  29. struct kern_ipc_perm sem_perm; /* permissions .. see ipc.h */
  30. time64_t sem_ctime; /* create/last semctl() time */
  31. struct list_head pending_alter; /* pending operations */
  32. /* that alter the array */
  33. struct list_head pending_const; /* pending complex operations */
  34. /* that do not alter semvals */
  35. struct list_head list_id; /* undo requests on this array */
  36. int sem_nsems; /* no. of semaphores in array */
  37. int complex_count; /* pending complex operations */
  38. unsigned int use_global_lock;/* >0: global lock required */
  39. struct sem sems[];
  40. } __randomize_layout;
  41. #ifdef CONFIG_SYSVIPC
  42. struct sysv_sem {
  43. struct sem_undo_list *undo_list;
  44. };
  45. extern int copy_semundo(unsigned long clone_flags, struct task_struct *tsk);
  46. extern void exit_sem(struct task_struct *tsk);
  47. #else
  48. struct sysv_sem {
  49. /* empty */
  50. };
  51. static inline int copy_semundo(unsigned long clone_flags, struct task_struct *tsk)
  52. {
  53. return 0;
  54. }
  55. static inline void exit_sem(struct task_struct *tsk)
  56. {
  57. return;
  58. }
  59. #endif
  60. #endif /* _LINUX_SEM_H */