source: rtems/cpukit/rtems/src/regiongetsegment.c @ f6c7c57d

4.115
Last change on this file since f6c7c57d was f6c7c57d, checked in by Sebastian Huber <sebastian.huber@…>, on 07/23/13 at 12:38:19

rtems: Create region implementation header

Move implementation specific parts of region.h and region.inl into new
header file regionimpl.h. The region.h contains now only the
application visible API.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief RTEMS Get Region Segment
5 *  @ingroup ClassicRegion
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2007.
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.com/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/score/object.h>
25#include <rtems/rtems/optionsimpl.h>
26#include <rtems/rtems/regionimpl.h>
27#include <rtems/score/states.h>
28#include <rtems/score/thread.h>
29#include <rtems/score/apimutex.h>
30
31rtems_status_code rtems_region_get_segment(
32  rtems_id           id,
33  uintptr_t          size,
34  rtems_option       option_set,
35  rtems_interval     timeout,
36  void              **segment
37)
38{
39  Thread_Control     *executing;
40  Objects_Locations   location;
41  rtems_status_code   return_status;
42  Region_Control     *the_region;
43  void               *the_segment;
44
45  if ( !segment )
46    return RTEMS_INVALID_ADDRESS;
47
48  *segment = NULL;
49
50  if ( size == 0 )
51    return RTEMS_INVALID_SIZE;
52
53  _RTEMS_Lock_allocator();
54
55    executing  = _Thread_Executing;
56    the_region = _Region_Get( id, &location );
57    switch ( location ) {
58
59      case OBJECTS_LOCAL:
60        if ( size > the_region->maximum_segment_size )
61          return_status = RTEMS_INVALID_SIZE;
62
63        else {
64          _Region_Debug_Walk( the_region, 1 );
65
66          the_segment = _Region_Allocate_segment( the_region, size );
67
68          _Region_Debug_Walk( the_region, 2 );
69
70          if ( the_segment ) {
71            the_region->number_of_used_blocks += 1;
72            *segment = the_segment;
73            return_status = RTEMS_SUCCESSFUL;
74          } else if ( _Options_Is_no_wait( option_set ) ) {
75            return_status = RTEMS_UNSATISFIED;
76          } else {
77            /*
78             *  Switch from using the memory allocation mutex to using a
79             *  dispatching disabled critical section.  We have to do this
80             *  because this thread is going to block.
81             */
82            /* FIXME: Lock order reversal */
83            _Thread_Disable_dispatch();
84            _RTEMS_Unlock_allocator();
85
86            executing->Wait.queue           = &the_region->Wait_queue;
87            executing->Wait.id              = id;
88            executing->Wait.count           = size;
89            executing->Wait.return_argument = segment;
90
91            _Thread_queue_Enter_critical_section( &the_region->Wait_queue );
92
93            _Thread_queue_Enqueue( &the_region->Wait_queue, timeout );
94
95            _Objects_Put( &the_region->Object );
96
97            return (rtems_status_code) executing->Wait.return_code;
98          }
99        }
100        break;
101
102#if defined(RTEMS_MULTIPROCESSING)
103      case OBJECTS_REMOTE:        /* this error cannot be returned */
104        break;
105#endif
106
107      case OBJECTS_ERROR:
108      default:
109        return_status = RTEMS_INVALID_ID;
110        break;
111    }
112
113  _RTEMS_Unlock_allocator();
114  return return_status;
115}
Note: See TracBrowser for help on using the repository browser.