1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief CORE Mutex API |
---|
5 | * |
---|
6 | * This include file contains all the constants and structures associated with |
---|
7 | * the Mutex Handler. A mutex is an enhanced version of the standard Dijkstra |
---|
8 | * binary semaphore used to provide synchronization and mutual exclusion |
---|
9 | * capabilities. |
---|
10 | */ |
---|
11 | |
---|
12 | /* |
---|
13 | * COPYRIGHT (c) 1989-2011. |
---|
14 | * On-Line Applications Research Corporation (OAR). |
---|
15 | * |
---|
16 | * The license and distribution terms for this file may be |
---|
17 | * found in the file LICENSE in this distribution or at |
---|
18 | * http://www.rtems.org/license/LICENSE. |
---|
19 | */ |
---|
20 | |
---|
21 | #ifndef _RTEMS_SCORE_COREMUTEX_H |
---|
22 | #define _RTEMS_SCORE_COREMUTEX_H |
---|
23 | |
---|
24 | #include <rtems/score/thread.h> |
---|
25 | #include <rtems/score/threadq.h> |
---|
26 | #include <rtems/score/priority.h> |
---|
27 | #include <rtems/score/watchdog.h> |
---|
28 | #include <rtems/score/interr.h> |
---|
29 | |
---|
30 | #ifdef __cplusplus |
---|
31 | extern "C" { |
---|
32 | #endif |
---|
33 | |
---|
34 | /** |
---|
35 | * @defgroup ScoreMutex Mutex Handler |
---|
36 | * |
---|
37 | * @ingroup Score |
---|
38 | * |
---|
39 | * This handler encapsulates functionality which provides the foundation |
---|
40 | * Mutex services used in all of the APIs supported by RTEMS. |
---|
41 | */ |
---|
42 | /**@{*/ |
---|
43 | |
---|
44 | /** |
---|
45 | * @brief The blocking disciplines for a mutex. |
---|
46 | * |
---|
47 | * This enumerated type defines the blocking disciplines for a mutex. |
---|
48 | */ |
---|
49 | typedef enum { |
---|
50 | /** This specifies that threads will wait for the mutex in FIFO order. */ |
---|
51 | CORE_MUTEX_DISCIPLINES_FIFO, |
---|
52 | /** This specifies that threads will wait for the mutex in priority order. */ |
---|
53 | CORE_MUTEX_DISCIPLINES_PRIORITY, |
---|
54 | /** This specifies that threads will wait for the mutex in priority order. |
---|
55 | * Additionally, the Priority Inheritance Protocol will be in effect. |
---|
56 | */ |
---|
57 | CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT, |
---|
58 | /** This specifies that threads will wait for the mutex in priority order. |
---|
59 | * Additionally, the Priority Ceiling Protocol will be in effect. |
---|
60 | */ |
---|
61 | CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING |
---|
62 | } CORE_mutex_Disciplines; |
---|
63 | |
---|
64 | /** |
---|
65 | * @brief The possible behaviors for lock nesting. |
---|
66 | * |
---|
67 | * This enumerated type defines the possible behaviors for |
---|
68 | * lock nesting. |
---|
69 | */ |
---|
70 | typedef enum { |
---|
71 | /** |
---|
72 | * This sequence has no blocking or errors: |
---|
73 | * |
---|
74 | * + lock(m) |
---|
75 | * + lock(m) |
---|
76 | * + unlock(m) |
---|
77 | * + unlock(m) |
---|
78 | */ |
---|
79 | CORE_MUTEX_NESTING_ACQUIRES, |
---|
80 | #if defined(RTEMS_POSIX_API) |
---|
81 | /** |
---|
82 | * This sequence returns an error at the indicated point: |
---|
83 | * |
---|
84 | * + lock(m) |
---|
85 | * + lock(m) - already locked error |
---|
86 | * + unlock(m) |
---|
87 | */ |
---|
88 | CORE_MUTEX_NESTING_IS_ERROR, |
---|
89 | #endif |
---|
90 | /** |
---|
91 | * This sequence performs as indicated: |
---|
92 | * + lock(m) |
---|
93 | * + lock(m) - deadlocks or timeouts |
---|
94 | * + unlock(m) - releases |
---|
95 | */ |
---|
96 | CORE_MUTEX_NESTING_BLOCKS |
---|
97 | } CORE_mutex_Nesting_behaviors; |
---|
98 | |
---|
99 | /** |
---|
100 | * @brief The control block used to manage attributes of each mutex. |
---|
101 | * |
---|
102 | * The following defines the control block used to manage the |
---|
103 | * attributes of each mutex. |
---|
104 | */ |
---|
105 | typedef struct { |
---|
106 | /** This field determines what the behavior of this mutex instance will |
---|
107 | * be when attempting to acquire the mutex when it is already locked. |
---|
108 | */ |
---|
109 | CORE_mutex_Nesting_behaviors lock_nesting_behavior; |
---|
110 | /** When this field is true, then only the thread that locked the mutex |
---|
111 | * is allowed to unlock it. |
---|
112 | */ |
---|
113 | bool only_owner_release; |
---|
114 | /** This field indicates whether threads waiting on the mutex block in |
---|
115 | * FIFO or priority order. |
---|
116 | */ |
---|
117 | CORE_mutex_Disciplines discipline; |
---|
118 | /** This field contains the ceiling priority to be used if that protocol |
---|
119 | * is selected. |
---|
120 | */ |
---|
121 | Priority_Control priority_ceiling; |
---|
122 | } CORE_mutex_Attributes; |
---|
123 | |
---|
124 | /** |
---|
125 | * @brief Control block used to manage each mutex. |
---|
126 | * |
---|
127 | * The following defines the control block used to manage each mutex. |
---|
128 | */ |
---|
129 | typedef struct { |
---|
130 | /** This field is the Waiting Queue used to manage the set of tasks |
---|
131 | * which are blocked waiting to lock the mutex. |
---|
132 | */ |
---|
133 | Thread_queue_Control Wait_queue; |
---|
134 | |
---|
135 | /** |
---|
136 | * @brief The thread queue operations according to the blocking discipline. |
---|
137 | */ |
---|
138 | const Thread_queue_Operations *operations; |
---|
139 | |
---|
140 | /** This element is the set of attributes which define this instance's |
---|
141 | * behavior. |
---|
142 | */ |
---|
143 | CORE_mutex_Attributes Attributes; |
---|
144 | /** This element contains the number of times the mutex has been acquired |
---|
145 | * nested. This must be zero (0) before the mutex is actually unlocked. |
---|
146 | */ |
---|
147 | uint32_t nest_count; |
---|
148 | /** This element points to the thread which is currently holding this mutex. |
---|
149 | * The holder is the last thread to successfully lock the mutex and which |
---|
150 | * has not unlocked it. If the thread is not locked, there is no holder. |
---|
151 | */ |
---|
152 | Thread_Control *holder; |
---|
153 | } CORE_mutex_Control; |
---|
154 | |
---|
155 | /**@}*/ |
---|
156 | |
---|
157 | #ifdef __cplusplus |
---|
158 | } |
---|
159 | #endif |
---|
160 | |
---|
161 | #endif |
---|
162 | /* end of include file */ |
---|