source: rtems/cpukit/score/include/rtems/score/coresem.h @ 8907a01c

4.104.115
Last change on this file since 8907a01c was 8907a01c, checked in by Joel Sherrill <joel.sherrill@…>, on 09/13/09 at 20:54:01

2009-09-13 Joel Sherrill <joel.sherrill@…>

  • score/include/rtems/score/coresem.h, score/src/coresemseize.c: Disable body of _CORE_semaphore_Seize() if it is not used because all APIs using it are disabled.
  • Property mode set to 100644
File size: 6.6 KB
Line 
1/**
2 *  @file  rtems/score/coresem.h
3 *
4 *  This include file contains all the constants and structures associated
5 *  with the Counting Semaphore Handler.  A counting semaphore is the
6 *  standard Dijkstra binary semaphore used to provide synchronization
7 *  and mutual exclusion capabilities.
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-2008.
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 *  $Id$
19 */
20
21#ifndef _RTEMS_SCORE_CORESEM_H
22#define _RTEMS_SCORE_CORESEM_H
23
24/**
25 *  @defgroup ScoreSemaphore Semaphore Handler
26 *
27 *  This handler encapsulates functionality which provides the foundation
28 *  Semaphore services used in all of the APIs supported by RTEMS.
29 */
30/**@{*/
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36#include <rtems/score/thread.h>
37#include <rtems/score/threadq.h>
38#include <rtems/score/priority.h>
39#include <rtems/score/watchdog.h>
40
41#if defined(RTEMS_POSIX_API) || defined(RTEMS_ITRON_API)
42  #define RTEMS_SCORE_CORESEM_ENABLE_SEIZE_BODY
43#endif
44
45/**
46 *  The following type defines the callout which the API provides
47 *  to support global/multiprocessor operations on semaphores.
48 */
49typedef void ( *CORE_semaphore_API_mp_support_callout )(
50                 Thread_Control *,
51                 Objects_Id
52             );
53
54/**
55 *  Blocking disciplines for a semaphore.
56 */
57typedef enum {
58  /** This specifies that threads will wait for the semaphore in FIFO order. */
59  CORE_SEMAPHORE_DISCIPLINES_FIFO,
60  /** This specifies that threads will wait for the semaphore in
61   *  priority order.
62   */
63  CORE_SEMAPHORE_DISCIPLINES_PRIORITY
64}   CORE_semaphore_Disciplines;
65
66/**
67 *  Core Semaphore handler return statuses.
68 */
69typedef enum {
70  /** This status indicates that the operation completed successfully. */
71  CORE_SEMAPHORE_STATUS_SUCCESSFUL,
72  /** This status indicates that the calling task did not want to block
73   *  and the operation was unable to complete immediately because the
74   *  resource was unavailable.
75   */
76  CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT,
77  /** This status indicates that the thread was blocked waiting for an
78   *  operation to complete and the semaphore was deleted.
79   */
80  CORE_SEMAPHORE_WAS_DELETED,
81  /** This status indicates that the calling task was willing to block
82   *  but the operation was unable to complete within the time allotted
83   *  because the resource never became available.
84   */
85  CORE_SEMAPHORE_TIMEOUT,
86  /** This status indicates that an attempt was made to unlock the semaphore
87   *  and this would have made its count greater than that allowed.
88   */
89  CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED
90}   CORE_semaphore_Status;
91
92/**
93 *  @brief Core Semaphore Last Status
94 *
95 *  This is the last status value.
96 */
97#define CORE_SEMAPHORE_STATUS_LAST CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED
98
99/**
100 *  The following defines the control block used to manage the
101 *  attributes of each semaphore.
102 */
103typedef struct {
104  /** This element indicates the maximum count this semaphore may have. */
105  uint32_t                    maximum_count;
106  /** This field indicates whether threads waiting on the semaphore block in
107   *  FIFO or priority order.
108   */
109  CORE_semaphore_Disciplines  discipline;
110}   CORE_semaphore_Attributes;
111
112/**
113 *  The following defines the control block used to manage each
114 *  counting semaphore.
115 */
116typedef struct {
117  /** This field is the Waiting Queue used to manage the set of tasks
118   *  which are blocked waiting to obtain the semaphore.
119   */
120  Thread_queue_Control        Wait_queue;
121  /** This element is the set of attributes which define this instance's
122   *  behavior.
123   */
124  CORE_semaphore_Attributes   Attributes;
125  /** This element contains the current count of this semaphore. */
126  uint32_t                    count;
127}   CORE_semaphore_Control;
128
129/**
130 *  This routine initializes the semaphore based on the parameters passed.
131 *
132 *  @param[in] the_semaphore is the semaphore to initialize
133 *  @param[in] the_semaphore_attributes define the behavior of this instance
134 *  @param[in] initial_value is the initial count of the semaphore
135 */
136void _CORE_semaphore_Initialize(
137  CORE_semaphore_Control       *the_semaphore,
138  CORE_semaphore_Attributes    *the_semaphore_attributes,
139  uint32_t                      initial_value
140);
141
142#if defined(RTEMS_SCORE_CORESEM_ENABLE_SEIZE_BODY)
143  /**
144   *  This routine attempts to receive a unit from @a the_semaphore.
145   *  If a unit is available or if the wait flag is false, then the routine
146   *  returns.  Otherwise, the calling task is blocked until a unit becomes
147   *  available.
148   *
149   *  @param[in] the_semaphore is the semaphore to seize
150   *  @param[in] id is the Id of the API level Semaphore object associated
151   *         with this instance of a SuperCore Semaphore
152   *  @param[in] wait indicates if the caller is willing to block
153   *  @param[in] timeout is the number of ticks the calling thread is willing
154   *         to wait if @a wait is true.
155   */
156  void _CORE_semaphore_Seize(
157    CORE_semaphore_Control  *the_semaphore,
158    Objects_Id               id,
159    bool                     wait,
160    Watchdog_Interval        timeout
161  );
162#endif
163
164/**
165 *  This routine frees a unit to the semaphore.  If a task was blocked waiting
166 *  for a unit from this semaphore, then that task will be readied and the unit
167 *  given to that task.  Otherwise, the unit will be returned to the semaphore.
168 *
169 *  @param[in] the_semaphore is the semaphore to surrender
170 *  @param[in] id is the Id of the API level Semaphore object associated
171 *         with this instance of a SuperCore Semaphore
172 *  @param[in] api_semaphore_mp_support is the routine to invoke if the
173 *         thread unblocked is remote
174 *
175 *  @return an indication of whether the routine succeeded or failed
176 */
177CORE_semaphore_Status _CORE_semaphore_Surrender(
178  CORE_semaphore_Control                *the_semaphore,
179  Objects_Id                             id,
180  CORE_semaphore_API_mp_support_callout  api_semaphore_mp_support
181);
182
183/**
184 *  This routine assists in the deletion of a semaphore by flushing the
185 *  associated wait queue.
186 *
187 *  @param[in] the_semaphore is the semaphore to flush
188 *  @param[in] remote_extract_callout is the routine to invoke if the
189 *         thread unblocked is remote
190 *  @param[in] status is the status to be returned to the unblocked thread
191 */
192void _CORE_semaphore_Flush(
193  CORE_semaphore_Control         *the_semaphore,
194  Thread_queue_Flush_callout      remote_extract_callout,
195  uint32_t                        status
196);
197
198#ifndef __RTEMS_APPLICATION__
199#include <rtems/score/coresem.inl>
200#endif
201
202#ifdef __cplusplus
203}
204#endif
205
206/**@}*/
207
208#endif
209/*  end of include file */
Note: See TracBrowser for help on using the repository browser.