source: rtems/cpukit/rtems/src/regionresizesegment.c @ 1240aade

5
Last change on this file since 1240aade was 1142f55, checked in by Sebastian Huber <sebastian.huber@…>, on 04/08/16 at 04:56:46

rtems: Add and use _Region_Get_and_lock()

Get region and lock allocator in _Region_Get_and_lock() in case the
region exists and unlock it in _Region_Unlock().

  • Property mode set to 100644
File size: 1.4 KB
RevLine 
[52adc808]1/**
2 *  @file
[80f2885b]3 *
[52adc808]4 *  @brief Resize RTEMS Region Segment
5 *  @ingroup ClassicRegion
6 */
7
8/*
[3a638ce]9 *  COPYRIGHT (c) 1989-2014.
[80f2885b]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
[c499856]14 *  http://www.rtems.org/license/LICENSE.
[80f2885b]15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
[f6c7c57d]21#include <rtems/rtems/regionimpl.h>
[80f2885b]22
23rtems_status_code rtems_region_resize_segment(
[d3b72ca3]24  rtems_id    id,
[80f2885b]25  void       *segment,
[dea3eccb]26  uintptr_t   size,
27  uintptr_t  *old_size
[80f2885b]28)
29{
[572cb624]30  uintptr_t           avail_size;
31  uintptr_t           osize;
32  rtems_status_code   status;
33  Heap_Resize_status  resize_status;
34  Region_Control     *the_region;
[80f2885b]35
[572cb624]36  if ( old_size == NULL ) {
[80f2885b]37    return RTEMS_INVALID_ADDRESS;
[572cb624]38  }
[80f2885b]39
[1142f55]40  the_region = _Region_Get_and_lock( id );
[80f2885b]41
[1142f55]42  if ( the_region == NULL ) {
43    return RTEMS_INVALID_ID;
44  }
[5700b804]45
[1142f55]46  resize_status = _Heap_Resize_block(
47    &the_region->Memory,
48    segment,
49    (uint32_t) size,
50    &osize,
51    &avail_size
52  );
53  *old_size = (uint32_t) osize;
[80f2885b]54
[1142f55]55  switch ( resize_status ) {
56    case HEAP_RESIZE_SUCCESSFUL:
57      /* Unlocks allocator */
58      _Region_Process_queue( the_region );
59      return RTEMS_SUCCESSFUL;
[80f2885b]60
[1142f55]61    case HEAP_RESIZE_UNSATISFIED:
62      status = RTEMS_UNSATISFIED;
63      break;
[80f2885b]64
[1142f55]65    default:
66      status = RTEMS_INVALID_ADDRESS;
67      break;
[572cb624]68  }
[80f2885b]69
[1142f55]70  _Region_Unlock( the_region );
[572cb624]71  return status;
[80f2885b]72}
Note: See TracBrowser for help on using the repository browser.