1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup ClassicRegionImpl |
---|
5 | * |
---|
6 | * @brief Classic Region Manager Implementation |
---|
7 | */ |
---|
8 | |
---|
9 | /* COPYRIGHT (c) 1989-2008. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #ifndef _RTEMS_RTEMS_REGIONIMPL_H |
---|
18 | #define _RTEMS_RTEMS_REGIONIMPL_H |
---|
19 | |
---|
20 | #include <rtems/rtems/region.h> |
---|
21 | #include <rtems/score/heapimpl.h> |
---|
22 | #include <rtems/score/objectimpl.h> |
---|
23 | #include <rtems/score/threadqimpl.h> |
---|
24 | |
---|
25 | #ifdef __cplusplus |
---|
26 | extern "C" { |
---|
27 | #endif |
---|
28 | |
---|
29 | /** |
---|
30 | * @defgroup ClassicRegionImpl Classic Region Manager Implementation |
---|
31 | * |
---|
32 | * @ingroup ClassicRegion |
---|
33 | * |
---|
34 | * @{ |
---|
35 | */ |
---|
36 | |
---|
37 | /** |
---|
38 | * @brief Instantiate RTEMS Region Data |
---|
39 | * |
---|
40 | * Region Manager -- Instantiate Data |
---|
41 | * |
---|
42 | * This constant is defined to extern most of the time when using |
---|
43 | * this header file. However by defining it to nothing, the data |
---|
44 | * declared in this header file can be instantiated. This is done |
---|
45 | * in a single per manager file. |
---|
46 | */ |
---|
47 | #ifndef RTEMS_REGION_EXTERN |
---|
48 | #define RTEMS_REGION_EXTERN extern |
---|
49 | #endif |
---|
50 | |
---|
51 | /** |
---|
52 | * The following defines the information control block used to |
---|
53 | * manage this class of objects. |
---|
54 | */ |
---|
55 | RTEMS_REGION_EXTERN Objects_Information _Region_Information; |
---|
56 | |
---|
57 | /** |
---|
58 | * @brief _Region_Manager_initialization |
---|
59 | * |
---|
60 | * Region Manager |
---|
61 | * |
---|
62 | * This routine performs the initialization necessary for this manager. |
---|
63 | */ |
---|
64 | void _Region_Manager_initialization(void); |
---|
65 | |
---|
66 | /** |
---|
67 | * @brief Region_Allocate |
---|
68 | * |
---|
69 | * This function allocates a region control block from |
---|
70 | * the inactive chain of free region control blocks. |
---|
71 | */ |
---|
72 | RTEMS_INLINE_ROUTINE Region_Control *_Region_Allocate( void ) |
---|
73 | { |
---|
74 | return (Region_Control *) _Objects_Allocate( &_Region_Information ); |
---|
75 | } |
---|
76 | |
---|
77 | /** |
---|
78 | * @brief Region_Free |
---|
79 | * |
---|
80 | * This routine frees a region control block to the |
---|
81 | * inactive chain of free region control blocks. |
---|
82 | */ |
---|
83 | RTEMS_INLINE_ROUTINE void _Region_Free ( |
---|
84 | Region_Control *the_region |
---|
85 | ) |
---|
86 | { |
---|
87 | _Thread_queue_Destroy( &the_region->Wait_queue ); |
---|
88 | _Objects_Free( &_Region_Information, &the_region->Object ); |
---|
89 | } |
---|
90 | |
---|
91 | /** |
---|
92 | * @brief Region_Get |
---|
93 | * |
---|
94 | * This function maps region IDs to region control blocks. |
---|
95 | * If ID corresponds to a local region, then it returns |
---|
96 | * the_region control pointer which maps to ID and location |
---|
97 | * is set to OBJECTS_LOCAL. Otherwise, location is set |
---|
98 | * to OBJECTS_ERROR and the_region is undefined. |
---|
99 | */ |
---|
100 | RTEMS_INLINE_ROUTINE Region_Control *_Region_Get ( |
---|
101 | Objects_Id id, |
---|
102 | Objects_Locations *location |
---|
103 | ) |
---|
104 | { |
---|
105 | return (Region_Control *) |
---|
106 | _Objects_Get_no_protection( &_Region_Information, id, location ); |
---|
107 | } |
---|
108 | |
---|
109 | /** |
---|
110 | * @brief Region_Allocate_segment |
---|
111 | * |
---|
112 | * This function attempts to allocate a segment from the_region. |
---|
113 | * If successful, it returns the address of the allocated segment. |
---|
114 | * Otherwise, it returns NULL. |
---|
115 | */ |
---|
116 | RTEMS_INLINE_ROUTINE void *_Region_Allocate_segment ( |
---|
117 | Region_Control *the_region, |
---|
118 | uintptr_t size |
---|
119 | ) |
---|
120 | { |
---|
121 | return _Heap_Allocate( &the_region->Memory, size ); |
---|
122 | } |
---|
123 | |
---|
124 | /** |
---|
125 | * @brief Region_Free_segment |
---|
126 | * |
---|
127 | * This function frees the_segment to the_region. |
---|
128 | */ |
---|
129 | RTEMS_INLINE_ROUTINE bool _Region_Free_segment ( |
---|
130 | Region_Control *the_region, |
---|
131 | void *the_segment |
---|
132 | ) |
---|
133 | { |
---|
134 | return _Heap_Free( &the_region->Memory, the_segment ); |
---|
135 | } |
---|
136 | |
---|
137 | /** |
---|
138 | * @brief Process Region Queue |
---|
139 | * |
---|
140 | * This is a helper routine which is invoked any time memory is |
---|
141 | * freed. It looks at the set of waiting tasks and attempts to |
---|
142 | * satisfy all outstanding requests. |
---|
143 | * |
---|
144 | * @param[in] the_region is the the region |
---|
145 | */ |
---|
146 | extern void _Region_Process_queue(Region_Control *the_region); |
---|
147 | |
---|
148 | /**@}*/ |
---|
149 | |
---|
150 | #ifdef __cplusplus |
---|
151 | } |
---|
152 | #endif |
---|
153 | |
---|
154 | #if defined(RTEMS_MULTIPROCESSING) |
---|
155 | #include <rtems/rtems/regionmp.h> |
---|
156 | #endif |
---|
157 | |
---|
158 | #endif |
---|
159 | /* end of include file */ |
---|