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

4.115
Last change on this file since e6f7f81 was 4b48ece0, checked in by Sebastian Huber <sebastian.huber@…>, on 07/22/13 at 08:21:03

score: Create watchdog implementation header

Move implementation specific parts of watchdog.h and watchdog.inl into
new header file watchdogimpl.h. The watchdog.h contains now only the
application visible API.

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