source: rtems/cpukit/score/src/threadqdequeuepriority.c @ 7fa97181

Last change on this file since 7fa97181 was a6eef8b, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/03 at 18:52:48

2003-09-04 Joel Sherrill <joel@…>

  • apiext.c, chain.c, coremsg.c, coremsgbroadcast.c, coremsgclose.c, coremsgflush.c, coremsgflushsupp.c, coremsgflushwait.c, coremsginsert.c, coremsgseize.c, coremsgsubmit.c, coremutex.c, coremutexflush.c, coremutexseize.c, coremutexsurrender.c, coresem.c, coresemflush.c, coresemseize.c, coresemsurrender.c, coretod.c, coretodset.c, coretodtickle.c, coretodtoseconds.c, coretodvalidate.c, heap.c, heapallocate.c, heapextend.c, heapfree.c, heapgetinfo.c, heapsizeofuserarea.c, heapwalk.c, interr.c, isr.c, mpci.c, object.c, objectallocate.c, objectallocatebyindex.c, objectclearname.c, objectcomparenameraw.c, objectcomparenamestring.c, objectcopynameraw.c, objectcopynamestring.c, objectextendinformation.c, objectfree.c, objectget.c, objectgetbyindex.c, objectgetisr.c, objectgetnext.c, objectgetnoprotection.c, objectinitializeinformation.c, objectmp.c, objectnametoid.c, objectshrinkinformation.c, thread.c, threadchangepriority.c, threadclearstate.c, threadclose.c, threadcreateidle.c, threaddelayended.c, threaddispatch.c, threadevaluatemode.c, threadget.c, threadhandler.c, threadidlebody.c, threadinitialize.c, threadloadenv.c, threadmp.c, threadq.c, threadqdequeue.c, threadqdequeuefifo.c, threadqdequeuepriority.c, threadqenqueue.c, threadqenqueuefifo.c, threadqenqueuepriority.c, threadqextract.c, threadqextractfifo.c, threadqextractpriority.c, threadqextractwithproxy.c, threadqfirst.c, threadqfirstfifo.c, threadqfirstpriority.c, threadqflush.c, threadqtimeout.c, threadready.c, threadreset.c, threadresettimeslice.c, threadrestart.c, threadresume.c, threadrotatequeue.c, threadsetpriority.c, threadsetstate.c, threadsettransient.c, threadstackallocate.c, threadstackfree.c, threadstart.c, threadstartmultitasking.c, threadsuspend.c, threadtickletimeslice.c, threadyieldprocessor.c, userext.c, watchdog.c, watchdogadjust.c, watchdoginsert.c, watchdogremove.c, watchdogtickle.c, wkspace.c: URL for license changed.
  • 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  unsigned32      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.