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 |
---|
23 | extern "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 | |
---|
36 | typedef void ( *CORE_mutex_API_mp_support_callout )( |
---|
37 | Thread_Control *, |
---|
38 | Objects_Id |
---|
39 | ); |
---|
40 | |
---|
41 | /* |
---|
42 | * Blocking disciplines for a mutex. |
---|
43 | */ |
---|
44 | |
---|
45 | typedef 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 | |
---|
56 | typedef 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 | |
---|
77 | typedef 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 | |
---|
87 | typedef 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 | |
---|
104 | void _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 | |
---|
123 | void _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 | |
---|
140 | CORE_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 | |
---|
155 | void _CORE_mutex_Flush( |
---|
156 | CORE_mutex_Control *the_mutex, |
---|
157 | Thread_queue_Flush_callout remote_extract_callout, |
---|
158 | unsigned32 status |
---|
159 | ); |
---|
160 | |
---|
161 | #ifndef __RTEMS_APPLICATION__ |
---|
162 | #include <rtems/score/coremutex.inl> |
---|
163 | #endif |
---|
164 | |
---|
165 | #ifdef __cplusplus |
---|
166 | } |
---|
167 | #endif |
---|
168 | |
---|
169 | #endif |
---|
170 | /* end of include file */ |
---|
171 | |
---|