Merge branch 'vendor/DHCPCD'
[dragonfly.git] / lib / libc / sysvipc / sysvipc_sem.h
1 /* $FreeBSD: src/sys/kern/sysv_sem.c,v 1.69 2004/03/17 09:37:13 cperciva Exp $ */
2
3 /*
4  * Implementation of SVID semaphores
5  *
6  * Author:  Daniel Boulet
7  * Copyright (c) 2013 Larisa Grigore <larisagrigore@gmail.com>
8  *
9  * This software is provided ``AS IS'' without any warranties of any kind.
10  */
11
12 #ifndef _SYSVIPC_SEM_H_
13 #define _SYSVIPC_SEM_H_
14
15 #include <sys/sem.h>
16
17 #include "sysvipc_lock.h"
18 #include "sysvipc_lock_generic.h"
19
20 //#define SYSV_SEMS
21                 /* Used to define if each semaphore in the
22                  * set is protected by a mutex, the entire
23                  * group being protected by a read lock.
24                  * If SYSV_SEMS is not defined, then the entire
25                  * group is protected only by a write lock.
26                  */
27 struct sem {
28         u_short semval;         /* semaphore value */
29         pid_t   sempid;         /* pid of last operation */
30         u_short semncnt;        /* # awaiting semval > cval */
31         u_short semzcnt;        /* # awaiting semval = 0 */
32 #ifdef SYSV_SEMS
33         struct sysv_mutex sem_mutex;
34 #endif
35 };
36
37 /* Used internally. The struct semid_ds is used only
38  * by caller, as argument to semctl.
39  */
40 struct semid_ds_internal {
41         struct  ipc_perm sem_perm;      /* operation permission struct */
42         u_short sem_nsems;      /* number of sems in set */
43         time_t  sem_otime;      /* last operation time */
44         time_t  sem_ctime;      /* last change time */
45                                 /* Times measured in secs since */
46                                 /* 00:00:00 GMT, Jan. 1, 1970 */
47         struct  sem sem_base[0];        /* pointer to first semaphore in set */
48 };
49
50 struct semid_pool {
51 #ifdef SYSV_RWLOCK
52         struct sysv_rwlock rwlock;
53 #else
54         struct sysv_mutex mutex;
55 #endif
56         struct semid_ds_internal ds;
57         char gen;
58 };
59
60 /*
61  * Undo structure (one per process)
62  */
63 struct sem_undo {
64 //      pthread_rwlock_t un_lock;
65         int     un_pages;
66         short   un_cnt;                 /* # of active entries */
67         short   un_unused;
68         struct undo {
69                 short   un_adjval;      /* adjust on exit values */
70                 short   un_num;         /* semaphore # */
71                 int     un_id;          /* semid */
72         } un_ent[0];                    /* undo entries */
73 };
74
75 int sysvipc___semctl(int, int, int, union semun *);
76 int sysvipc_semget(key_t, int, int);
77 int sysvipc_semop(int, struct sembuf *, unsigned);
78
79 #endif /* !_SYSVIPC_SEM_H_ */