1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Shrink an Object Class Information Record |
---|
5 | * @ingroup ScoreCPU |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-1999. |
---|
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 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/score/objectimpl.h> |
---|
22 | #include <rtems/score/assert.h> |
---|
23 | #include <rtems/score/chainimpl.h> |
---|
24 | #include <rtems/score/wkspace.h> |
---|
25 | |
---|
26 | void _Objects_Shrink_information( |
---|
27 | Objects_Information *information |
---|
28 | ) |
---|
29 | { |
---|
30 | Objects_Maximum objects_per_block; |
---|
31 | Objects_Maximum index_base; |
---|
32 | Objects_Maximum block_count; |
---|
33 | Objects_Maximum block; |
---|
34 | |
---|
35 | _Assert( _Objects_Allocator_is_owner() ); |
---|
36 | |
---|
37 | /* |
---|
38 | * Search the list to find block or chunk with all objects inactive. |
---|
39 | */ |
---|
40 | |
---|
41 | objects_per_block = information->objects_per_block; |
---|
42 | index_base = _Objects_Get_index( information->minimum_id ); |
---|
43 | block_count = ( information->maximum - index_base ) / objects_per_block; |
---|
44 | |
---|
45 | for ( block = 0; block < block_count; block++ ) { |
---|
46 | if ( information->inactive_per_block[ block ] == objects_per_block ) { |
---|
47 | Chain_Node *node; |
---|
48 | const Chain_Node *tail; |
---|
49 | uint32_t index_end; |
---|
50 | |
---|
51 | node = _Chain_First( &information->Inactive ); |
---|
52 | tail = _Chain_Immutable_tail( &information->Inactive ); |
---|
53 | index_end = index_base + objects_per_block; |
---|
54 | |
---|
55 | while ( node != tail ) { |
---|
56 | Objects_Control *object; |
---|
57 | uint32_t index; |
---|
58 | |
---|
59 | object = (Objects_Control *) node; |
---|
60 | index = _Objects_Get_index( object->id ); |
---|
61 | |
---|
62 | /* |
---|
63 | * Get the next node before the node is extracted |
---|
64 | */ |
---|
65 | node = _Chain_Next( node ); |
---|
66 | |
---|
67 | if ( index >= index_base && index < index_end ) { |
---|
68 | _Chain_Extract_unprotected( &object->Node ); |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | /* |
---|
73 | * Free the memory and reset the structures in the object' information |
---|
74 | */ |
---|
75 | |
---|
76 | _Workspace_Free( information->object_blocks[ block ] ); |
---|
77 | information->object_blocks[ block ] = NULL; |
---|
78 | information->inactive_per_block[ block ] = 0; |
---|
79 | |
---|
80 | information->inactive -= objects_per_block; |
---|
81 | |
---|
82 | return; |
---|
83 | } |
---|
84 | |
---|
85 | index_base += objects_per_block; |
---|
86 | } |
---|
87 | } |
---|