1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Process Region Queue |
---|
5 | * @ingroup ClassicRegion |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-1999. |
---|
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/score/status.h> |
---|
23 | #include <rtems/score/threadqimpl.h> |
---|
24 | |
---|
25 | void _Region_Process_queue( |
---|
26 | Region_Control *the_region |
---|
27 | ) |
---|
28 | { |
---|
29 | Per_CPU_Control *cpu_self; |
---|
30 | Thread_Control *the_thread; |
---|
31 | void *the_segment; |
---|
32 | |
---|
33 | /* |
---|
34 | * Switch from using the memory allocation mutex to using a |
---|
35 | * dispatching disabled critical section. We have to do this |
---|
36 | * because this thread may unblock one or more threads that were |
---|
37 | * waiting on memory. |
---|
38 | * |
---|
39 | * NOTE: Be sure to disable dispatching before unlocking the mutex |
---|
40 | * since we do not want to open a window where a context |
---|
41 | * switch could occur. |
---|
42 | */ |
---|
43 | cpu_self = _Thread_Dispatch_disable(); |
---|
44 | _Region_Unlock( the_region ); |
---|
45 | |
---|
46 | /* |
---|
47 | * NOTE: The following loop is O(n) where n is the number of |
---|
48 | * threads whose memory request is satisfied. |
---|
49 | */ |
---|
50 | for ( ; ; ) { |
---|
51 | the_thread = _Thread_queue_First( |
---|
52 | &the_region->Wait_queue, |
---|
53 | the_region->wait_operations |
---|
54 | ); |
---|
55 | |
---|
56 | if ( the_thread == NULL ) |
---|
57 | break; |
---|
58 | |
---|
59 | the_segment = (void **) _Region_Allocate_segment( |
---|
60 | the_region, |
---|
61 | the_thread->Wait.count |
---|
62 | ); |
---|
63 | |
---|
64 | if ( the_segment == NULL ) |
---|
65 | break; |
---|
66 | |
---|
67 | *(void **)the_thread->Wait.return_argument = the_segment; |
---|
68 | _Thread_queue_Extract( the_thread ); |
---|
69 | the_thread->Wait.return_code = STATUS_SUCCESSFUL; |
---|
70 | } |
---|
71 | |
---|
72 | _Thread_Dispatch_enable( cpu_self ); |
---|
73 | } |
---|