This repository has been archived by the owner on Aug 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsemaphore.h
102 lines (88 loc) · 3.04 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
95
96
97
98
99
100
101
102
/**
* \file semaphore.h (interface file)
*
* \brief Semaphore management.
*
* Operations defined on semaphores:
* \li creation of a set of semaphores
* \li connection to a previously created set of semaphores
* \li destruction of a previously created set of semaphores
* \li signalling start of operations
* \li <em>down</em> of a semaphore within the set
* \li <em>up</em> of a semaphore within the set.
*
* \author António Rui Borges - October 1995
*/
#ifndef SEMAPHORE_H_
#define SEMAPHORE_H_
/**
* \brief Creation of a set of semaphores.
*
* All semaphores in the set will be in set to <em>red state</em> upon creation.
* The function fails if there is already a semaphore set with a creation key equal to <tt>key</tt>.
*
* \param key creation key
* \param snum number of semaphores in the set (>= 1)
*
* \return set identifier, upon success
* \return -\c 1, when an error occurs (the actual situation is reported in <tt>errno</tt>)
*/
extern int semCreate (int key, unsigned int snum);
/**
* \brief Connection to a previously created set of semaphores.
*
* The function fails if there is no semaphore set with a creation key equal to <tt>key</tt>.
*
* \param key creation key
*
* \return set identifier, upon success
* \return -\c 1, when an error occurs (the actual situation is reported in <tt>errno</tt>)
*/
extern int semConnect (int key);
/**
* \brief Destruction of a previously created set of semaphores.
*
* The function fails if there is no semaphore set with an identifier equal to <tt>semgid</tt>.
*
* \param semgid set identifier
*
* \return \c 0, upon success
* \return -\c 1, when an error occurs (the actual situation is reported in <tt>errno</tt>)
*/
extern int semDestroy (int semgid);
/**
* \brief Signalling start of operations upon initialization of shared data structures.
*
* The function fails if there is no semaphore set with an identifier equal to <tt>semgid</tt>.
*
* \param semgid set identifier
*
* \return \c 0, upon success
* \return -\c 1, when an error occurs (the actual situation is reported in <tt>errno</tt>)
*/
extern int semSignal (int semgid);
/**
* \brief <em>Down</em> of a semaphore within the set.
*
* The function fails if there is no semaphore set with an identifier equal to <tt>semgid</tt>.
*
* \param semgid set identifier
* \param sindex semaphore location in the set (1 .. snum)
*
* \return \c 0, upon success
* \return -\c 1, when an error occurs (the actual situation is reported in <tt>errno</tt>)
*/
extern int semDown (int semgid, unsigned int sindex);
/**
* \brief <em>Up</em> of a semaphore within the set.
*
* The function fails if there is no semaphore set with an identifier equal to <tt>semgid</tt>.
*
* \param semgid set identifier
* \param sindex semaphore location in the set (1 .. snum)
*
* \return \c 0, upon success
* \return -\c 1, when an error occurs (the actual situation is reported in <tt>errno</tt>)
*/
extern int semUp (int semgid, unsigned int sindex);
#endif /* SEMAPHORE_H_ */