source: rtems/cpukit/rtems/include/rtems/rtems/sem.h @ 3ca6e618

5
Last change on this file since 3ca6e618 was 3ca6e618, checked in by Sebastian Huber <sebastian.huber@…>, on 05/25/16 at 14:49:53

rtems: Simplify rtems_semaphore_delete()

  • Property mode set to 100644
File size: 8.0 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 * - flush a semaphore
21 * - set ceiling priority for a semaphore
22 */
23
24/*
25 * COPYRIGHT (c) 1989-2008, 2016.
26 * On-Line Applications Research Corporation (OAR).
27 *
28 * The license and distribution terms for this file may be
29 * found in the file LICENSE in this distribution or at
30 * http://www.rtems.org/license/LICENSE.
31 */
32
33#ifndef _RTEMS_RTEMS_SEM_H
34#define _RTEMS_RTEMS_SEM_H
35
36#include <rtems/rtems/types.h>
37#include <rtems/rtems/options.h>
38#include <rtems/rtems/support.h>
39#include <rtems/rtems/tasks.h>
40#include <rtems/rtems/attr.h>
41#include <rtems/score/coremutex.h>
42#include <rtems/score/object.h>
43#include <rtems/score/coresem.h>
44#include <rtems/score/mrsp.h>
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
50/**
51 *  @defgroup ClassicSem Semaphores
52 *
53 *  @ingroup ClassicRTEMS
54 *
55 *  This encapsulates functionality related to the Classic API
56 *  Semaphore Manager.
57 */
58/**@{*/
59
60/**
61 *  The following defines the control block used to manage each semaphore.
62 */
63typedef struct {
64  /** This field is the object management portion of a Semaphore instance. */
65  Objects_Control          Object;
66
67  /**
68   *  This contains the memory associated with the SuperCore Semaphore or
69   *  Mutex instance that provides the primary functionality of each
70   *  Classic API Semaphore instance.  The structure used is dependent
71   *  on the attributes specified by the user on the create directive.
72   *
73   *  @note Only one of these has meaning in a particular Classic API
74   *        Semaphore instance.
75   */
76  union {
77    /**
78     * @brief The thread queue present in all other variants.
79     */
80    Thread_queue_Control Wait_queue;
81
82    /**
83     *  This is the SuperCore Mutex instance associated with this Classic
84     *  API Semaphore instance.
85     */
86    CORE_mutex_Control     mutex;
87
88    /**
89     *  This is the SuperCore Semaphore instance associated with this Classic
90     *  API Semaphore instance.
91     */
92    CORE_semaphore_Control semaphore;
93
94#if defined(RTEMS_SMP)
95    MRSP_Control mrsp;
96#endif
97  } Core_control;
98
99  /**
100   *  This is the Classic API attribute provided to the create directive.
101   *  It is translated into behavioral attributes on the SuperCore Semaphore
102   *  or Mutex instance.
103   */
104  rtems_attribute          attribute_set;
105}   Semaphore_Control;
106
107/**
108 *  @brief rtems_semaphore_create
109 *
110 *  This routine implements the rtems_semaphore_create directive.  The
111 *  semaphore will have the name name.  The starting count for
112 *  the semaphore is count.  The attribute_set determines if
113 *  the semaphore is global or local and the thread queue
114 *  discipline.  It returns the id of the created semaphore in ID.
115 */
116rtems_status_code rtems_semaphore_create(
117  rtems_name           name,
118  uint32_t             count,
119  rtems_attribute      attribute_set,
120  rtems_task_priority  priority_ceiling,
121  rtems_id            *id
122);
123
124/**
125 * @brief RTEMS Semaphore Name to Id
126 *
127 * This routine implements the rtems_semaphore_ident directive.
128 * This directive returns the semaphore ID associated with name.
129 * If more than one semaphore is named name, then the semaphore
130 * to which the ID belongs is arbitrary. node indicates the
131 * extent of the search for the ID of the semaphore named name.
132 * The search can be limited to a particular node or allowed to
133 * encompass all nodes.
134 *
135 * @param[in] name is the user defined semaphore name
136 * @param[in] node is(are) the node(s) to be searched
137 * @param[in] id is the pointer to semaphore id
138 *
139 * @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful and
140 * *id filled in with the semaphore id
141 */
142rtems_status_code rtems_semaphore_ident(
143  rtems_name    name,
144  uint32_t      node,
145  rtems_id     *id
146);
147
148/**
149 * @brief RTEMS Delete Semaphore
150 *
151 * This routine implements the rtems_semaphore_delete directive. The
152 * semaphore indicated by ID is deleted.
153 *
154 * @param[in] id is the semaphore id
155 *
156 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
157 *         error. Otherwise, a status code is returned indicating the
158 *         source of the error.
159 */
160rtems_status_code rtems_semaphore_delete(
161  rtems_id   id
162);
163
164/**
165 * @brief RTEMS Obtain Semaphore
166 *
167 * This routine implements the rtems_semaphore_obtain directive. It
168 * attempts to obtain a unit from the semaphore associated with ID.
169 * If a unit can be allocated, the calling task will return immediately.
170 * If no unit is available, then the task may return immediately or
171 * block waiting for a unit with an optional timeout of timeout
172 * clock ticks. Whether the task blocks or returns immediately
173 * is based on the RTEMS_NO_WAIT option in the option_set.
174 *
175 * @param[in] id is the semaphore id
176 * @param[in] option_set is the wait option
177 * @param[in] timeout is the number of ticks to wait (0 means wait forever)
178 *
179 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
180 *         error. Otherwise, a status code is returned indicating the
181 *         source of the error.
182 */
183rtems_status_code rtems_semaphore_obtain(
184  rtems_id       id,
185  rtems_option   option_set,
186  rtems_interval timeout
187);
188
189/**
190 *  @brief RTEMS Semaphore Release
191 *
192 *  This routine implements the rtems_semaphore_release directive.  It
193 *  frees a unit to the semaphore associated with ID.  If a task was
194 *  blocked waiting for a unit from this semaphore, then that task will
195 *  be readied and the unit given to that task.  Otherwise, the unit
196 *  will be returned to the semaphore.
197 */
198rtems_status_code rtems_semaphore_release(
199  rtems_id   id
200);
201
202/**
203 * @brief RTEMS Semaphore Flush
204 *
205 * This method is the implementation of the flush directive
206 * of the Semaphore Manager.
207 *
208 * This directive allows a thread to flush the threads
209 * pending on the semaphore.
210 *
211 * @param[in] id is the semaphore id
212 *
213 * @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful
214 */
215rtems_status_code rtems_semaphore_flush(
216  rtems_id         id
217);
218
219/**
220 * @brief Sets the priority value with respect to the specified scheduler of a
221 * semaphore.
222 *
223 * The special priority value @ref RTEMS_CURRENT_PRIORITY can be used to get
224 * the current priority value without changing it.
225 *
226 * The interpretation of the priority value depends on the protocol of the
227 * semaphore object.
228 *
229 * - The Multiprocessor Resource Sharing Protocol needs a ceiling priority per
230 *   scheduler instance.  This operation can be used to specify these priority
231 *   values.
232 * - For the Priority Ceiling Protocol the ceiling priority is used with this
233 *   operation.
234 * - For other protocols this operation is not defined.
235 *
236 * @param[in] semaphore_id Identifier of the semaphore.
237 * @param[in] scheduler_id Identifier of the scheduler.
238 * @param[in] new_priority The new priority value.  Use
239 * @ref RTEMS_CURRENT_PRIORITY to not set a new priority and only get the
240 * current priority.
241 * @param[out] old_priority Reference to store the old priority value.
242 *
243 * @retval RTEMS_SUCCESSFUL Successful operation.
244 * @retval RTEMS_INVALID_ID Invalid semaphore or scheduler identifier.
245 * @retval RTEMS_INVALID_ADDRESS The old priority reference is @c NULL.
246 * @retval RTEMS_INVALID_PRIORITY The new priority value is invalid.
247 * @retval RTEMS_NOT_DEFINED The set priority operation is not defined for the
248 * protocol of this semaphore object.
249 * @retval RTEMS_ILLEGAL_ON_REMOTE_OBJECT Not supported for remote semaphores.
250 *
251 * @see rtems_scheduler_ident() and rtems_task_set_priority().
252 */
253rtems_status_code rtems_semaphore_set_priority(
254  rtems_id             semaphore_id,
255  rtems_id             scheduler_id,
256  rtems_task_priority  new_priority,
257  rtems_task_priority *old_priority
258);
259
260/**@}*/
261
262#ifdef __cplusplus
263}
264#endif
265
266#endif
267/*  end of include file */
Note: See TracBrowser for help on using the repository browser.