source: rtems/cpukit/score/src/threadqextractpriority.c @ b50468c

4.10
Last change on this file since b50468c was b50468c, checked in by Gedare Bloom <gedare@…>, on Dec 21, 2017 at 6:04:50 PM

score: add Inherited_priorities priority queue and functions

Adds enqueue, dequeue, requeue, evaluate, and release functions
for the thread priority node priority queue of inherited priorities.
Add calls to these functions as needed to maintain the priority
queue due to blocking, unblocking, and priority changes.

Closes #3359.

  • Property mode set to 100644
File size: 3.5 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/coremutex.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
29/*PAGE
30 *
31 *  _Thread_queue_Extract_priority
32 *
33 *  This routine removes a specific thread from the specified threadq,
34 *  deletes any timeout, and unblocks the thread.
35 *
36 *  Input parameters:
37 *    the_thread_queue - pointer to a threadq header
38 *    the_thread       - pointer to a thread control block
39 *    requeuing        - true if requeuing and should not alter timeout or state
40 *
41 *  Output parameters: NONE
42 *
43 *  INTERRUPT LATENCY:
44 *    EXTRACT_PRIORITY
45 */
46
47bool _Thread_queue_Extract_priority_helper(
48  Thread_queue_Control *the_thread_queue __attribute__((unused)),
49  Thread_Control       *the_thread,
50  bool                  requeuing
51)
52{
53  ISR_Level       level;
54  Chain_Node     *the_node;
55  Chain_Node     *next_node;
56  Chain_Node     *previous_node;
57  Thread_Control *new_first_thread;
58  Chain_Node     *new_first_node;
59  Chain_Node     *new_second_node;
60  Chain_Node     *last_node;
61  CORE_mutex_Control *mutex;
62
63  the_node = (Chain_Node *) the_thread;
64  _ISR_Disable( level );
65  if ( !_States_Is_waiting_on_thread_queue( the_thread->current_state ) ) {
66    _ISR_Enable( level );
67    return false;
68  }
69
70  /*
71   *  The thread was actually waiting on a thread queue so let's remove it.
72   */
73
74  next_node     = the_node->next;
75  previous_node = the_node->previous;
76
77  if ( !_Chain_Is_empty( &the_thread->Wait.Block2n ) ) {
78    new_first_node   = the_thread->Wait.Block2n.first;
79    new_first_thread = (Thread_Control *) new_first_node;
80    last_node        = the_thread->Wait.Block2n.last;
81    new_second_node  = new_first_node->next;
82
83    previous_node->next      = new_first_node;
84    next_node->previous      = new_first_node;
85    new_first_node->next     = next_node;
86    new_first_node->previous = previous_node;
87
88    if ( !_Chain_Has_only_one_node( &the_thread->Wait.Block2n ) ) {
89                                        /* > two threads on 2-n */
90      new_second_node->previous =
91                _Chain_Head( &new_first_thread->Wait.Block2n );
92      new_first_thread->Wait.Block2n.first = new_second_node;
93
94      new_first_thread->Wait.Block2n.last = last_node;
95      last_node->next = _Chain_Tail( &new_first_thread->Wait.Block2n );
96    }
97  } else {
98    previous_node->next = next_node;
99    next_node->previous = previous_node;
100  }
101
102  /*
103   *  If we are not supposed to touch timers or the thread's state, return.
104   */
105
106  if ( requeuing ) {
107    _ISR_Enable( level );
108    return true;
109  }
110
111  mutex = _Thread_Dequeue_priority_node( &the_thread->Priority_node );
112  _Thread_Evaluate_priority( mutex->holder );
113
114  if ( !_Watchdog_Is_active( &the_thread->Timer ) ) {
115    _ISR_Enable( level );
116  } else {
117    _Watchdog_Deactivate( &the_thread->Timer );
118    _ISR_Enable( level );
119    (void) _Watchdog_Remove( &the_thread->Timer );
120  }
121  _Thread_Unblock( the_thread );
122
123#if defined(RTEMS_MULTIPROCESSING)
124  if ( !_Objects_Is_local_id( the_thread->Object.id ) )
125    _Thread_MP_Free_proxy( the_thread );
126#endif
127
128  return true;
129}
Note: See TracBrowser for help on using the repository browser.