sem.h
上传用户:szlgq88
上传日期:2009-04-28
资源大小:48287k
文件大小:5k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. #ifndef _LINUX_SEM_H
  2. #define _LINUX_SEM_H
  3. #include <linux/ipc.h>
  4. #include <asm/atomic.h>
  5. /* semop flags */
  6. #define SEM_UNDO        0x1000  /* undo the operation on exit */
  7. /* semctl Command Definitions. */
  8. #define GETPID  11       /* get sempid */
  9. #define GETVAL  12       /* get semval */
  10. #define GETALL  13       /* get all semval's */
  11. #define GETNCNT 14       /* get semncnt */
  12. #define GETZCNT 15       /* get semzcnt */
  13. #define SETVAL  16       /* set semval */
  14. #define SETALL  17       /* set all semval's */
  15. /* ipcs ctl cmds */
  16. #define SEM_STAT 18
  17. #define SEM_INFO 19
  18. /* Obsolete, used only for backwards compatibility and libc5 compiles */
  19. struct semid_ds {
  20. struct ipc_perm sem_perm; /* permissions .. see ipc.h */
  21. __kernel_time_t sem_otime; /* last semop time */
  22. __kernel_time_t sem_ctime; /* last change time */
  23. struct sem *sem_base; /* ptr to first semaphore in array */
  24. struct sem_queue *sem_pending; /* pending operations to be processed */
  25. struct sem_queue **sem_pending_last; /* last pending operation */
  26. struct sem_undo *undo; /* undo requests on this array */
  27. unsigned short sem_nsems; /* no. of semaphores in array */
  28. };
  29. /* Include the definition of semid64_ds */
  30. #include <asm/sembuf.h>
  31. /* semop system calls takes an array of these. */
  32. struct sembuf {
  33. unsigned short  sem_num; /* semaphore index in array */
  34. short sem_op; /* semaphore operation */
  35. short sem_flg; /* operation flags */
  36. };
  37. /* arg for semctl system calls. */
  38. union semun {
  39. int val; /* value for SETVAL */
  40. struct semid_ds __user *buf; /* buffer for IPC_STAT & IPC_SET */
  41. unsigned short __user *array; /* array for GETALL & SETALL */
  42. struct seminfo __user *__buf; /* buffer for IPC_INFO */
  43. void __user *__pad;
  44. };
  45. struct  seminfo {
  46. int semmap;
  47. int semmni;
  48. int semmns;
  49. int semmnu;
  50. int semmsl;
  51. int semopm;
  52. int semume;
  53. int semusz;
  54. int semvmx;
  55. int semaem;
  56. };
  57. #define SEMMNI  128             /* <= IPCMNI  max # of semaphore identifiers */
  58. #define SEMMSL  250             /* <= 8 000 max num of semaphores per id */
  59. #define SEMMNS  (SEMMNI*SEMMSL) /* <= INT_MAX max # of semaphores in system */
  60. #define SEMOPM  32         /* <= 1 000 max num of ops per semop call */
  61. #define SEMVMX  32767           /* <= 32767 semaphore maximum value */
  62. #define SEMAEM  SEMVMX          /* adjust on exit max value */
  63. /* unused */
  64. #define SEMUME  SEMOPM          /* max num of undo entries per process */
  65. #define SEMMNU  SEMMNS          /* num of undo structures system wide */
  66. #define SEMMAP  SEMMNS          /* # of entries in semaphore map */
  67. #define SEMUSZ  20 /* sizeof struct sem_undo */
  68. #ifdef __KERNEL__
  69. /* One semaphore structure for each semaphore in the system. */
  70. struct sem {
  71. int semval; /* current value */
  72. int sempid; /* pid of last operation */
  73. };
  74. /* One sem_array data structure for each set of semaphores in the system. */
  75. struct sem_array {
  76. struct kern_ipc_perm sem_perm; /* permissions .. see ipc.h */
  77. int sem_id;
  78. time_t sem_otime; /* last semop time */
  79. time_t sem_ctime; /* last change time */
  80. struct sem *sem_base; /* ptr to first semaphore in array */
  81. struct sem_queue *sem_pending; /* pending operations to be processed */
  82. struct sem_queue **sem_pending_last; /* last pending operation */
  83. struct sem_undo *undo; /* undo requests on this array */
  84. unsigned long sem_nsems; /* no. of semaphores in array */
  85. };
  86. /* One queue for each sleeping process in the system. */
  87. struct sem_queue {
  88. struct sem_queue * next;  /* next entry in the queue */
  89. struct sem_queue ** prev;  /* previous entry in the queue, *(q->prev) == q */
  90. struct task_struct* sleeper; /* this process */
  91. struct sem_undo * undo;  /* undo structure */
  92. int     pid;  /* process id of requesting process */
  93. int     status;  /* completion status of operation */
  94. struct sem_array * sma;  /* semaphore array for operations */
  95. int id;  /* internal sem id */
  96. struct sembuf * sops;  /* array of pending operations */
  97. int nsops;  /* number of operations */
  98. int alter;   /* does the operation alter the array? */
  99. };
  100. /* Each task has a list of undo requests. They are executed automatically
  101.  * when the process exits.
  102.  */
  103. struct sem_undo {
  104. struct sem_undo * proc_next; /* next entry on this process */
  105. struct sem_undo * id_next; /* next entry on this semaphore set */
  106. int semid; /* semaphore set identifier */
  107. short * semadj; /* array of adjustments, one per semaphore */
  108. };
  109. /* sem_undo_list controls shared access to the list of sem_undo structures
  110.  * that may be shared among all a CLONE_SYSVSEM task group.
  111.  */ 
  112. struct sem_undo_list {
  113. atomic_t refcnt;
  114. spinlock_t lock;
  115. struct sem_undo *proc_list;
  116. };
  117. struct sysv_sem {
  118. struct sem_undo_list *undo_list;
  119. };
  120. #ifdef CONFIG_SYSVIPC
  121. extern int copy_semundo(unsigned long clone_flags, struct task_struct *tsk);
  122. extern void exit_sem(struct task_struct *tsk);
  123. #else
  124. static inline int copy_semundo(unsigned long clone_flags, struct task_struct *tsk)
  125. {
  126. return 0;
  127. }
  128. static inline void exit_sem(struct task_struct *tsk)
  129. {
  130. return;
  131. }
  132. #endif
  133. #endif /* __KERNEL__ */
  134. #endif /* _LINUX_SEM_H */