Subversion Repositories shark

Rev

Rev 422 | Details | Compare with Previous | Last modification | View Log | RSS feed

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