1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Thread queue Extract priority Helper |
---|
5 | * @ingroup ScoreThreadQ |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2008. |
---|
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/score/threadqimpl.h> |
---|
22 | #include <rtems/score/chainimpl.h> |
---|
23 | #include <rtems/score/isrlevel.h> |
---|
24 | #include <rtems/score/threadimpl.h> |
---|
25 | #include <rtems/score/watchdogimpl.h> |
---|
26 | |
---|
27 | bool _Thread_queue_Extract_priority_helper( |
---|
28 | Thread_Control *the_thread, |
---|
29 | bool requeuing |
---|
30 | ) |
---|
31 | { |
---|
32 | ISR_Level level; |
---|
33 | Chain_Node *head; |
---|
34 | Chain_Node *tail; |
---|
35 | Chain_Node *the_node; |
---|
36 | Chain_Node *next_node; |
---|
37 | Chain_Node *previous_node; |
---|
38 | Thread_Control *new_first_thread; |
---|
39 | Chain_Node *new_first_node; |
---|
40 | Chain_Node *new_second_node; |
---|
41 | Chain_Node *last_node; |
---|
42 | |
---|
43 | the_node = (Chain_Node *) the_thread; |
---|
44 | _ISR_Disable( level ); |
---|
45 | if ( !_States_Is_waiting_on_thread_queue( the_thread->current_state ) ) { |
---|
46 | _ISR_Enable( level ); |
---|
47 | return false; |
---|
48 | } |
---|
49 | |
---|
50 | /* |
---|
51 | * The thread was actually waiting on a thread queue so let's remove it. |
---|
52 | */ |
---|
53 | |
---|
54 | next_node = the_node->next; |
---|
55 | previous_node = the_node->previous; |
---|
56 | |
---|
57 | if ( !_Chain_Is_empty( &the_thread->Wait.Block2n ) ) { |
---|
58 | new_first_node = _Chain_First( &the_thread->Wait.Block2n ); |
---|
59 | new_first_thread = (Thread_Control *) new_first_node; |
---|
60 | last_node = _Chain_Last( &the_thread->Wait.Block2n ); |
---|
61 | new_second_node = new_first_node->next; |
---|
62 | |
---|
63 | previous_node->next = new_first_node; |
---|
64 | next_node->previous = new_first_node; |
---|
65 | new_first_node->next = next_node; |
---|
66 | new_first_node->previous = previous_node; |
---|
67 | |
---|
68 | if ( !_Chain_Has_only_one_node( &the_thread->Wait.Block2n ) ) { |
---|
69 | /* > two threads on 2-n */ |
---|
70 | head = _Chain_Head( &new_first_thread->Wait.Block2n ); |
---|
71 | tail = _Chain_Tail( &new_first_thread->Wait.Block2n ); |
---|
72 | |
---|
73 | new_second_node->previous = head; |
---|
74 | head->next = new_second_node; |
---|
75 | tail->previous = last_node; |
---|
76 | last_node->next = tail; |
---|
77 | } |
---|
78 | } else { |
---|
79 | previous_node->next = next_node; |
---|
80 | next_node->previous = previous_node; |
---|
81 | } |
---|
82 | |
---|
83 | /* |
---|
84 | * If we are not supposed to touch timers or the thread's state, return. |
---|
85 | */ |
---|
86 | |
---|
87 | if ( requeuing ) { |
---|
88 | _ISR_Enable( level ); |
---|
89 | return true; |
---|
90 | } |
---|
91 | |
---|
92 | if ( !_Watchdog_Is_active( &the_thread->Timer ) ) { |
---|
93 | _ISR_Enable( level ); |
---|
94 | } else { |
---|
95 | _Watchdog_Deactivate( &the_thread->Timer ); |
---|
96 | _ISR_Enable( level ); |
---|
97 | (void) _Watchdog_Remove( &the_thread->Timer ); |
---|
98 | } |
---|
99 | _Thread_Unblock( the_thread ); |
---|
100 | |
---|
101 | #if defined(RTEMS_MULTIPROCESSING) |
---|
102 | if ( !_Objects_Is_local_id( the_thread->Object.id ) ) |
---|
103 | _Thread_MP_Free_proxy( the_thread ); |
---|
104 | #endif |
---|
105 | |
---|
106 | return true; |
---|
107 | } |
---|