source: rtems/cpukit/score/src/threadqdequeuepriority.c @ dfbfa2b0

4.104.114.84.95
Last change on this file since dfbfa2b0 was dfbfa2b0, checked in by Joel Sherrill <joel.sherrill@…>, on 11/02/99 at 20:36:11

Split threadq.c into multiple files.

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[dfbfa2b0]1/*
2 *  Thread Queue Handler
3 *
4 *
5 *  COPYRIGHT (c) 1989-1998.
6 *  On-Line Applications Research Corporation (OAR).
7 *  Copyright assigned to U.S. Government, 1994.
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.OARcorp.com/rtems/license.html.
12 *
13 *  $Id$
14 */
15
16#include <rtems/system.h>
17#include <rtems/score/chain.h>
18#include <rtems/score/isr.h>
19#include <rtems/score/object.h>
20#include <rtems/score/states.h>
21#include <rtems/score/thread.h>
22#include <rtems/score/threadq.h>
23#include <rtems/score/tqdata.h>
24
25/*PAGE
26 *
27 *  _Thread_queue_Dequeue_priority
28 *
29 *  This routine removes a thread from the specified PRIORITY based
30 *  threadq, unblocks it, and cancels its timeout timer.
31 *
32 *  Input parameters:
33 *    the_thread_queue - pointer to thread queue
34 *
35 *  Output parameters:
36 *    returns - thread dequeued or NULL
37 *
38 *  INTERRUPT LATENCY:
39 *    only case
40 */
41
42Thread_Control *_Thread_queue_Dequeue_priority(
43  Thread_queue_Control *the_thread_queue
44)
45{
46  unsigned32      index;
47  ISR_Level       level;
48  Thread_Control *the_thread = NULL;  /* just to remove warnings */
49  Thread_Control *new_first_thread;
50  Chain_Node     *new_first_node;
51  Chain_Node     *new_second_node;
52  Chain_Node     *last_node;
53  Chain_Node     *next_node;
54  Chain_Node     *previous_node;
55
56  _ISR_Disable( level );
57  for( index=0 ;
58       index < TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS ;
59       index++ ) {
60    if ( !_Chain_Is_empty( &the_thread_queue->Queues.Priority[ index ] ) ) {
61      the_thread = (Thread_Control *)
62                    the_thread_queue->Queues.Priority[ index ].first;
63      goto dequeue;
64    }
65  }
66
67  switch ( the_thread_queue->sync_state ) {
68    case THREAD_QUEUE_SYNCHRONIZED:
69    case THREAD_QUEUE_SATISFIED:
70      _ISR_Enable( level );
71      return NULL;
72
73    case THREAD_QUEUE_NOTHING_HAPPENED:
74    case THREAD_QUEUE_TIMEOUT:
75      the_thread_queue->sync_state = THREAD_QUEUE_SATISFIED;
76      _ISR_Enable( level );
77      return _Thread_Executing;
78  }
79
80dequeue:
81  new_first_node   = the_thread->Wait.Block2n.first;
82  new_first_thread = (Thread_Control *) new_first_node;
83  next_node        = the_thread->Object.Node.next;
84  previous_node    = the_thread->Object.Node.previous;
85
86  if ( !_Chain_Is_empty( &the_thread->Wait.Block2n ) ) {
87    last_node       = the_thread->Wait.Block2n.last;
88    new_second_node = new_first_node->next;
89
90    previous_node->next      = new_first_node;
91    next_node->previous      = new_first_node;
92    new_first_node->next     = next_node;
93    new_first_node->previous = previous_node;
94
95    if ( !_Chain_Has_only_one_node( &the_thread->Wait.Block2n ) ) {
96                                                /* > two threads on 2-n */
97      new_second_node->previous =
98                _Chain_Head( &new_first_thread->Wait.Block2n );
99
100      new_first_thread->Wait.Block2n.first = new_second_node;
101      new_first_thread->Wait.Block2n.last  = last_node;
102
103      last_node->next = _Chain_Tail( &new_first_thread->Wait.Block2n );
104    }
105  } else {
106    previous_node->next = next_node;
107    next_node->previous = previous_node;
108  }
109
110  if ( !_Watchdog_Is_active( &the_thread->Timer ) ) {
111    _ISR_Enable( level );
112    _Thread_Unblock( the_thread );
113  } else {
114    _Watchdog_Deactivate( &the_thread->Timer );
115    _ISR_Enable( level );
116    (void) _Watchdog_Remove( &the_thread->Timer );
117    _Thread_Unblock( the_thread );
118  }
119
120#if defined(RTEMS_MULTIPROCESSING)
121  if ( !_Objects_Is_local_id( the_thread->Object.id ) )
122    _Thread_MP_Free_proxy( the_thread );
123#endif
124  return( the_thread );
125}
126
Note: See TracBrowser for help on using the repository browser.