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

4.115
Last change on this file since f5d6c8b was f5d6c8b, checked in by Sebastian Huber <sebastian.huber@…>, on 04/27/15 at 14:25:52

score: Delete Thread_queue_Control::timeout_status

Use a parameter for _Thread_queue_Enqueue() instead to reduce memory
usage.

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