source: rtems/cpukit/rtems/include/rtems/rtems/sem.h @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 6.1 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup ClassicSem
5 *
6 * @brief Classic Semaphores API
7 *
8 * This include file contains all the constants and structures associated
9 * with the Semaphore Manager. This manager utilizes standard Dijkstra
10 * counting semaphores to provide synchronization and mutual exclusion
11 * capabilities.
12 *
13 * Directives provided are:
14 *
15 * - create a semaphore
16 * - get an ID of a semaphore
17 * - delete a semaphore
18 * - acquire a semaphore
19 * - release a semaphore
20 */
21
22/* COPYRIGHT (c) 1989-2008.
23 * On-Line Applications Research Corporation (OAR).
24 *
25 * The license and distribution terms for this file may be
26 * found in the file LICENSE in this distribution or at
27 * http://www.rtems.org/license/LICENSE.
28 */
29
30#ifndef _RTEMS_RTEMS_SEM_H
31#define _RTEMS_RTEMS_SEM_H
32
33#include <rtems/rtems/types.h>
34#include <rtems/rtems/options.h>
35#include <rtems/rtems/support.h>
36#include <rtems/rtems/tasks.h>
37#include <rtems/rtems/attr.h>
38#include <rtems/score/coremutex.h>
39#include <rtems/score/object.h>
40#include <rtems/score/coresem.h>
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46/**
47 *  @defgroup ClassicSem Semaphores
48 *
49 *  @ingroup ClassicRTEMS
50 *
51 *  This encapsulates functionality related to the Classic API
52 *  Semaphore Manager.
53 */
54/**@{*/
55
56/**
57 *  The following defines the control block used to manage each semaphore.
58 */
59typedef struct {
60  /** This field is the object management portion of a Semaphore instance. */
61  Objects_Control          Object;
62
63  /**
64   *  This is the Classic API attribute provided to the create directive.
65   *  It is translated into behavioral attributes on the SuperCore Semaphore
66   *  or Mutex instance.
67   */
68  rtems_attribute          attribute_set;
69
70  /**
71   *  This contains the memory associated with the SuperCore Semaphore or
72   *  Mutex instance that provides the primary functionality of each
73   *  Classic API Semaphore instance.  The structure used is dependent
74   *  on the attributes specified by the user on the create directive.
75   *
76   *  @note Only one of these has meaning in a particular Classic API
77   *        Semaphore instance.
78   */
79  union {
80    /**
81     *  This is the SuperCore Mutex instance associated with this Classic
82     *  API Semaphore instance.
83     */
84    CORE_mutex_Control     mutex;
85
86    /**
87     *  This is the SuperCore Semaphore instance associated with this Classic
88     *  API Semaphore instance.
89     */
90    CORE_semaphore_Control semaphore;
91  } Core_control;
92}   Semaphore_Control;
93
94/**
95 *  @brief rtems_semaphore_create
96 *
97 *  This routine implements the rtems_semaphore_create directive.  The
98 *  semaphore will have the name name.  The starting count for
99 *  the semaphore is count.  The attribute_set determines if
100 *  the semaphore is global or local and the thread queue
101 *  discipline.  It returns the id of the created semaphore in ID.
102 *
103 *  Semaphore Manager
104 */
105rtems_status_code rtems_semaphore_create(
106  rtems_name           name,
107  uint32_t             count,
108  rtems_attribute      attribute_set,
109  rtems_task_priority  priority_ceiling,
110  rtems_id            *id
111);
112
113/**
114 * @brief RTEMS Semaphore Name to Id
115 *
116 * This routine implements the rtems_semaphore_ident directive.
117 * This directive returns the semaphore ID associated with name.
118 * If more than one semaphore is named name, then the semaphore
119 * to which the ID belongs is arbitrary. node indicates the
120 * extent of the search for the ID of the semaphore named name.
121 * The search can be limited to a particular node or allowed to
122 * encompass all nodes.
123 *
124 * @param[in] name is the user defined semaphore name
125 * @param[in] node is(are) the node(s) to be searched
126 * @param[in] id is the pointer to semaphore id
127 *
128 * @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful and
129 * *id filled in with the semaphore id
130 */
131rtems_status_code rtems_semaphore_ident(
132  rtems_name    name,
133  uint32_t      node,
134  rtems_id     *id
135);
136
137/**
138 * @brief RTEMS Delete Semaphore
139 *
140 * This routine implements the rtems_semaphore_delete directive. The
141 * semaphore indicated by ID is deleted.
142 *
143 * @param[in] id is the semaphore id
144 *
145 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
146 *         error. Otherwise, a status code is returned indicating the
147 *         source of the error.
148 */
149rtems_status_code rtems_semaphore_delete(
150  rtems_id   id
151);
152
153/**
154 * @brief RTEMS Obtain Semaphore
155 *
156 * This routine implements the rtems_semaphore_obtain directive. It
157 * attempts to obtain a unit from the semaphore associated with ID.
158 * If a unit can be allocated, the calling task will return immediately.
159 * If no unit is available, then the task may return immediately or
160 * block waiting for a unit with an optional timeout of timeout
161 * clock ticks. Whether the task blocks or returns immediately
162 * is based on the RTEMS_NO_WAIT option in the option_set.
163 *
164 * @param[in] id is the semaphore id
165 * @param[in] option_set is the wait option
166 * @param[in] timeout is the number of ticks to wait (0 means wait forever)
167 *
168 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
169 *         error. Otherwise, a status code is returned indicating the
170 *         source of the error.
171 */
172rtems_status_code rtems_semaphore_obtain(
173  rtems_id       id,
174  rtems_option   option_set,
175  rtems_interval timeout
176);
177
178/**
179 *  @brief RTEMS Semaphore Release
180 *
181 *  Semaphore Manager
182 *
183 *  This routine implements the rtems_semaphore_release directive.  It
184 *  frees a unit to the semaphore associated with ID.  If a task was
185 *  blocked waiting for a unit from this semaphore, then that task will
186 *  be readied and the unit given to that task.  Otherwise, the unit
187 *  will be returned to the semaphore.
188 */
189rtems_status_code rtems_semaphore_release(
190  rtems_id   id
191);
192
193/**
194 * @brief RTEMS Semaphore Flush
195 *
196 * DESCRIPTION:
197 * This package is the implementation of the flush directive
198 * of the Semaphore Manager.
199 *
200 * This directive allows a thread to flush the threads
201 * pending on the semaphore.
202 *
203 * @param[in] id is the semaphore id
204 *
205 * @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful
206 */
207rtems_status_code rtems_semaphore_flush(
208  rtems_id         id
209);
210
211/**@}*/
212
213#ifdef __cplusplus
214}
215#endif
216
217#endif
218/*  end of include file */
Note: See TracBrowser for help on using the repository browser.