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

5
Last change on this file since 3692095 was 93306058, checked in by Sebastian Huber <sebastian.huber@…>, on 05/27/16 at 12:43:19

score: _CORE_mutex_Check_dispatch_for_seize()

Move the safety check performed by
_CORE_mutex_Check_dispatch_for_seize() out of the performance critical
path and generalize it. Blocking on a thread queue with an unexpected
thread dispatch disabled level is illegal in all system states.

Add the expected thread dispatch disable level (which may be 1 or 2
depending on the operation) to Thread_queue_Context and use it in
_Thread_queue_Enqueue_critical().

  • Property mode set to 100644
File size: 2.3 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/rtems/statusimpl.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  rtems_status_code  status;
36  Region_Control    *the_region;
37
38  if ( segment == NULL ) {
39    return RTEMS_INVALID_ADDRESS;
40  }
41
42  *segment = NULL;
43
44  if ( size == 0 ) {
45    return RTEMS_INVALID_SIZE;
46  }
47
48  the_region = _Region_Get_and_lock( id );
49
50  if ( the_region == NULL ) {
51    return RTEMS_INVALID_ID;
52  }
53
54  if ( size > the_region->maximum_segment_size ) {
55    status = RTEMS_INVALID_SIZE;
56  } else {
57    void *the_segment;
58
59    the_segment = _Region_Allocate_segment( the_region, size );
60
61    if ( the_segment != NULL ) {
62      *segment = the_segment;
63      status = RTEMS_SUCCESSFUL;
64    } else if ( _Options_Is_no_wait( option_set ) ) {
65      status = RTEMS_UNSATISFIED;
66    } else {
67      Per_CPU_Control *cpu_self;
68      Thread_Control  *executing;
69
70      /*
71       *  Switch from using the memory allocation mutex to using a
72       *  dispatching disabled critical section.  We have to do this
73       *  because this thread is going to block.
74       */
75      /* FIXME: This is a home grown condition variable */
76      cpu_self = _Thread_Dispatch_disable();
77      _Region_Unlock( the_region );
78
79      executing  = _Per_CPU_Get_executing( cpu_self );
80
81      executing->Wait.count           = size;
82      executing->Wait.return_argument = segment;
83
84      _Thread_queue_Enqueue(
85        &the_region->Wait_queue,
86        the_region->wait_operations,
87        executing,
88        STATES_WAITING_FOR_SEGMENT,
89        timeout,
90        2
91      );
92
93      _Thread_Dispatch_enable( cpu_self );
94
95      return _Status_Get_after_wait( executing );
96    }
97  }
98
99  _Region_Unlock( the_region );
100  return status;
101}
Note: See TracBrowser for help on using the repository browser.