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/apimutex.h> |
---|
22 | #include <rtems/score/heapimpl.h> |
---|
23 | #include <rtems/score/objectimpl.h> |
---|
24 | #include <rtems/score/threadqimpl.h> |
---|
25 | |
---|
26 | #ifdef __cplusplus |
---|
27 | extern "C" { |
---|
28 | #endif |
---|
29 | |
---|
30 | /** |
---|
31 | * @defgroup ClassicRegionImpl Classic Region Manager Implementation |
---|
32 | * |
---|
33 | * @ingroup ClassicRegion |
---|
34 | * |
---|
35 | * @{ |
---|
36 | */ |
---|
37 | |
---|
38 | /** |
---|
39 | * The following defines the information control block used to |
---|
40 | * manage this class of objects. |
---|
41 | */ |
---|
42 | extern Objects_Information _Region_Information; |
---|
43 | |
---|
44 | /** |
---|
45 | * @brief Region_Allocate |
---|
46 | * |
---|
47 | * This function allocates a region control block from |
---|
48 | * the inactive chain of free region control blocks. |
---|
49 | */ |
---|
50 | RTEMS_INLINE_ROUTINE Region_Control *_Region_Allocate( void ) |
---|
51 | { |
---|
52 | return (Region_Control *) _Objects_Allocate( &_Region_Information ); |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | * @brief Region_Free |
---|
57 | * |
---|
58 | * This routine frees a region control block to the |
---|
59 | * inactive chain of free region control blocks. |
---|
60 | */ |
---|
61 | RTEMS_INLINE_ROUTINE void _Region_Free ( |
---|
62 | Region_Control *the_region |
---|
63 | ) |
---|
64 | { |
---|
65 | _Thread_queue_Destroy( &the_region->Wait_queue ); |
---|
66 | _Objects_Free( &_Region_Information, &the_region->Object ); |
---|
67 | } |
---|
68 | |
---|
69 | RTEMS_INLINE_ROUTINE Region_Control *_Region_Get_and_lock( Objects_Id id ) |
---|
70 | { |
---|
71 | Region_Control *the_region; |
---|
72 | |
---|
73 | _RTEMS_Lock_allocator(); |
---|
74 | |
---|
75 | the_region = (Region_Control *) |
---|
76 | _Objects_Get_no_protection( &_Region_Information, id ); |
---|
77 | |
---|
78 | if ( the_region != NULL ) { |
---|
79 | /* Keep allocator lock */ |
---|
80 | return the_region; |
---|
81 | } |
---|
82 | |
---|
83 | _RTEMS_Unlock_allocator(); |
---|
84 | return NULL; |
---|
85 | } |
---|
86 | |
---|
87 | RTEMS_INLINE_ROUTINE void _Region_Unlock( Region_Control *the_region ) |
---|
88 | { |
---|
89 | (void) the_region; |
---|
90 | _RTEMS_Unlock_allocator(); |
---|
91 | } |
---|
92 | |
---|
93 | /** |
---|
94 | * @brief Region_Allocate_segment |
---|
95 | * |
---|
96 | * This function attempts to allocate a segment from the_region. |
---|
97 | * If successful, it returns the address of the allocated segment. |
---|
98 | * Otherwise, it returns NULL. |
---|
99 | */ |
---|
100 | RTEMS_INLINE_ROUTINE void *_Region_Allocate_segment ( |
---|
101 | Region_Control *the_region, |
---|
102 | uintptr_t size |
---|
103 | ) |
---|
104 | { |
---|
105 | return _Heap_Allocate( &the_region->Memory, size ); |
---|
106 | } |
---|
107 | |
---|
108 | /** |
---|
109 | * @brief Region_Free_segment |
---|
110 | * |
---|
111 | * This function frees the_segment to the_region. |
---|
112 | */ |
---|
113 | RTEMS_INLINE_ROUTINE bool _Region_Free_segment ( |
---|
114 | Region_Control *the_region, |
---|
115 | void *the_segment |
---|
116 | ) |
---|
117 | { |
---|
118 | return _Heap_Free( &the_region->Memory, the_segment ); |
---|
119 | } |
---|
120 | |
---|
121 | /** |
---|
122 | * @brief Process Region Queue |
---|
123 | * |
---|
124 | * This is a helper routine which is invoked any time memory is |
---|
125 | * freed. It looks at the set of waiting tasks and attempts to |
---|
126 | * satisfy all outstanding requests. |
---|
127 | * |
---|
128 | * @param[in] the_region is the the region |
---|
129 | */ |
---|
130 | extern void _Region_Process_queue(Region_Control *the_region); |
---|
131 | |
---|
132 | /**@}*/ |
---|
133 | |
---|
134 | #ifdef __cplusplus |
---|
135 | } |
---|
136 | #endif |
---|
137 | |
---|
138 | #if defined(RTEMS_MULTIPROCESSING) |
---|
139 | #include <rtems/rtems/regionmp.h> |
---|
140 | #endif |
---|
141 | |
---|
142 | #endif |
---|
143 | /* end of include file */ |
---|