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/apimutex.h> |
---|
23 | #include <rtems/score/threadqimpl.h> |
---|
24 | |
---|
25 | void _Region_Process_queue( |
---|
26 | Region_Control *the_region |
---|
27 | ) |
---|
28 | { |
---|
29 | Thread_Control *the_thread; |
---|
30 | void *the_segment; |
---|
31 | /* |
---|
32 | * Switch from using the memory allocation mutex to using a |
---|
33 | * dispatching disabled critical section. We have to do this |
---|
34 | * because this thread may unblock one or more threads that were |
---|
35 | * waiting on memory. |
---|
36 | * |
---|
37 | * NOTE: Be sure to disable dispatching before unlocking the mutex |
---|
38 | * since we do not want to open a window where a context |
---|
39 | * switch could occur. |
---|
40 | */ |
---|
41 | _Thread_Disable_dispatch(); |
---|
42 | _RTEMS_Unlock_allocator(); |
---|
43 | |
---|
44 | /* |
---|
45 | * NOTE: The following loop is O(n) where n is the number of |
---|
46 | * threads whose memory request is satisfied. |
---|
47 | */ |
---|
48 | for ( ; ; ) { |
---|
49 | the_thread = _Thread_queue_First( &the_region->Wait_queue ); |
---|
50 | |
---|
51 | if ( the_thread == NULL ) |
---|
52 | break; |
---|
53 | |
---|
54 | the_segment = (void **) _Region_Allocate_segment( |
---|
55 | the_region, |
---|
56 | the_thread->Wait.count |
---|
57 | ); |
---|
58 | |
---|
59 | if ( the_segment == NULL ) |
---|
60 | break; |
---|
61 | |
---|
62 | *(void **)the_thread->Wait.return_argument = the_segment; |
---|
63 | the_region->number_of_used_blocks += 1; |
---|
64 | _Thread_queue_Extract( the_thread ); |
---|
65 | the_thread->Wait.return_code = RTEMS_SUCCESSFUL; |
---|
66 | } |
---|
67 | _Thread_Enable_dispatch(); |
---|
68 | } |
---|