summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/include/semaphore.h
blob: 109766f67d530ed90f71f1dbed99c8b072859a64 (plain) (blame)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/**
 * @file
 * 
 * @brief Private Support Information for POSIX Semaphores
 *
 * This file contains definitions that are internal to the RTEMS
 * implementation of POSIX Semaphores.
 */

/*
 *  COPYRIGHT (c) 1989-2011.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.com/license/LICENSE.
 */

#ifndef _SEMAPHORE_H
#define _SEMAPHORE_H

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @defgroup POSIX_SEMAPHORE POSIX Semaphores Support
 *
 * @ingroup POSIXAPI
 *
 * @brief Private Support Information for POSIX Semaphores
 */

#include <unistd.h>

#if defined(_POSIX_SEMAPHORES)

#include <sys/time.h>

/*
 *  11.1 Semaphore Characteristics, P1003.1b-1993, p.219
 */
typedef int sem_t;

/*
 *  Bad semaphore Id
 */
#define SEM_FAILED (sem_t *) -1

/*
 *  11.2.1 Initialize an Unnamed Semaphore, P1003.1b-1993, p.219
 */
int sem_init(
  sem_t         *sem,
  int            pshared,
  unsigned int   value
);

/**
 * @brief Destroy an unnamed semaphore.
 *
 * 11.2.2 Destroy an Unnamed Semaphore, P1003.1b-1993, p.220
 */
int sem_destroy(
  sem_t *sem
);

/*
 *  11.2.3 Initialize/Open a Named Semaphore, P1003.1b-1993, p.221
 *
 *  NOTE: Follows open() calling conventions.
 */
sem_t *sem_open(
  const char *name,
  int         oflag,
  ...
);

/**
 * @brief Close a named semaphore.
 *
 * Routine to close a semaphore that has been opened or initialized.
 *
 * 11.2.4 Close a Named Semaphore, P1003.1b-1993, p.224
 */
int sem_close(
  sem_t *sem
);

/**
 * @brief Remove a named semaphore.
 *
 * Unlinks a named semaphore, sem_close must also be called to remove
 * the semaphore.
 *
 * 11.2.5 Remove a Named Semaphore, P1003.1b-1993, p.225
 */
int sem_unlink(
  const char *name
);

/**
 * @brief Lock a semaphore.
 *
 * 11.2.6 Lock a Semaphore, P1003.1b-1993, p.226
 *
 * NOTE: P1003.4b/D8 adds sem_timedwait(), p. 27
 */
int sem_wait(
  sem_t *sem
);

/**
 * @brief Lock a semaphore.
 *
 * @see sem_wait()
 */
int sem_trywait(
  sem_t *sem
);

#if defined(_POSIX_TIMEOUTS)
/**
 * @brief Lock a semaphore.
 */
int sem_timedwait(
  sem_t                 *__restrict sem,
  const struct timespec *__restrict timeout
);
#endif

/**
 * @brief Unlock a semaphore.
 *
 * 11.2.7 Unlock a Semaphore, P1003.1b-1993, p.227
 */
int sem_post(
  sem_t  *sem
);

/**
 * @brief Get the value of a semaphore.
 *
 * 11.2.8 Get the Value of a Semaphore, P1003.1b-1993, p.229
 */
int sem_getvalue(
  sem_t  *__restrict sem,
  int    *__restrict sval
);

#endif   /* _POSIX_SEMAPHORES */

#ifdef __cplusplus
}
#endif

#endif
/* end of include file */