RTEMS
threadqflush.c
Go to the documentation of this file.
1 
9 /*
10  * COPYRIGHT (c) 1989-2008.
11  * On-Line Applications Research Corporation (OAR).
12  *
13  * The license and distribution terms for this file may be
14  * found in the file LICENSE in this distribution or at
15  * http://www.rtems.org/license/LICENSE.
16  */
17 
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21 
22 #include <rtems/score/threadimpl.h>
24 #include <rtems/score/status.h>
25 
27  Thread_Control *the_thread,
28  Thread_queue_Queue *queue,
29  Thread_queue_Context *queue_context
30 )
31 {
32  (void) queue;
33  (void) queue_context;
34  return the_thread;
35 }
36 
38  Thread_Control *the_thread,
39  Thread_queue_Queue *queue,
40  Thread_queue_Context *queue_context
41 )
42 {
43  the_thread->Wait.return_code = STATUS_OBJECT_WAS_DELETED;
44 
45  (void) queue;
46  (void) queue_context;
47  return the_thread;
48 }
49 
51  Thread_Control *the_thread,
52  Thread_queue_Queue *queue,
53  Thread_queue_Context *queue_context
54 )
55 {
56  the_thread->Wait.return_code = STATUS_UNAVAILABLE;
57 
58  (void) queue;
59  (void) queue_context;
60  return the_thread;
61 }
62 
64  Thread_queue_Queue *queue,
65  const Thread_queue_Operations *operations,
67  Thread_queue_Context *queue_context
68 )
69 {
70  size_t flushed;
71  Chain_Control unblock;
72  Thread_Control *owner;
73  Chain_Node *node;
74  Chain_Node *tail;
75 
76  flushed = 0;
77  _Chain_Initialize_empty( &unblock );
78  owner = queue->owner;
79 
80  while ( true ) {
81  Thread_queue_Heads *heads;
82  Thread_Control *first;
83  bool do_unblock;
84 
85  heads = queue->heads;
86  if ( heads == NULL ) {
87  break;
88  }
89 
90  first = ( *operations->first )( heads );
91  first = ( *filter )( first, queue, queue_context );
92  if ( first == NULL ) {
93  break;
94  }
95 
96  /*
97  * We do not have enough space in the queue context to collect all priority
98  * updates, so clear it each time. We unconditionally do the priority
99  * update for the owner later if it exists.
100  */
102 
103  do_unblock = _Thread_queue_Extract_locked(
104  queue,
105  operations,
106  first,
107  queue_context
108  );
109  if ( do_unblock ) {
110  Scheduler_Node *scheduler_node;
111 
112  scheduler_node = _Thread_Scheduler_get_home_node( first );
114  &unblock,
115  &scheduler_node->Wait.Priority.Node.Node.Chain
116  );
117  }
118 
119  ++flushed;
120  }
121 
122  node = _Chain_First( &unblock );
123  tail = _Chain_Tail( &unblock );
124 
125  if ( node != tail ) {
126  Per_CPU_Control *cpu_self;
127 
128  cpu_self = _Thread_queue_Dispatch_disable( queue_context );
129  _Thread_queue_Queue_release( queue, &queue_context->Lock_context.Lock_context );
130 
131  do {
132  Scheduler_Node *scheduler_node;
133  Thread_Control *the_thread;
134  Chain_Node *next;
135 
136  next = _Chain_Next( node );
137  scheduler_node = SCHEDULER_NODE_OF_WAIT_PRIORITY_NODE( node );
138  the_thread = _Scheduler_Node_get_owner( scheduler_node );
139  _Thread_Remove_timer_and_unblock( the_thread, queue );
140 
141  node = next;
142  } while ( node != tail );
143 
144  if ( owner != NULL ) {
145  ISR_lock_Context lock_context;
146 
147  _Thread_State_acquire( owner, &lock_context );
149  _Thread_State_release( owner, &lock_context );
150  }
151 
152  _Thread_Dispatch_enable( cpu_self );
153  } else {
154  _Thread_queue_Queue_release( queue, &queue_context->Lock_context.Lock_context );
155  }
156 
157  return flushed;
158 }
Thread_Control * owner
The thread queue owner.
Definition: threadq.h:431
static __inline__ Chain_Node * _Chain_First(const Chain_Control *the_chain)
Returns pointer to chain&#39;s first node.
Definition: chainimpl.h:260
static __inline__ Per_CPU_Control * _Thread_queue_Dispatch_disable(Thread_queue_Context *queue_context)
Disables dispatching in a critical section.
Definition: threadqimpl.h:429
bool _Thread_queue_Extract_locked(Thread_queue_Queue *queue, const Thread_queue_Operations *operations, Thread_Control *the_thread, Thread_queue_Context *queue_context)
Extracts the thread from the thread queue, restores the default wait operations and restores the defa...
Thread_Wait_information Wait
Definition: thread.h:767
Thread queue context for the thread queue methods.
Definition: threadq.h:198
Inlined Routines Associated with the Manipulation of the Scheduler.
uint32_t return_code
Definition: thread.h:413
Thread_Control * _Thread_queue_Flush_status_unavailable(Thread_Control *the_thread, Thread_queue_Queue *queue, Thread_queue_Context *queue_context)
Status unavailable thread queue flush filter function.
Definition: threadqflush.c:50
Thread_queue_First_operation first
Thread queue first operation.
Definition: threadq.h:545
static __inline__ void _Thread_State_release(Thread_Control *the_thread, ISR_lock_Context *lock_context)
Releases the lock context and enables interrupts.
Definition: threadimpl.h:592
Thread queue operations.
Definition: threadq.h:517
Thread_Control * _Thread_queue_Flush_default_filter(Thread_Control *the_thread, Thread_queue_Queue *queue, Thread_queue_Context *queue_context)
Default thread queue flush filter function.
Definition: threadqflush.c:26
Thread_Control *(* Thread_queue_Flush_filter)(Thread_Control *the_thread, Thread_queue_Queue *queue, Thread_queue_Context *queue_context)
Thread queue flush filter function.
Definition: threadqimpl.h:1223
Thread_queue_Heads * heads
The thread queue heads.
Definition: threadq.h:426
Thread queue heads.
Definition: threadq.h:360
static __inline__ void _Chain_Append_unprotected(Chain_Control *the_chain, Chain_Node *the_node)
Appends a node (unprotected).
Definition: chainimpl.h:680
size_t _Thread_queue_Flush_critical(Thread_queue_Queue *queue, const Thread_queue_Operations *operations, Thread_queue_Flush_filter filter, Thread_queue_Context *queue_context)
Unblocks all threads enqueued on the thread queue.
Definition: threadqflush.c:63
Per CPU Core Structure.
Definition: percpu.h:347
static __inline__ Scheduler_Node * _Thread_Scheduler_get_home_node(const Thread_Control *the_thread)
Gets the scheduler&#39;s home node.
Definition: threadimpl.h:1438
static __inline__ Chain_Node * _Chain_Next(const Chain_Node *the_node)
Returns pointer to the next node from this node.
Definition: chainimpl.h:327
Thread_queue_Lock_context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:203
static __inline__ Thread_Control * _Scheduler_Node_get_owner(const Scheduler_Node *node)
Gets the owner of the node.
Thread_Control * _Thread_queue_Flush_status_object_was_deleted(Thread_Control *the_thread, Thread_queue_Queue *queue, Thread_queue_Context *queue_context)
Status object was deleted thread queue flush filter function.
Definition: threadqflush.c:37
void _Thread_Dispatch_enable(Per_CPU_Control *cpu_self)
Enables thread dispatching.
static __inline__ void _Thread_queue_Context_clear_priority_updates(Thread_queue_Context *queue_context)
Clears the priority update count of the thread queue context.
Definition: threadqimpl.h:338
Priority_Node Node
This priority node reflects the overall priority of the aggregation.
Definition: priority.h:147
static __inline__ void _Thread_Remove_timer_and_unblock(Thread_Control *the_thread, Thread_queue_Queue *queue)
Remove the watchdog timer from the thread and unblock if necessary.
Definition: threadimpl.h:2482
static __inline__ void _Thread_queue_Queue_release(Thread_queue_Queue *queue, ISR_lock_Context *lock_context)
Releases the thread queue queue and enables interrupts.
Definition: threadqimpl.h:625
struct Scheduler_Node::@20 Wait
Thread wait support block.
static __inline__ void _Scheduler_Update_priority(Thread_Control *the_thread)
Propagates a priority change of a thread to the scheduler.
static __inline__ void _Chain_Initialize_empty(Chain_Control *the_chain)
Initializes this chain as empty.
Definition: chainimpl.h:505
Scheduler node for per-thread data.
Definition: schedulernode.h:79
Inlined Routines from the Thread Handler.
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
ISR_lock_Context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:130
union Priority_Node::@16 Node
Node component for a chain or red-black tree.
static __inline__ void _Thread_State_acquire(Thread_Control *the_thread, ISR_lock_Context *lock_context)
Disables interrupts and acquires the lock_context.
Definition: threadimpl.h:542
static __inline__ Chain_Node * _Chain_Tail(Chain_Control *the_chain)
Returns pointer to chain tail.
Definition: chainimpl.h:227