source: rtems/c/src/exec/score/headers/coremutex.h @ 37f4c2d

4.104.114.84.95
Last change on this file since 37f4c2d was 5e9b32b, checked in by Joel Sherrill <joel.sherrill@…>, on 09/26/95 at 19:27:15

posix support initially added

  • Property mode set to 100644
File size: 5.5 KB
Line 
1/*  mutex.h
2 *
3 *  This include file contains all the constants and structures associated
4 *  with the Mutex Handler.  A mutex is an enhanced version of the standard
5 *  Dijkstra binary semaphore used to provide synchronization and mutual
6 *  exclusion capabilities.
7 *
8 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
9 *  On-Line Applications Research Corporation (OAR).
10 *  All rights assigned to U.S. Government, 1994.
11 *
12 *  This material may be reproduced by or for the U.S. Government pursuant
13 *  to the copyright license under the clause at DFARS 252.227-7013.  This
14 *  notice must appear in all copies of this file and its derivatives.
15 *
16 *  $Id$
17 */
18 
19#ifndef __RTEMS_CORE_MUTEX_h
20#define __RTEMS_CORE_MUTEX_h
21 
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#include <rtems/score/thread.h>
27#include <rtems/score/threadq.h>
28#include <rtems/score/priority.h>
29#include <rtems/score/watchdog.h>
30 
31/*
32 *  The following type defines the callout which the API provides
33 *  to support global/multiprocessor operations on mutexes.
34 */
35 
36typedef void ( *CORE_mutex_API_mp_support_callout )(
37                 Thread_Control *,
38                 Objects_Id
39             );
40
41/*
42 *  Blocking disciplines for a mutex.
43 */
44
45typedef enum {
46  CORE_MUTEX_DISCIPLINES_FIFO,
47  CORE_MUTEX_DISCIPLINES_PRIORITY,
48  CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT,
49  CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING
50}   CORE_mutex_Disciplines;
51
52/*
53 *  Mutex handler return statuses.
54 */
55 
56typedef enum {
57  CORE_MUTEX_STATUS_SUCCESSFUL,
58  CORE_MUTEX_STATUS_UNSATISFIED_NOWAIT,
59  CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED,
60  CORE_MUTEX_STATUS_NOT_OWNER_OF_RESOURCE,
61  CORE_MUTEX_WAS_DELETED,
62  CORE_MUTEX_TIMEOUT
63}   CORE_mutex_Status;
64
65/*
66 *  Locked and unlocked values
67 */
68
69#define CORE_MUTEX_UNLOCKED 1
70#define CORE_MUTEX_LOCKED   0
71
72/*
73 *  The following defines the control block used to manage the
74 *  attributes of each mutex.
75 */
76
77typedef struct {
78  boolean                 allow_nesting;
79  CORE_mutex_Disciplines  discipline;
80  Priority_Control        priority_ceiling;
81}   CORE_mutex_Attributes;
82 
83/*
84 *  The following defines the control block used to manage each mutex.
85 */
86 
87typedef struct {
88  Thread_queue_Control    Wait_queue;
89  CORE_mutex_Attributes   Attributes;
90  unsigned32              lock;
91  unsigned32              nest_count;
92  Thread_Control         *holder;
93  Objects_Id              holder_id;
94}   CORE_mutex_Control;
95
96/*
97 *  _CORE_mutex_Initialize
98 *
99 *  DESCRIPTION:
100 *
101 *  This routine initializes the mutex based on the parameters passed.
102 */
103
104void _CORE_mutex_Initialize(
105  CORE_mutex_Control           *the_mutex,
106  Objects_Classes               the_class,
107  CORE_mutex_Attributes        *the_mutex_attributes,
108  unsigned32                    initial_lock,
109  Thread_queue_Extract_callout  proxy_extract_callout
110);
111 
112/*
113 *  _CORE_mutex_Seize
114 *
115 *  DESCRIPTION:
116 *
117 *  This routine attempts to receive a unit from the_mutex.
118 *  If a unit is available or if the wait flag is FALSE, then the routine
119 *  returns.  Otherwise, the calling task is blocked until a unit becomes
120 *  available.
121 */
122
123void _CORE_mutex_Seize(
124  CORE_mutex_Control  *the_mutex,
125  Objects_Id           id,
126  boolean              wait,
127  Watchdog_Interval    timeout
128);
129 
130/*
131 *  _CORE_mutex_Surrender
132 *
133 *  DESCRIPTION:
134 *
135 *  This routine frees a unit to the mutex.  If a task was blocked waiting for
136 *  a unit from this mutex, then that task will be readied and the unit
137 *  given to that task.  Otherwise, the unit will be returned to the mutex.
138 */
139
140CORE_mutex_Status _CORE_mutex_Surrender(
141  CORE_mutex_Control                *the_mutex,
142  Objects_Id                         id,
143  CORE_mutex_API_mp_support_callout  api_mutex_mp_support
144);
145 
146/*
147 *  _CORE_mutex_Flush
148 *
149 *  DESCRIPTION:
150 *
151 *  This routine assists in the deletion of a mutex by flushing the associated
152 *  wait queue.
153 */
154 
155void _CORE_mutex_Flush(
156  CORE_mutex_Control         *the_mutex,
157  Thread_queue_Flush_callout  remote_extract_callout,
158  unsigned32                  status
159);
160 
161/*
162 *  _CORE_mutex_Is_locked
163 *
164 *  DESCRIPTION:
165 *
166 *  This routine returns TRUE if the mutex specified is locked and FALSE
167 *  otherwise.
168 */
169 
170STATIC INLINE boolean _CORE_mutex_Is_locked(
171  CORE_mutex_Control  *the_mutex
172);
173
174/*
175 *  _CORE_mutex_Is_fifo
176 *
177 *  DESCRIPTION:
178 *
179 *  This routine returns TRUE if the mutex's wait discipline is FIFO and FALSE
180 *  otherwise.
181 */
182 
183STATIC INLINE boolean _CORE_mutex_Is_fifo(
184  CORE_mutex_Attributes *the_attribute
185);
186
187/*
188 *  _CORE_mutex_Is_priority
189 *
190 *  DESCRIPTION:
191 *
192 *  This routine returns TRUE if the mutex's wait discipline is PRIORITY and
193 *  FALSE otherwise.
194 */
195
196STATIC INLINE boolean _CORE_mutex_Is_priority(
197  CORE_mutex_Attributes *the_attribute
198);
199
200/*
201 *  _CORE_mutex_Is_inherit_priority
202 *
203 *  DESCRIPTION:
204 *
205 *  This routine returns TRUE if the mutex's wait discipline is
206 *  INHERIT_PRIORITY and FALSE otherwise.
207 */
208
209STATIC INLINE boolean _CORE_mutex_Is_inherit_priority(
210  CORE_mutex_Attributes *the_attribute
211);
212
213/*
214 *  _CORE_mutex_Is_priority_ceiling
215 *
216 *  DESCRIPTION:
217 *
218 *  This routine returns TRUE if the mutex's wait discipline is
219 *  PRIORITY_CEILING and FALSE otherwise.
220 */
221
222STATIC INLINE boolean _CORE_mutex_Is_priority_ceiling(
223  CORE_mutex_Attributes *the_attribute
224);
225
226/*
227 *  _CORE_mutex_Is_nesting_allowed
228 *
229 *  DESCRIPTION:
230 *
231 *  This routine returns TRUE if the mutex allows a task to obtain a
232 *  semaphore more than once and nest.
233 */
234 
235STATIC INLINE boolean _CORE_mutex_Is_nesting_allowed(
236  CORE_mutex_Attributes *the_attribute
237);
238
239#include <rtems/score/coremutex.inl>
240
241#ifdef __cplusplus
242}
243#endif
244 
245#endif
246/*  end of include file */
247
Note: See TracBrowser for help on using the repository browser.