1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup RTEMSScoreObject |
---|
7 | * |
---|
8 | * @brief This source file contains the implementation of |
---|
9 | * _Objects_Free_objects_block() and _Objects_Shrink_information(). |
---|
10 | */ |
---|
11 | |
---|
12 | /* |
---|
13 | * COPYRIGHT (c) 1989-1999. |
---|
14 | * On-Line Applications Research Corporation (OAR). |
---|
15 | * |
---|
16 | * Redistribution and use in source and binary forms, with or without |
---|
17 | * modification, are permitted provided that the following conditions |
---|
18 | * are met: |
---|
19 | * 1. Redistributions of source code must retain the above copyright |
---|
20 | * notice, this list of conditions and the following disclaimer. |
---|
21 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
22 | * notice, this list of conditions and the following disclaimer in the |
---|
23 | * documentation and/or other materials provided with the distribution. |
---|
24 | * |
---|
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
35 | * POSSIBILITY OF SUCH DAMAGE. |
---|
36 | */ |
---|
37 | |
---|
38 | #ifdef HAVE_CONFIG_H |
---|
39 | #include "config.h" |
---|
40 | #endif |
---|
41 | |
---|
42 | #include <rtems/score/objectimpl.h> |
---|
43 | #include <rtems/score/assert.h> |
---|
44 | #include <rtems/score/chainimpl.h> |
---|
45 | #include <rtems/score/wkspace.h> |
---|
46 | |
---|
47 | void _Objects_Free_objects_block( |
---|
48 | Objects_Information *information, |
---|
49 | Objects_Maximum block |
---|
50 | ) |
---|
51 | { |
---|
52 | Objects_Maximum objects_per_block; |
---|
53 | Objects_Maximum index_base; |
---|
54 | Objects_Maximum index_end; |
---|
55 | Chain_Node *node; |
---|
56 | const Chain_Node *tail; |
---|
57 | |
---|
58 | objects_per_block = information->objects_per_block; |
---|
59 | |
---|
60 | _Assert( _Objects_Allocator_is_owner() ); |
---|
61 | _Assert( _Objects_Is_auto_extend( information ) ); |
---|
62 | _Assert( block >= 1 ); |
---|
63 | _Assert( |
---|
64 | block < _Objects_Get_maximum_index( information ) / objects_per_block |
---|
65 | ); |
---|
66 | |
---|
67 | index_base = block * objects_per_block; |
---|
68 | index_end = index_base + objects_per_block; |
---|
69 | node = _Chain_First( &information->Inactive ); |
---|
70 | tail = _Chain_Immutable_tail( &information->Inactive ); |
---|
71 | |
---|
72 | while ( node != tail ) { |
---|
73 | Objects_Control *object; |
---|
74 | uint32_t index; |
---|
75 | |
---|
76 | object = (Objects_Control *) node; |
---|
77 | index = _Objects_Get_index( object->id ) - OBJECTS_INDEX_MINIMUM; |
---|
78 | |
---|
79 | /* |
---|
80 | * Get the next node before the node is extracted |
---|
81 | */ |
---|
82 | node = _Chain_Next( node ); |
---|
83 | |
---|
84 | if ( index >= index_base && index < index_end ) { |
---|
85 | _Chain_Extract_unprotected( &object->Node ); |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | /* |
---|
90 | * Free the memory and reset the structures in the object' information |
---|
91 | */ |
---|
92 | |
---|
93 | _Workspace_Free( information->object_blocks[ block ] ); |
---|
94 | information->object_blocks[ block ] = NULL; |
---|
95 | information->inactive_per_block[ block ] = 0; |
---|
96 | information->inactive -= objects_per_block; |
---|
97 | } |
---|
98 | |
---|
99 | void _Objects_Shrink_information( |
---|
100 | Objects_Information *information |
---|
101 | ) |
---|
102 | { |
---|
103 | Objects_Maximum objects_per_block; |
---|
104 | Objects_Maximum block_count; |
---|
105 | Objects_Maximum block; |
---|
106 | |
---|
107 | _Assert( _Objects_Allocator_is_owner() ); |
---|
108 | _Assert( _Objects_Is_auto_extend( information ) ); |
---|
109 | |
---|
110 | /* |
---|
111 | * Search the list to find block or chunk with all objects inactive. |
---|
112 | */ |
---|
113 | |
---|
114 | objects_per_block = information->objects_per_block; |
---|
115 | block_count = _Objects_Get_maximum_index( information ) / objects_per_block; |
---|
116 | |
---|
117 | for ( block = 1; block < block_count; block++ ) { |
---|
118 | if ( information->inactive_per_block[ block ] == objects_per_block ) { |
---|
119 | _Objects_Free_objects_block( information, block ); |
---|
120 | return; |
---|
121 | } |
---|
122 | } |
---|
123 | } |
---|