source: rtems/cpukit/rtems/src/regionprocessqueue.c @ ebe61382

4.104.114.95
Last change on this file since ebe61382 was 2ff7d00, checked in by Ralf Corsepius <ralf.corsepius@…>, on 05/08/07 at 15:34:14

Add HAVE_CONFIG_H magic.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 *  Region Manager
3 *
4 *
5 *  COPYRIGHT (c) 1989-1999.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/rtems/status.h>
21#include <rtems/rtems/support.h>
22#include <rtems/score/object.h>
23#include <rtems/rtems/options.h>
24#include <rtems/rtems/region.h>
25#include <rtems/score/states.h>
26#include <rtems/score/thread.h>
27#include <rtems/score/apimutex.h>
28
29/*PAGE
30 *
31 *  _Region_Process_queue
32 *
33 *  If enough memory is available to satisfy the rtems_region_get_segment of
34 *  the first blocked task, then that task and as many subsequent tasks as
35 *  possible will be unblocked with their requests satisfied.
36 *
37 *  Input parameters:
38 *    the_region - the region
39 *
40 *  Output parameters:
41 *    none
42 */
43
44void _Region_Process_queue(
45  Region_Control *the_region
46)
47{
48  Thread_Control *the_thread;
49  void           *the_segment;
50  /*
51   *  Switch from using the memory allocation mutex to using a
52   *  dispatching disabled critical section.  We have to do this
53   *  because this thread may unblock one or more threads that were
54   *  waiting on memory. 
55   *
56   *  NOTE: Be sure to disable dispatching before unlocking the mutex
57   *        since we do not want to open a window where a context
58   *        switch could occur.
59   */
60  _Thread_Disable_dispatch();
61  _RTEMS_Unlock_allocator();
62
63  /*
64   *  NOTE: The following loop is O(n) where n is the number of
65   *        threads whose memory request is satisfied.
66   */
67  for ( ; ; ) {
68    the_thread = _Thread_queue_First( &the_region->Wait_queue );
69
70    if ( the_thread == NULL )
71      break;
72
73    the_segment = (void **) _Region_Allocate_segment(
74      the_region,
75      the_thread->Wait.count
76    );
77
78    if ( the_segment == NULL )
79      break;
80
81    *(void **)the_thread->Wait.return_argument = the_segment;
82    the_region->number_of_used_blocks += 1;
83    _Thread_queue_Extract( &the_region->Wait_queue, the_thread );
84    the_thread->Wait.return_code = RTEMS_SUCCESSFUL;
85  }
86  _Thread_Enable_dispatch();
87}
Note: See TracBrowser for help on using the repository browser.