blob: 73f91617b59eb92765766a5a808cb2094df4f30e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/**
* @file
*
* @brief Shrink an Object Class Information Record
*/
/*
* COPYRIGHT (c) 1989-1999.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems/score/objectimpl.h>
#include <rtems/score/assert.h>
#include <rtems/score/chainimpl.h>
#include <rtems/score/wkspace.h>
void _Objects_Free_objects_block(
Objects_Information *information,
Objects_Maximum block
)
{
Objects_Maximum objects_per_block;
Objects_Maximum index_base;
Objects_Maximum index_end;
Chain_Node *node;
const Chain_Node *tail;
objects_per_block = information->objects_per_block;
_Assert( _Objects_Allocator_is_owner() );
_Assert( _Objects_Is_auto_extend( information ) );
_Assert( block >= 1 );
_Assert(
block < _Objects_Get_maximum_index( information ) / objects_per_block
);
index_base = block * objects_per_block;
index_end = index_base + objects_per_block;
node = _Chain_First( &information->Inactive );
tail = _Chain_Immutable_tail( &information->Inactive );
while ( node != tail ) {
Objects_Control *object;
uint32_t index;
object = (Objects_Control *) node;
index = _Objects_Get_index( object->id ) - OBJECTS_INDEX_MINIMUM;
/*
* Get the next node before the node is extracted
*/
node = _Chain_Next( node );
if ( index >= index_base && index < index_end ) {
_Chain_Extract_unprotected( &object->Node );
}
}
/*
* Free the memory and reset the structures in the object' information
*/
_Workspace_Free( information->object_blocks[ block ] );
information->object_blocks[ block ] = NULL;
information->inactive_per_block[ block ] = 0;
information->inactive -= objects_per_block;
}
void _Objects_Shrink_information(
Objects_Information *information
)
{
Objects_Maximum objects_per_block;
Objects_Maximum block_count;
Objects_Maximum block;
_Assert( _Objects_Allocator_is_owner() );
_Assert( _Objects_Is_auto_extend( information ) );
/*
* Search the list to find block or chunk with all objects inactive.
*/
objects_per_block = information->objects_per_block;
block_count = _Objects_Get_maximum_index( information ) / objects_per_block;
for ( block = 1; block < block_count; block++ ) {
if ( information->inactive_per_block[ block ] == objects_per_block ) {
_Objects_Free_objects_block( information, block );
return;
}
}
}
|