source: rtems/cpukit/score/src/threadqflush.c @ dce48791

5
Last change on this file since dce48791 was dce48791, checked in by Sebastian Huber <sebastian.huber@…>, on 05/23/16 at 11:37:59

score: Add Status_Control for all APIs

Unify the status codes of the Classic and POSIX API to use the new enum
Status_Control. This eliminates the Thread_Control::Wait::timeout_code
field and the timeout parameter of _Thread_queue_Enqueue_critical() and
_MPCI_Send_request_packet(). It gets rid of the status code translation
tables and instead uses simple bit operations to get the status for a
particular API. This enables translation of status code constants at
compile time. Add _Thread_Wait_get_status() to avoid direct access of
thread internal data structures.

  • Property mode set to 100644
File size: 2.8 KB
Line 
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
24Thread_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
35Thread_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
48Thread_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
61size_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}
Note: See TracBrowser for help on using the repository browser.