source: rtems/cpukit/score/src/objectshrinkinformation.c @ 0daa8ab

5
Last change on this file since 0daa8ab was 23fec9f0, checked in by Sebastian Huber <sebastian.huber@…>, on 03/27/14 at 13:16:12

score: PR2152: Use allocator mutex for objects

Use allocator mutex for objects allocate/free. This prevents that the
thread dispatch latency depends on the workspace/heap fragmentation.

  • Property mode set to 100644
File size: 2.1 KB
Line 
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
26void _Objects_Shrink_information(
27  Objects_Information *information
28)
29{
30  uint32_t          block_count;
31  uint32_t          block;
32  uint32_t          index_base;
33
34  _Assert( _Debug_Is_owner_of_allocator() );
35
36  /*
37   * Search the list to find block or chunk with all objects inactive.
38   */
39
40  index_base = _Objects_Get_index( information->minimum_id );
41  block_count = (information->maximum - index_base) /
42                 information->allocation_size;
43
44  for ( block = 0; block < block_count; block++ ) {
45    if ( information->inactive_per_block[ block ] ==
46         information->allocation_size ) {
47      Chain_Node       *node = _Chain_First( &information->Inactive );
48      const Chain_Node *tail = _Chain_Immutable_tail( &information->Inactive );
49      uint32_t          index_end = index_base + information->allocation_size;
50
51      while ( node != tail ) {
52        Objects_Control *object = (Objects_Control *) node;
53        uint32_t         index = _Objects_Get_index( object->id );
54
55        /*
56         *  Get the next node before the node is extracted
57         */
58        node = _Chain_Next( node );
59
60        if ( index >= index_base && index < index_end ) {
61          _Chain_Extract_unprotected( &object->Node );
62        }
63      }
64
65      /*
66       *  Free the memory and reset the structures in the object' information
67       */
68
69      _Workspace_Free( information->object_blocks[ block ] );
70      information->object_blocks[ block ] = NULL;
71      information->inactive_per_block[ block ] = 0;
72
73      information->inactive -= information->allocation_size;
74
75      return;
76    }
77
78    index_base += information->allocation_size;
79  }
80}
Note: See TracBrowser for help on using the repository browser.