source: rtems/cpukit/score/include/rtems/score/coresemimpl.h @ 07332ae

4.115
Last change on this file since 07332ae was 07332ae, checked in by Sebastian Huber <sebastian.huber@…>, on 08/22/13 at 13:20:06

score: _Thread_queue_Enqueue_with_handler()

Add thread parameter to _Thread_queue_Enqueue_with_handler() to avoid
access to global _Thread_Executing.

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