source: rtems/cpukit/rtems/src/regiongetsegment.c @ 02c4c441

4.115
Last change on this file since 02c4c441 was 02c4c441, checked in by Sebastian Huber <sebastian.huber@…>, on 04/23/15 at 08:01:22

score: Add Thread_queue_Control::Lock

Move the complete thread queue enqueue procedure into
_Thread_queue_Enqueue_critical(). It is possible to use the thread
queue lock to protect state of the object embedding the thread queue.
This enables per object fine grained locking in the future.

Delete _Thread_queue_Enter_critical_section().

Update #2273.

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