source: rtems/cpukit/score/src/threadchangepriority.c @ c6e21ee1

4.115
Last change on this file since c6e21ee1 was c6e21ee1, checked in by Sebastian Huber <sebastian.huber@…>, on 07/24/13 at 11:12:38

score: Create scheduler implementation header

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

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/**
2 * @file
3 *
4 * @brief Changes the Priority of a Thread
5 *
6 * @ingroup ScoreThread
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2011.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.com/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/score/thread.h>
23#include <rtems/score/isr.h>
24#include <rtems/score/schedulerimpl.h>
25#include <rtems/score/threadq.h>
26
27void _Thread_Change_priority(
28  Thread_Control   *the_thread,
29  Priority_Control  new_priority,
30  bool              prepend_it
31)
32{
33  ISR_Level      level;
34  States_Control state, original_state;
35
36  /*
37   * Save original state
38   */
39  original_state = the_thread->current_state;
40
41  /*
42   * Set a transient state for the thread so it is pulled off the Ready chains.
43   * This will prevent it from being scheduled no matter what happens in an
44   * ISR.
45   */
46  _Thread_Set_transient( the_thread );
47
48  /*
49   *  Do not bother recomputing all the priority related information if
50   *  we are not REALLY changing priority.
51   */
52 if ( the_thread->current_priority != new_priority )
53    _Thread_Set_priority( the_thread, new_priority );
54
55  _ISR_Disable( level );
56
57  /*
58   *  If the thread has more than STATES_TRANSIENT set, then it is blocked,
59   *  If it is blocked on a thread queue, then we need to requeue it.
60   */
61  state = the_thread->current_state;
62  if ( state != STATES_TRANSIENT ) {
63    /* Only clear the transient state if it wasn't set already */
64    if ( ! _States_Is_transient( original_state ) )
65      the_thread->current_state = _States_Clear( STATES_TRANSIENT, state );
66    _ISR_Enable( level );
67    if ( _States_Is_waiting_on_thread_queue( state ) ) {
68      _Thread_queue_Requeue( the_thread->Wait.queue, the_thread );
69    }
70    return;
71  }
72
73  /* Only clear the transient state if it wasn't set already */
74  if ( ! _States_Is_transient( original_state ) ) {
75    /*
76     *  Interrupts are STILL disabled.
77     *  We now know the thread will be in the READY state when we remove
78     *  the TRANSIENT state.  So we have to place it on the appropriate
79     *  Ready Queue with interrupts off.
80     */
81    the_thread->current_state = _States_Clear( STATES_TRANSIENT, state );
82
83    if ( prepend_it )
84      _Scheduler_Enqueue_first( the_thread );
85    else
86      _Scheduler_Enqueue( the_thread );
87  }
88
89  _ISR_Flash( level );
90
91  /*
92   *  We altered the set of thread priorities.  So let's figure out
93   *  who is the heir and if we need to switch to them.
94   */
95  _Scheduler_Schedule();
96
97  if ( !_Thread_Is_executing_also_the_heir() &&
98       _Thread_Executing->is_preemptible )
99    _Thread_Dispatch_necessary = true;
100  _ISR_Enable( level );
101}
Note: See TracBrowser for help on using the repository browser.