source: rtems/cpukit/score/src/threadqextractpriority.c @ 215ccce

4.11
Last change on this file since 215ccce was 215ccce, checked in by Sebastian Huber <sebastian.huber@…>, on Aug 23, 2013 at 9:52:01 AM

score: PR2140: _Thread_queue_Extract()

Return if the executing context performed the extract operation since
interrupts may interfere.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/**
2 * @file
3 *
4 * @brief Thread queue Extract priority Helper
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/score/threadqimpl.h>
22#include <rtems/score/chainimpl.h>
23#include <rtems/score/isrlevel.h>
24#include <rtems/score/threadimpl.h>
25#include <rtems/score/watchdogimpl.h>
26
27bool _Thread_queue_Extract_priority_helper(
28  Thread_queue_Control *the_thread_queue __attribute__((unused)),
29  Thread_Control       *the_thread,
30  bool                  requeuing
31)
32{
33  ISR_Level       level;
34  Chain_Node     *head;
35  Chain_Node     *tail;
36  Chain_Node     *the_node;
37  Chain_Node     *next_node;
38  Chain_Node     *previous_node;
39  Thread_Control *new_first_thread;
40  Chain_Node     *new_first_node;
41  Chain_Node     *new_second_node;
42  Chain_Node     *last_node;
43
44  the_node = (Chain_Node *) the_thread;
45  _ISR_Disable( level );
46  if ( !_States_Is_waiting_on_thread_queue( the_thread->current_state ) ) {
47    _ISR_Enable( level );
48    return false;
49  }
50
51  /*
52   *  The thread was actually waiting on a thread queue so let's remove it.
53   */
54
55  next_node     = the_node->next;
56  previous_node = the_node->previous;
57
58  if ( !_Chain_Is_empty( &the_thread->Wait.Block2n ) ) {
59    new_first_node   = _Chain_First( &the_thread->Wait.Block2n );
60    new_first_thread = (Thread_Control *) new_first_node;
61    last_node        = _Chain_Last( &the_thread->Wait.Block2n );
62    new_second_node  = new_first_node->next;
63
64    previous_node->next      = new_first_node;
65    next_node->previous      = new_first_node;
66    new_first_node->next     = next_node;
67    new_first_node->previous = previous_node;
68
69    if ( !_Chain_Has_only_one_node( &the_thread->Wait.Block2n ) ) {
70                                        /* > two threads on 2-n */
71      head = _Chain_Head( &new_first_thread->Wait.Block2n );
72      tail = _Chain_Tail( &new_first_thread->Wait.Block2n );
73
74      new_second_node->previous = head;
75      head->next = new_second_node;
76      tail->previous = last_node;
77      last_node->next = tail;
78    }
79  } else {
80    previous_node->next = next_node;
81    next_node->previous = previous_node;
82  }
83
84  /*
85   *  If we are not supposed to touch timers or the thread's state, return.
86   */
87
88  if ( requeuing ) {
89    _ISR_Enable( level );
90    return true;
91  }
92
93  if ( !_Watchdog_Is_active( &the_thread->Timer ) ) {
94    _ISR_Enable( level );
95  } else {
96    _Watchdog_Deactivate( &the_thread->Timer );
97    _ISR_Enable( level );
98    (void) _Watchdog_Remove( &the_thread->Timer );
99  }
100  _Thread_Unblock( the_thread );
101
102#if defined(RTEMS_MULTIPROCESSING)
103  if ( !_Objects_Is_local_id( the_thread->Object.id ) )
104    _Thread_MP_Free_proxy( the_thread );
105#endif
106
107  return true;
108}
Note: See TracBrowser for help on using the repository browser.