-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsemaphore.h
94 lines (80 loc) · 2.35 KB
/
semaphore.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef SEMAPHORE_H
#define SEMAPHORE_H
#include <sys/ipc.h>
#include <sys/types.h>
#include <sys/sem.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* semctl() additional (4th) parameter union
*/
union semun {
int val; /* used for SETVAL only */
struct semid_ds *buf; /* used for IPC_STAT and IPC_SET */
ushort *array; /* used for GETALL and SETALL */
struct seminfo *__buf; /* Buffer for IPC_INFO, Linux specific */
};
/**
* @brief Initialize the semaphore set
* @param key Key generated by ftok()
* @param nsems Count of semaphore's in the set
* @param val Initialization values of all the semaphores in the set
* @return The semaphore-set-id if succeeded, -1 otherwise
*/
int semInit(key_t key, int nsems, int* vals);
/**
* @brief Set a semaphore's value
* @param semid Semaphore set's id
* @param semnum Semaphore's index in the set
* @param val Value the semaphore will set to
* @return 0 if successful, -1 otherwise
*/
int semSetValue(int semid, int semnum, int val);
/**
* @brief Get a semaphore's value
* @param semid Semaphore set's id
* @param semnum Semaphore's index in the set
* @return Semaphore's value if successful, -1 otherwise
*/
int semGetValue(int semid, int semnum);
/**
* @brief Semaphore pass-check operation
* If the semaphore less than or equal to 0, sem_p() would block
* @param semid Semaphore set's id
* @param semnum Semaphore's index in the set
* @return 0 if successful, -1 otherwise
*/
int semP(int semid, int semnum);
/**
* @brief Semaphore release operation
* Increse the semaphore and return immediately
* @param semid Semaphore set's id
* @param semnum Semaphore's index in the set
* @return 0 if successful, -1 otherwise
*/
int semV(int semid, int semnum);
/**
* @brief Remove the semaphore set
* @param semid Semaphore set's id
* @return 0 if successful, -1 otherwise
*/
int semRemove(int semid);
/**
* @brief Get samaphore's semncnt (man semctl)
* @param semid Semaphore set's id
* @param semnum Semaphore's index in the set
* @return The semaphore's semncnt
*/
int semncnt(int semid, int semnum);
/**
* @brief Get samaphore's semzcnt (man semctl)
* @param semid Semaphore set's id
* @param semnum Semaphore's index in the set
* @return The semaphore's semzcnt
*/
int semnznt(int semid, int semnum);
#ifdef __cplusplus
}
#endif
#endif /* End of header file */