1 /* $FreeBSD: src/sys/kern/sysv_sem.c,v 1.69 2004/03/17 09:37:13 cperciva Exp $ */
4 * Implementation of SVID semaphores
6 * Author: Daniel Boulet
7 * Copyright (c) 2013 Larisa Grigore <larisagrigore@gmail.com>
9 * This software is provided ``AS IS'' without any warranties of any kind.
17 #include "sysvipc_lock.h"
18 #include "sysvipc_lock_generic.h"
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.
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 */
33 struct sysv_mutex sem_mutex
;
37 /* Used internally. The struct semid_ds is used only
38 * by caller, as argument to semctl.
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 */
52 struct sysv_rwlock rwlock
;
54 struct sysv_mutex mutex
;
56 struct semid_ds_internal ds
;
61 * Undo structure (one per process)
64 // pthread_rwlock_t un_lock;
66 short un_cnt
; /* # of active entries */
69 short un_adjval
; /* adjust on exit values */
70 short un_num
; /* semaphore # */
71 int un_id
; /* semid */
72 } un_ent
[0]; /* undo entries */
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);