1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup RTEMSImplClassicRegion |
---|
7 | * |
---|
8 | * @brief This header file provides the implementation interfaces of |
---|
9 | * the @ref RTEMSImplClassicRegion. |
---|
10 | */ |
---|
11 | |
---|
12 | /* COPYRIGHT (c) 1989-2008. |
---|
13 | * On-Line Applications Research Corporation (OAR). |
---|
14 | * |
---|
15 | * Redistribution and use in source and binary forms, with or without |
---|
16 | * modification, are permitted provided that the following conditions |
---|
17 | * are met: |
---|
18 | * 1. Redistributions of source code must retain the above copyright |
---|
19 | * notice, this list of conditions and the following disclaimer. |
---|
20 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
21 | * notice, this list of conditions and the following disclaimer in the |
---|
22 | * documentation and/or other materials provided with the distribution. |
---|
23 | * |
---|
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
34 | * POSSIBILITY OF SUCH DAMAGE. |
---|
35 | */ |
---|
36 | |
---|
37 | #ifndef _RTEMS_RTEMS_REGIONIMPL_H |
---|
38 | #define _RTEMS_RTEMS_REGIONIMPL_H |
---|
39 | |
---|
40 | #include <rtems/rtems/regiondata.h> |
---|
41 | #include <rtems/score/apimutex.h> |
---|
42 | #include <rtems/score/heapimpl.h> |
---|
43 | #include <rtems/score/objectimpl.h> |
---|
44 | #include <rtems/score/threadqimpl.h> |
---|
45 | |
---|
46 | #ifdef __cplusplus |
---|
47 | extern "C" { |
---|
48 | #endif |
---|
49 | |
---|
50 | /** |
---|
51 | * @defgroup RTEMSImplClassicRegion Region Manager |
---|
52 | * |
---|
53 | * @ingroup RTEMSImplClassic |
---|
54 | * |
---|
55 | * @brief This group contains the Region Manager implementation. |
---|
56 | * |
---|
57 | * @{ |
---|
58 | */ |
---|
59 | |
---|
60 | #define REGION_OF_THREAD_QUEUE_QUEUE( queue ) \ |
---|
61 | RTEMS_CONTAINER_OF( queue, Region_Control, Wait_queue.Queue ) |
---|
62 | |
---|
63 | /** |
---|
64 | * @brief Region_Allocate |
---|
65 | * |
---|
66 | * This function allocates a region control block from |
---|
67 | * the inactive chain of free region control blocks. |
---|
68 | */ |
---|
69 | RTEMS_INLINE_ROUTINE Region_Control *_Region_Allocate( void ) |
---|
70 | { |
---|
71 | return (Region_Control *) _Objects_Allocate( &_Region_Information ); |
---|
72 | } |
---|
73 | |
---|
74 | /** |
---|
75 | * @brief Region_Free |
---|
76 | * |
---|
77 | * This routine frees a region control block to the |
---|
78 | * inactive chain of free region control blocks. |
---|
79 | */ |
---|
80 | RTEMS_INLINE_ROUTINE void _Region_Free ( |
---|
81 | Region_Control *the_region |
---|
82 | ) |
---|
83 | { |
---|
84 | _Thread_queue_Destroy( &the_region->Wait_queue ); |
---|
85 | _Objects_Free( &_Region_Information, &the_region->Object ); |
---|
86 | } |
---|
87 | |
---|
88 | RTEMS_INLINE_ROUTINE Region_Control *_Region_Get_and_lock( Objects_Id id ) |
---|
89 | { |
---|
90 | Region_Control *the_region; |
---|
91 | |
---|
92 | _RTEMS_Lock_allocator(); |
---|
93 | |
---|
94 | the_region = (Region_Control *) |
---|
95 | _Objects_Get_no_protection( id, &_Region_Information ); |
---|
96 | |
---|
97 | if ( the_region != NULL ) { |
---|
98 | /* Keep allocator lock */ |
---|
99 | return the_region; |
---|
100 | } |
---|
101 | |
---|
102 | _RTEMS_Unlock_allocator(); |
---|
103 | return NULL; |
---|
104 | } |
---|
105 | |
---|
106 | RTEMS_INLINE_ROUTINE void _Region_Unlock( Region_Control *the_region ) |
---|
107 | { |
---|
108 | (void) the_region; |
---|
109 | _RTEMS_Unlock_allocator(); |
---|
110 | } |
---|
111 | |
---|
112 | /** |
---|
113 | * @brief Region_Allocate_segment |
---|
114 | * |
---|
115 | * This function attempts to allocate a segment from the_region. |
---|
116 | * If successful, it returns the address of the allocated segment. |
---|
117 | * Otherwise, it returns NULL. |
---|
118 | */ |
---|
119 | RTEMS_INLINE_ROUTINE void *_Region_Allocate_segment ( |
---|
120 | Region_Control *the_region, |
---|
121 | uintptr_t size |
---|
122 | ) |
---|
123 | { |
---|
124 | return _Heap_Allocate( &the_region->Memory, size ); |
---|
125 | } |
---|
126 | |
---|
127 | /** |
---|
128 | * @brief Region_Free_segment |
---|
129 | * |
---|
130 | * This function frees the_segment to the_region. |
---|
131 | */ |
---|
132 | RTEMS_INLINE_ROUTINE bool _Region_Free_segment ( |
---|
133 | Region_Control *the_region, |
---|
134 | void *the_segment |
---|
135 | ) |
---|
136 | { |
---|
137 | return _Heap_Free( &the_region->Memory, the_segment ); |
---|
138 | } |
---|
139 | |
---|
140 | /** |
---|
141 | * @brief Process Region Queue |
---|
142 | * |
---|
143 | * This is a helper routine which is invoked any time memory is |
---|
144 | * freed. It looks at the set of waiting tasks and attempts to |
---|
145 | * satisfy all outstanding requests. |
---|
146 | * |
---|
147 | * @param[in] the_region is the the region |
---|
148 | */ |
---|
149 | extern void _Region_Process_queue(Region_Control *the_region); |
---|
150 | |
---|
151 | /**@}*/ |
---|
152 | |
---|
153 | #ifdef __cplusplus |
---|
154 | } |
---|
155 | #endif |
---|
156 | |
---|
157 | #endif |
---|
158 | /* end of include file */ |
---|