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

4.115
Last change on this file since d7c3883 was ce002b16, checked in by Sebastian Huber <sebastian.huber@…>, on 11/25/10 at 09:27:06

2010-11-25 Sebastian Huber <sebastian.huber@…>

  • libfs/src/dosfs/fat_file.c, libfs/src/imfs/imfs_debug.c, libfs/src/imfs/imfs_directory.c, libfs/src/imfs/imfs_getchild.c, posix/src/killinfo.c, score/inline/rtems/score/schedulerpriority.inl, score/inline/rtems/score/watchdog.inl, score/src/apiext.c, score/src/chain.c, score/src/coremsgflushsupp.c, score/src/coremsginsert.c, score/src/objectshrinkinformation.c, score/src/schedulerpriorityyield.c, score/src/threadqdequeuepriority.c, score/src/threadqenqueuepriority.c, score/src/threadqextractpriority.c, score/src/threadqfirstfifo.c, score/src/threadqfirstpriority.c, score/src/threadyieldprocessor.c, score/src/userextthreadbegin.c, score/src/userextthreadcreate.c, score/src/userextthreaddelete.c, score/src/userextthreadrestart.c, score/src/userextthreadstart.c, score/src/userextthreadswitch.c, score/src/watchdogreportchain.c: Avoid chain API violations.
  • 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     *head;
54  Chain_Node     *tail;
55  Chain_Node     *new_first_node;
56  Chain_Node     *new_second_node;
57  Chain_Node     *last_node;
58  Chain_Node     *next_node;
59  Chain_Node     *previous_node;
60
61  _ISR_Disable( level );
62  for( index=0 ;
63       index < TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS ;
64       index++ ) {
65    if ( !_Chain_Is_empty( &the_thread_queue->Queues.Priority[ index ] ) ) {
66      the_thread = (Thread_Control *) _Chain_First(
67        &the_thread_queue->Queues.Priority[ index ]
68      );
69      goto dequeue;
70    }
71  }
72
73  /*
74   * We did not find a thread to unblock.
75   */
76  _ISR_Enable( level );
77  return NULL;
78
79dequeue:
80  the_thread->Wait.queue = NULL;
81  new_first_node   = _Chain_First( &the_thread->Wait.Block2n );
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       = _Chain_Last( &the_thread->Wait.Block2n );
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      head = _Chain_Head( &new_first_thread->Wait.Block2n );
98      tail = _Chain_Tail( &new_first_thread->Wait.Block2n );
99
100      new_second_node->previous = head;
101      head->next = new_second_node;
102      tail->previous = last_node;
103      last_node->next = tail;
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}
Note: See TracBrowser for help on using the repository browser.