1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup ScoreAPIMutex |
---|
5 | * |
---|
6 | * @brief API Mutex Handler API |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * COPYRIGHT (c) 1989-2008. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.rtems.org/license/LICENSE. |
---|
16 | */ |
---|
17 | |
---|
18 | #ifndef _RTEMS_SCORE_APIMUTEX_H |
---|
19 | #define _RTEMS_SCORE_APIMUTEX_H |
---|
20 | |
---|
21 | #include <rtems/score/coremutex.h> |
---|
22 | #include <rtems/score/object.h> |
---|
23 | |
---|
24 | /** |
---|
25 | * @defgroup ScoreAPIMutex API Mutex Handler |
---|
26 | * |
---|
27 | * @ingroup Score |
---|
28 | * |
---|
29 | * @brief Provides routines to ensure mutual exclusion on API level. |
---|
30 | */ |
---|
31 | /**@{**/ |
---|
32 | |
---|
33 | #ifdef __cplusplus |
---|
34 | extern "C" { |
---|
35 | #endif |
---|
36 | |
---|
37 | /** |
---|
38 | * @brief Control block used to manage each API mutex. |
---|
39 | */ |
---|
40 | typedef struct { |
---|
41 | /** |
---|
42 | * @brief Allows each API Mutex to be a full-fledged RTEMS object. |
---|
43 | */ |
---|
44 | Objects_Control Object; |
---|
45 | |
---|
46 | /** |
---|
47 | * Contains the SuperCore mutex information. |
---|
48 | */ |
---|
49 | CORE_recursive_mutex_Control Mutex; |
---|
50 | |
---|
51 | /** |
---|
52 | * @brief The thread life protection state before the outer-most mutex |
---|
53 | * obtain. |
---|
54 | */ |
---|
55 | Thread_Life_state previous_thread_life_state; |
---|
56 | } API_Mutex_Control; |
---|
57 | |
---|
58 | /** |
---|
59 | * @brief Initialization for the API Mutexe Handler. |
---|
60 | * |
---|
61 | * The value @a maximum_mutexes is the maximum number of API mutexes that may |
---|
62 | * exist at any time. |
---|
63 | * |
---|
64 | * @param[in] maximum_mutexes is the maximum number of API mutexes. |
---|
65 | */ |
---|
66 | void _API_Mutex_Initialization( uint32_t maximum_mutexes ); |
---|
67 | |
---|
68 | /** |
---|
69 | * @brief Allocates an API mutex from the inactive set and returns it in |
---|
70 | * @a mutex. |
---|
71 | */ |
---|
72 | void _API_Mutex_Allocate( API_Mutex_Control **mutex ); |
---|
73 | |
---|
74 | /** |
---|
75 | * @brief Acquires the specified API mutex. |
---|
76 | * |
---|
77 | * @param[in] mutex The API mutex. |
---|
78 | */ |
---|
79 | void _API_Mutex_Lock( API_Mutex_Control *mutex ); |
---|
80 | |
---|
81 | /** |
---|
82 | * @brief Releases the specified API mutex. |
---|
83 | * |
---|
84 | * @param[in] mutex The API mutex. |
---|
85 | */ |
---|
86 | void _API_Mutex_Unlock( API_Mutex_Control *mutex ); |
---|
87 | |
---|
88 | /** |
---|
89 | * @brief Checks if the specified API mutex is owned by the executing thread. |
---|
90 | * |
---|
91 | * @param[in] mutex The API mutex. |
---|
92 | */ |
---|
93 | bool _API_Mutex_Is_owner( const API_Mutex_Control *mutex ); |
---|
94 | |
---|
95 | /** @} */ |
---|
96 | |
---|
97 | /** |
---|
98 | * @defgroup ScoreAllocatorMutex RTEMS Allocator Mutex |
---|
99 | * |
---|
100 | * @ingroup ScoreAPIMutex |
---|
101 | * |
---|
102 | * @brief Protection for all memory allocations and deallocations in RTEMS. |
---|
103 | * |
---|
104 | * When the APIs all use this for allocation and deallocation protection, then |
---|
105 | * this possibly should be renamed and moved to a higher level in the |
---|
106 | * hierarchy. |
---|
107 | */ |
---|
108 | /**@{**/ |
---|
109 | |
---|
110 | /** |
---|
111 | * @brief Memory allocation mutex. |
---|
112 | * |
---|
113 | * This points to the API Mutex instance used to ensure that only |
---|
114 | * one thread at a time is allocating or freeing memory. |
---|
115 | */ |
---|
116 | extern API_Mutex_Control *_RTEMS_Allocator_Mutex; |
---|
117 | |
---|
118 | static inline void _RTEMS_Lock_allocator( void ) |
---|
119 | { |
---|
120 | _API_Mutex_Lock( _RTEMS_Allocator_Mutex ); |
---|
121 | } |
---|
122 | |
---|
123 | static inline void _RTEMS_Unlock_allocator( void ) |
---|
124 | { |
---|
125 | _API_Mutex_Unlock( _RTEMS_Allocator_Mutex ); |
---|
126 | } |
---|
127 | |
---|
128 | static inline bool _RTEMS_Allocator_is_owner( void ) |
---|
129 | { |
---|
130 | return _API_Mutex_Is_owner( _RTEMS_Allocator_Mutex ); |
---|
131 | } |
---|
132 | |
---|
133 | extern API_Mutex_Control *_Once_Mutex; |
---|
134 | |
---|
135 | static inline void _Once_Lock( void ) |
---|
136 | { |
---|
137 | _API_Mutex_Lock( _Once_Mutex ); |
---|
138 | } |
---|
139 | |
---|
140 | static inline void _Once_Unlock( void ) |
---|
141 | { |
---|
142 | _API_Mutex_Unlock( _Once_Mutex ); |
---|
143 | } |
---|
144 | |
---|
145 | /** @} */ |
---|
146 | |
---|
147 | #ifdef __cplusplus |
---|
148 | } |
---|
149 | #endif |
---|
150 | |
---|
151 | #endif |
---|
152 | /* end of include file */ |
---|