source: rtems/cpukit/rtems/src/regionresizesegment.c @ 23fec9f0

4.115
Last change on this file since 23fec9f0 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 Resize RTEMS Region Segment
5 *  @ingroup ClassicRegion
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2014.
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/system.h>
22#include <rtems/rtems/status.h>
23#include <rtems/rtems/support.h>
24#include <rtems/rtems/options.h>
25#include <rtems/rtems/regionimpl.h>
26#include <rtems/score/thread.h>
27#include <rtems/score/apimutex.h>
28
29rtems_status_code rtems_region_resize_segment(
30  rtems_id    id,
31  void       *segment,
32  uintptr_t   size,
33  uintptr_t  *old_size
34)
35{
36  uintptr_t                avail_size;
37  Objects_Locations        location;
38  uintptr_t                osize;
39  rtems_status_code        return_status;
40  Heap_Resize_status       status;
41  Region_Control          *the_region;
42
43  if ( !old_size )
44    return RTEMS_INVALID_ADDRESS;
45
46  _RTEMS_Lock_allocator();
47
48    the_region = _Region_Get( id, &location );
49    switch ( location ) {
50
51      case OBJECTS_LOCAL:
52
53        _Region_Debug_Walk( the_region, 7 );
54
55        status = _Heap_Resize_block(
56          &the_region->Memory,
57          segment,
58          (uint32_t) size,
59          &osize,
60          &avail_size
61        );
62        *old_size = (uint32_t) osize;
63
64        _Region_Debug_Walk( the_region, 8 );
65
66        if ( status == HEAP_RESIZE_SUCCESSFUL )
67          /* unlocks allocator */
68          _Region_Process_queue( the_region );
69        else
70          _RTEMS_Unlock_allocator();
71
72
73        if (status == HEAP_RESIZE_SUCCESSFUL)
74          return RTEMS_SUCCESSFUL;
75        if (status == HEAP_RESIZE_UNSATISFIED)
76          return RTEMS_UNSATISFIED;
77        return RTEMS_INVALID_ADDRESS;
78        break;
79
80#if defined(RTEMS_MULTIPROCESSING)
81      case OBJECTS_REMOTE:        /* this error cannot be returned */
82        break;
83#endif
84
85      case OBJECTS_ERROR:
86      default:
87        return_status = RTEMS_INVALID_ID;
88        break;
89    }
90
91  _RTEMS_Unlock_allocator();
92  return return_status;
93}
Note: See TracBrowser for help on using the repository browser.