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

4.104.115
Last change on this file since da42259 was 11c16a64, checked in by Joel Sherrill <joel.sherrill@…>, on 01/22/08 at 21:19:18

2008-01-22 Joel Sherrill <joel.sherrill@…>

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