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

4.115
Last change on this file since bf54252 was bf54252, checked in by Alexandre Devienne <deviennealexandre@…>, on 11/28/12 at 20:14:50

Score misc: Clean up Doxygen #4 (GCI 2012)

This patch is a task from GCI 2012 which improves the Doxygen
comments in the RTEMS source.

http://www.google-melange.com/gci/task/view/google/gci2012/7985215

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/**
2 * @file
3 *
4 * @brief  Thread Queue Dequeue Priority
5 * @ingroup ScoreThreadQ
6
7/*
8 *  COPYRIGHT (c) 1989-2008.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 */
15
16#if HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#include <rtems/system.h>
21#include <rtems/score/chain.h>
22#include <rtems/score/isr.h>
23#include <rtems/score/object.h>
24#include <rtems/score/states.h>
25#include <rtems/score/thread.h>
26#include <rtems/score/threadq.h>
27#include <rtems/score/tqdata.h>
28
29Thread_Control *_Thread_queue_Dequeue_priority(
30  Thread_queue_Control *the_thread_queue
31)
32{
33  uint32_t        index;
34  ISR_Level       level;
35  Thread_Control *the_thread = NULL;  /* just to remove warnings */
36  Thread_Control *new_first_thread;
37  Chain_Node     *head;
38  Chain_Node     *tail;
39  Chain_Node     *new_first_node;
40  Chain_Node     *new_second_node;
41  Chain_Node     *last_node;
42  Chain_Node     *next_node;
43  Chain_Node     *previous_node;
44
45  _ISR_Disable( level );
46  for( index=0 ;
47       index < TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS ;
48       index++ ) {
49    if ( !_Chain_Is_empty( &the_thread_queue->Queues.Priority[ index ] ) ) {
50      the_thread = (Thread_Control *) _Chain_First(
51        &the_thread_queue->Queues.Priority[ index ]
52      );
53      goto dequeue;
54    }
55  }
56
57  /*
58   * We did not find a thread to unblock.
59   */
60  _ISR_Enable( level );
61  return NULL;
62
63dequeue:
64  the_thread->Wait.queue = NULL;
65  new_first_node   = _Chain_First( &the_thread->Wait.Block2n );
66  new_first_thread = (Thread_Control *) new_first_node;
67  next_node        = the_thread->Object.Node.next;
68  previous_node    = the_thread->Object.Node.previous;
69
70  if ( !_Chain_Is_empty( &the_thread->Wait.Block2n ) ) {
71    last_node       = _Chain_Last( &the_thread->Wait.Block2n );
72    new_second_node = new_first_node->next;
73
74    previous_node->next      = new_first_node;
75    next_node->previous      = new_first_node;
76    new_first_node->next     = next_node;
77    new_first_node->previous = previous_node;
78
79    if ( !_Chain_Has_only_one_node( &the_thread->Wait.Block2n ) ) {
80                                                /* > two threads on 2-n */
81      head = _Chain_Head( &new_first_thread->Wait.Block2n );
82      tail = _Chain_Tail( &new_first_thread->Wait.Block2n );
83
84      new_second_node->previous = head;
85      head->next = new_second_node;
86      tail->previous = last_node;
87      last_node->next = tail;
88    }
89  } else {
90    previous_node->next = next_node;
91    next_node->previous = previous_node;
92  }
93
94  if ( !_Watchdog_Is_active( &the_thread->Timer ) ) {
95    _ISR_Enable( level );
96    _Thread_Unblock( the_thread );
97  } else {
98    _Watchdog_Deactivate( &the_thread->Timer );
99    _ISR_Enable( level );
100    (void) _Watchdog_Remove( &the_thread->Timer );
101    _Thread_Unblock( the_thread );
102  }
103
104#if defined(RTEMS_MULTIPROCESSING)
105  if ( !_Objects_Is_local_id( the_thread->Object.id ) )
106    _Thread_MP_Free_proxy( the_thread );
107#endif
108  return( the_thread );
109}
Note: See TracBrowser for help on using the repository browser.