1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Thread Queue Flush |
---|
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/threadimpl.h> |
---|
22 | |
---|
23 | Thread_Control *_Thread_queue_Flush_default_filter( |
---|
24 | Thread_Control *the_thread, |
---|
25 | Thread_queue_Queue *queue, |
---|
26 | Thread_queue_Context *queue_context |
---|
27 | ) |
---|
28 | { |
---|
29 | (void) queue; |
---|
30 | (void) queue_context; |
---|
31 | return the_thread; |
---|
32 | } |
---|
33 | |
---|
34 | size_t _Thread_queue_Flush_critical( |
---|
35 | Thread_queue_Queue *queue, |
---|
36 | const Thread_queue_Operations *operations, |
---|
37 | Thread_queue_Flush_filter filter, |
---|
38 | Thread_queue_Context *queue_context |
---|
39 | ) |
---|
40 | { |
---|
41 | size_t flushed; |
---|
42 | Chain_Control unblock; |
---|
43 | Chain_Node *node; |
---|
44 | Chain_Node *tail; |
---|
45 | |
---|
46 | flushed = 0; |
---|
47 | _Chain_Initialize_empty( &unblock ); |
---|
48 | |
---|
49 | while ( true ) { |
---|
50 | Thread_queue_Heads *heads; |
---|
51 | Thread_Control *first; |
---|
52 | bool do_unblock; |
---|
53 | |
---|
54 | heads = queue->heads; |
---|
55 | if ( heads == NULL ) { |
---|
56 | break; |
---|
57 | } |
---|
58 | |
---|
59 | first = ( *operations->first )( heads ); |
---|
60 | first = ( *filter )( first, queue, queue_context ); |
---|
61 | if ( first == NULL ) { |
---|
62 | break; |
---|
63 | } |
---|
64 | |
---|
65 | do_unblock = _Thread_queue_Extract_locked( |
---|
66 | queue, |
---|
67 | operations, |
---|
68 | first, |
---|
69 | queue_context |
---|
70 | ); |
---|
71 | if ( do_unblock ) { |
---|
72 | _Chain_Append_unprotected( &unblock, &first->Wait.Node.Chain ); |
---|
73 | } |
---|
74 | |
---|
75 | ++flushed; |
---|
76 | } |
---|
77 | |
---|
78 | node = _Chain_First( &unblock ); |
---|
79 | tail = _Chain_Tail( &unblock ); |
---|
80 | |
---|
81 | if ( node != tail ) { |
---|
82 | Per_CPU_Control *cpu_self; |
---|
83 | |
---|
84 | cpu_self = _Thread_Dispatch_disable_critical( |
---|
85 | &queue_context->Lock_context |
---|
86 | ); |
---|
87 | _Thread_queue_Queue_release( queue, &queue_context->Lock_context ); |
---|
88 | |
---|
89 | do { |
---|
90 | Thread_Control *the_thread; |
---|
91 | Chain_Node *next; |
---|
92 | |
---|
93 | next = _Chain_Next( node ); |
---|
94 | the_thread = THREAD_CHAIN_NODE_TO_THREAD( node ); |
---|
95 | _Thread_Remove_timer_and_unblock( the_thread, queue ); |
---|
96 | |
---|
97 | node = next; |
---|
98 | } while ( node != tail ); |
---|
99 | |
---|
100 | _Thread_Dispatch_enable( cpu_self ); |
---|
101 | } else { |
---|
102 | _Thread_queue_Queue_release( queue, &queue_context->Lock_context ); |
---|
103 | } |
---|
104 | |
---|
105 | return flushed; |
---|
106 | } |
---|