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