source: rtems/cpukit/score/src/threadqdequeuepriority.c @ 1d486eff

4.104.114.84.95
Last change on this file since 1d486eff was 3127180, checked in by Ralf Corsepius <ralf.corsepius@…>, on 03/29/04 at 12:51:43

2004-04-29 Ralf Corsepius <ralf_corsepius@…>

  • score/src/Unlimited.txt, score/src/chain.c, score/src/coremsg.c, score/src/coremsgbroadcast.c, score/src/coremsgclose.c, score/src/coremsgflush.c, score/src/coremsgflushsupp.c, score/src/coremsgseize.c, score/src/coremsgsubmit.c, score/src/coremutex.c, score/src/coremutexflush.c, score/src/coresem.c, score/src/coresemflush.c, score/src/coretod.c, score/src/coretodtickle.c, score/src/coretodtoseconds.c, score/src/coretodvalidate.c, score/src/heap.c, score/src/heapallocate.c, score/src/heapextend.c, score/src/heapfree.c, score/src/heapsizeofuserarea.c, score/src/interr.c, score/src/iterateoverthreads.c, score/src/mpci.c, score/src/object.c, score/src/objectallocate.c, score/src/objectallocatebyindex.c, score/src/objectclearname.c, score/src/objectcomparenameraw.c, score/src/objectcomparenamestring.c, score/src/objectcopynameraw.c, score/src/objectcopynamestring.c, score/src/objectextendinformation.c, score/src/objectfree.c, score/src/objectget.c, score/src/objectgetbyindex.c, score/src/objectgetisr.c, score/src/objectgetnoprotection.c, score/src/objectidtoname.c, score/src/objectinitializeinformation.c, score/src/objectmp.c, score/src/objectnametoid.c, score/src/objectshrinkinformation.c, score/src/thread.c, score/src/threadcreateidle.c, score/src/threadget.c, score/src/threadidlebody.c, score/src/threadinitialize.c, score/src/threadmp.c, score/src/threadq.c, score/src/threadqdequeuepriority.c, score/src/threadqenqueuepriority.c, score/src/threadqfirstpriority.c, score/src/threadqflush.c, score/src/threadreset.c, score/src/threadrestart.c, score/src/threadsettransient.c, score/src/threadstackallocate.c, score/src/threadstart.c, score/src/userext.c, score/src/watchdoginsert.c, score/src/wkspace.c: Convert to using c99 fixed size types.
  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 *  Thread Queue Handler
3 *
4 *
5 *  COPYRIGHT (c) 1989-1999.
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#include <rtems/system.h>
16#include <rtems/score/chain.h>
17#include <rtems/score/isr.h>
18#include <rtems/score/object.h>
19#include <rtems/score/states.h>
20#include <rtems/score/thread.h>
21#include <rtems/score/threadq.h>
22#include <rtems/score/tqdata.h>
23
24/*PAGE
25 *
26 *  _Thread_queue_Dequeue_priority
27 *
28 *  This routine removes a thread from the specified PRIORITY based
29 *  threadq, unblocks it, and cancels its timeout timer.
30 *
31 *  Input parameters:
32 *    the_thread_queue - pointer to thread queue
33 *
34 *  Output parameters:
35 *    returns - thread dequeued or NULL
36 *
37 *  INTERRUPT LATENCY:
38 *    only case
39 */
40
41Thread_Control *_Thread_queue_Dequeue_priority(
42  Thread_queue_Control *the_thread_queue
43)
44{
45  uint32_t        index;
46  ISR_Level       level;
47  Thread_Control *the_thread = NULL;  /* just to remove warnings */
48  Thread_Control *new_first_thread;
49  Chain_Node     *new_first_node;
50  Chain_Node     *new_second_node;
51  Chain_Node     *last_node;
52  Chain_Node     *next_node;
53  Chain_Node     *previous_node;
54
55  _ISR_Disable( level );
56  for( index=0 ;
57       index < TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS ;
58       index++ ) {
59    if ( !_Chain_Is_empty( &the_thread_queue->Queues.Priority[ index ] ) ) {
60      the_thread = (Thread_Control *)
61                    the_thread_queue->Queues.Priority[ index ].first;
62      goto dequeue;
63    }
64  }
65
66  switch ( the_thread_queue->sync_state ) {
67    case THREAD_QUEUE_SYNCHRONIZED:
68    case THREAD_QUEUE_SATISFIED:
69      _ISR_Enable( level );
70      return NULL;
71
72    case THREAD_QUEUE_NOTHING_HAPPENED:
73    case THREAD_QUEUE_TIMEOUT:
74      the_thread_queue->sync_state = THREAD_QUEUE_SATISFIED;
75      _ISR_Enable( level );
76      return _Thread_Executing;
77  }
78
79dequeue:
80  new_first_node   = the_thread->Wait.Block2n.first;
81  new_first_thread = (Thread_Control *) new_first_node;
82  next_node        = the_thread->Object.Node.next;
83  previous_node    = the_thread->Object.Node.previous;
84
85  if ( !_Chain_Is_empty( &the_thread->Wait.Block2n ) ) {
86    last_node       = the_thread->Wait.Block2n.last;
87    new_second_node = new_first_node->next;
88
89    previous_node->next      = new_first_node;
90    next_node->previous      = new_first_node;
91    new_first_node->next     = next_node;
92    new_first_node->previous = previous_node;
93
94    if ( !_Chain_Has_only_one_node( &the_thread->Wait.Block2n ) ) {
95                                                /* > two threads on 2-n */
96      new_second_node->previous =
97                _Chain_Head( &new_first_thread->Wait.Block2n );
98
99      new_first_thread->Wait.Block2n.first = new_second_node;
100      new_first_thread->Wait.Block2n.last  = last_node;
101
102      last_node->next = _Chain_Tail( &new_first_thread->Wait.Block2n );
103    }
104  } else {
105    previous_node->next = next_node;
106    next_node->previous = previous_node;
107  }
108
109  if ( !_Watchdog_Is_active( &the_thread->Timer ) ) {
110    _ISR_Enable( level );
111    _Thread_Unblock( the_thread );
112  } else {
113    _Watchdog_Deactivate( &the_thread->Timer );
114    _ISR_Enable( level );
115    (void) _Watchdog_Remove( &the_thread->Timer );
116    _Thread_Unblock( the_thread );
117  }
118
119#if defined(RTEMS_MULTIPROCESSING)
120  if ( !_Objects_Is_local_id( the_thread->Object.id ) )
121    _Thread_MP_Free_proxy( the_thread );
122#endif
123  return( the_thread );
124}
125
Note: See TracBrowser for help on using the repository browser.