Debian Codegraph @

listings/chapter-5/sem_all_deall.c

raw
1 /***********************************************************************
2 * Code listing from "Advanced Linux Programming," by CodeSourcery LLC *
3 * Copyright (C) 2001 by New Riders Publishing *
4 * See COPYRIGHT for license information. *
5 ***********************************************************************/
6
7 #include <sys/ipc.h>
8 #include <sys/sem.h>
9 #include <sys/types.h>
10
11 /* We must define union semun ourselves. */
12
13 union semun {
14 int val;
15 struct semid_ds *buf;
16 unsigned short int *array;
17 struct seminfo *__buf;
18 };
19
20 /* Obtain a binary semaphore's ID, allocating if necessary. */
21
22 int binary_semaphore_allocation (key_t key, int sem_flags)
23 {
24 return semget (key, 1, sem_flags);
25 }
26
27 /* Deallocate a binary semaphore. All users must have finished their
28 use. Returns -1 on failure. */
29
30 int binary_semaphore_deallocate (int semid)
31 {
32 union semun ignored_argument;
33 return semctl (semid, 1, IPC_RMID, ignored_argument);
34 }