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 | #include <rtems/score/status.h> |
---|
23 | |
---|
24 | Thread_Control *_Thread_queue_Flush_default_filter( |
---|
25 | Thread_Control *the_thread, |
---|
26 | Thread_queue_Queue *queue, |
---|
27 | Thread_queue_Context *queue_context |
---|
28 | ) |
---|
29 | { |
---|
30 | (void) queue; |
---|
31 | (void) queue_context; |
---|
32 | return the_thread; |
---|
33 | } |
---|
34 | |
---|
35 | Thread_Control *_Thread_queue_Flush_status_object_was_deleted( |
---|
36 | Thread_Control *the_thread, |
---|
37 | Thread_queue_Queue *queue, |
---|
38 | Thread_queue_Context *queue_context |
---|
39 | ) |
---|
40 | { |
---|
41 | the_thread->Wait.return_code = STATUS_OBJECT_WAS_DELETED; |
---|
42 | |
---|
43 | (void) queue; |
---|
44 | (void) queue_context; |
---|
45 | return the_thread; |
---|
46 | } |
---|
47 | |
---|
48 | Thread_Control *_Thread_queue_Flush_status_unavailable( |
---|
49 | Thread_Control *the_thread, |
---|
50 | Thread_queue_Queue *queue, |
---|
51 | Thread_queue_Context *queue_context |
---|
52 | ) |
---|
53 | { |
---|
54 | the_thread->Wait.return_code = STATUS_UNAVAILABLE; |
---|
55 | |
---|
56 | (void) queue; |
---|
57 | (void) queue_context; |
---|
58 | return the_thread; |
---|
59 | } |
---|
60 | |
---|
61 | size_t _Thread_queue_Flush_critical( |
---|
62 | Thread_queue_Queue *queue, |
---|
63 | const Thread_queue_Operations *operations, |
---|
64 | Thread_queue_Flush_filter filter, |
---|
65 | Thread_queue_Context *queue_context |
---|
66 | ) |
---|
67 | { |
---|
68 | size_t flushed; |
---|
69 | Chain_Control unblock; |
---|
70 | Chain_Node *node; |
---|
71 | Chain_Node *tail; |
---|
72 | |
---|
73 | flushed = 0; |
---|
74 | _Chain_Initialize_empty( &unblock ); |
---|
75 | |
---|
76 | while ( true ) { |
---|
77 | Thread_queue_Heads *heads; |
---|
78 | Thread_Control *first; |
---|
79 | bool do_unblock; |
---|
80 | |
---|
81 | heads = queue->heads; |
---|
82 | if ( heads == NULL ) { |
---|
83 | break; |
---|
84 | } |
---|
85 | |
---|
86 | first = ( *operations->first )( heads ); |
---|
87 | first = ( *filter )( first, queue, queue_context ); |
---|
88 | if ( first == NULL ) { |
---|
89 | break; |
---|
90 | } |
---|
91 | |
---|
92 | do_unblock = _Thread_queue_Extract_locked( |
---|
93 | queue, |
---|
94 | operations, |
---|
95 | first, |
---|
96 | queue_context |
---|
97 | ); |
---|
98 | if ( do_unblock ) { |
---|
99 | _Chain_Append_unprotected( &unblock, &first->Wait.Node.Chain ); |
---|
100 | } |
---|
101 | |
---|
102 | ++flushed; |
---|
103 | } |
---|
104 | |
---|
105 | node = _Chain_First( &unblock ); |
---|
106 | tail = _Chain_Tail( &unblock ); |
---|
107 | |
---|
108 | if ( node != tail ) { |
---|
109 | Per_CPU_Control *cpu_self; |
---|
110 | |
---|
111 | cpu_self = _Thread_Dispatch_disable_critical( |
---|
112 | &queue_context->Lock_context |
---|
113 | ); |
---|
114 | _Thread_queue_Queue_release( queue, &queue_context->Lock_context ); |
---|
115 | |
---|
116 | do { |
---|
117 | Thread_Control *the_thread; |
---|
118 | Chain_Node *next; |
---|
119 | |
---|
120 | next = _Chain_Next( node ); |
---|
121 | the_thread = THREAD_CHAIN_NODE_TO_THREAD( node ); |
---|
122 | _Thread_Remove_timer_and_unblock( the_thread, queue ); |
---|
123 | |
---|
124 | node = next; |
---|
125 | } while ( node != tail ); |
---|
126 | |
---|
127 | _Thread_Dispatch_enable( cpu_self ); |
---|
128 | } else { |
---|
129 | _Thread_queue_Queue_release( queue, &queue_context->Lock_context ); |
---|
130 | } |
---|
131 | |
---|
132 | return flushed; |
---|
133 | } |
---|