source: rtems/cpukit/score/include/rtems/score/coresemimpl.h @ cfa5aab

4.115
Last change on this file since cfa5aab was cfa5aab, checked in by Sebastian Huber <sebastian.huber@…>, on 05/02/15 at 12:02:20

score: Delete _CORE_semaphore_Seize()

Rename _CORE_semaphore_Seize_isr_disable() to _CORE_semaphore_Seize().

  • Property mode set to 100644
File size: 7.3 KB
Line 
1/**
2 * @file
3 *
4 * @brief Inlined Routines Associated with the SuperCore Semaphore
5 *
6 * This include file contains all of the inlined routines associated
7 * with the SuperCore semaphore.
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-2006.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#ifndef _RTEMS_SCORE_CORESEMIMPL_H
20#define _RTEMS_SCORE_CORESEMIMPL_H
21
22#include <rtems/score/coresem.h>
23#include <rtems/score/threaddispatch.h>
24#include <rtems/score/threadqimpl.h>
25#include <rtems/score/statesimpl.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/**
32 * @addtogroup ScoreSemaphore
33 */
34/**@{**/
35
36/**
37 *  Core Semaphore handler return statuses.
38 */
39typedef enum {
40  /** This status indicates that the operation completed successfully. */
41  CORE_SEMAPHORE_STATUS_SUCCESSFUL,
42  /** This status indicates that the calling task did not want to block
43   *  and the operation was unable to complete immediately because the
44   *  resource was unavailable.
45   */
46  CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT,
47  /** This status indicates that the thread was blocked waiting for an
48   *  operation to complete and the semaphore was deleted.
49   */
50  CORE_SEMAPHORE_WAS_DELETED,
51  /** This status indicates that the calling task was willing to block
52   *  but the operation was unable to complete within the time allotted
53   *  because the resource never became available.
54   */
55  CORE_SEMAPHORE_TIMEOUT,
56  /** This status indicates that an attempt was made to unlock the semaphore
57   *  and this would have made its count greater than that allowed.
58   */
59  CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED
60}   CORE_semaphore_Status;
61
62/**
63 *  @brief Core semaphore last status value.
64 *
65 *  This is the last status value.
66 */
67#define CORE_SEMAPHORE_STATUS_LAST CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED
68
69/**
70 *  The following type defines the callout which the API provides
71 *  to support global/multiprocessor operations on semaphores.
72 */
73typedef void ( *CORE_semaphore_API_mp_support_callout )(
74                 Thread_Control *,
75                 Objects_Id
76             );
77
78/**
79 *  @brief Initialize the semaphore based on the parameters passed.
80 *
81 *  This package is the implementation of the CORE Semaphore Handler.
82 *  This core object utilizes standard Dijkstra counting semaphores to provide
83 *  synchronization and mutual exclusion capabilities.
84 *
85 *  This routine initializes the semaphore based on the parameters passed.
86 *
87 *  @param[in] the_semaphore is the semaphore to initialize
88 *  @param[in] the_semaphore_attributes define the behavior of this instance
89 *  @param[in] initial_value is the initial count of the semaphore
90 */
91void _CORE_semaphore_Initialize(
92  CORE_semaphore_Control          *the_semaphore,
93  const CORE_semaphore_Attributes *the_semaphore_attributes,
94  uint32_t                         initial_value
95);
96
97RTEMS_INLINE_ROUTINE void _CORE_semaphore_Destroy(
98  CORE_semaphore_Control *the_semaphore
99)
100{
101  _Thread_queue_Destroy( &the_semaphore->Wait_queue );
102}
103
104/**
105 *  @brief Surrender a unit to a semaphore.
106 *
107 *  This routine frees a unit to the semaphore.  If a task was blocked waiting
108 *  for a unit from this semaphore, then that task will be readied and the unit
109 *  given to that task.  Otherwise, the unit will be returned to the semaphore.
110 *
111 *  @param[in] the_semaphore is the semaphore to surrender
112 *  @param[in] id is the Id of the API level Semaphore object associated
113 *         with this instance of a SuperCore Semaphore
114 *  @param[in] api_semaphore_mp_support is the routine to invoke if the
115 *         thread unblocked is remote
116 *  @param[in] lock_context is a temporary variable used to contain the ISR
117 *        disable level cookie
118 *
119 *  @retval an indication of whether the routine succeeded or failed
120 */
121CORE_semaphore_Status _CORE_semaphore_Surrender(
122  CORE_semaphore_Control                *the_semaphore,
123  Objects_Id                             id,
124  CORE_semaphore_API_mp_support_callout  api_semaphore_mp_support,
125  ISR_lock_Context                      *lock_context
126);
127
128/**
129 *  @brief Core semaphore flush.
130 *
131 *  This package is the implementation of the CORE Semaphore Handler.
132 *  This core object utilizes standard Dijkstra counting semaphores to provide
133 *  synchronization and mutual exclusion capabilities.
134 *
135 *  This routine assists in the deletion of a semaphore by flushing the
136 *  associated wait queue.
137 *
138 *  @param[in] the_semaphore is the semaphore to flush
139 *  @param[in] remote_extract_callout is the routine to invoke if the
140 *         thread unblocked is remote
141 *  @param[in] status is the status to be returned to the unblocked thread
142 */
143void _CORE_semaphore_Flush(
144  CORE_semaphore_Control         *the_semaphore,
145  Thread_queue_Flush_callout      remote_extract_callout,
146  uint32_t                        status
147);
148
149/**
150 * This function returns true if the priority attribute is
151 * enabled in the @a attribute_set and false otherwise.
152 *
153 * @param[in] the_attribute is the attribute set to test
154 *
155 * @return true if the priority attribute is enabled
156 */
157RTEMS_INLINE_ROUTINE bool _CORE_semaphore_Is_priority(
158  const CORE_semaphore_Attributes *the_attribute
159)
160{
161   return ( the_attribute->discipline == CORE_SEMAPHORE_DISCIPLINES_PRIORITY );
162}
163
164/**
165 * This routine returns the current count associated with the semaphore.
166 *
167 * @param[in] the_semaphore is the semaphore to obtain the count of
168 *
169 * @return the current count of this semaphore
170 */
171RTEMS_INLINE_ROUTINE uint32_t  _CORE_semaphore_Get_count(
172  CORE_semaphore_Control  *the_semaphore
173)
174{
175  return the_semaphore->count;
176}
177
178/**
179 * This routine attempts to receive a unit from the_semaphore.
180 * If a unit is available or if the wait flag is false, then the routine
181 * returns.  Otherwise, the calling task is blocked until a unit becomes
182 * available.
183 *
184 * @param[in] the_semaphore is the semaphore to obtain
185 * @param[in,out] executing The currently executing thread.
186 * @param[in] id is the Id of the owning API level Semaphore object
187 * @param[in] wait is true if the thread is willing to wait
188 * @param[in] timeout is the maximum number of ticks to block
189 * @param[in] lock_context is a temporary variable used to contain the ISR
190 *        disable level cookie
191 *
192 * @note There is currently no MACRO version of this routine.
193 */
194RTEMS_INLINE_ROUTINE void _CORE_semaphore_Seize(
195  CORE_semaphore_Control  *the_semaphore,
196  Thread_Control          *executing,
197  Objects_Id               id,
198  bool                     wait,
199  Watchdog_Interval        timeout,
200  ISR_lock_Context        *lock_context
201)
202{
203  /* disabled when you get here */
204
205  executing->Wait.return_code = CORE_SEMAPHORE_STATUS_SUCCESSFUL;
206  _Thread_queue_Acquire_critical( &the_semaphore->Wait_queue, lock_context );
207  if ( the_semaphore->count != 0 ) {
208    the_semaphore->count -= 1;
209    _Thread_queue_Release( &the_semaphore->Wait_queue, lock_context );
210    return;
211  }
212
213  if ( !wait ) {
214    _Thread_queue_Release( &the_semaphore->Wait_queue, lock_context );
215    executing->Wait.return_code = CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT;
216    return;
217  }
218
219  executing->Wait.id = id;
220  _Thread_queue_Enqueue_critical(
221    &the_semaphore->Wait_queue,
222    executing,
223    STATES_WAITING_FOR_SEMAPHORE,
224    timeout,
225    CORE_SEMAPHORE_TIMEOUT,
226    lock_context
227  );
228}
229
230/** @} */
231
232#ifdef __cplusplus
233}
234#endif
235
236#endif
237/* end of include file */
Note: See TracBrowser for help on using the repository browser.