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

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.9 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.org/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/score/threadimpl.h>
23#include <rtems/score/schedulerimpl.h>
24#include <rtems/score/threadqimpl.h>
25
26void _Thread_Change_priority(
27  Thread_Control   *the_thread,
28  Priority_Control  new_priority,
29  bool              prepend_it
30)
31{
32  ISR_Level      level;
33  States_Control state, original_state;
34
35  /*
36   * Save original state
37   */
38  original_state = the_thread->current_state;
39
40  /*
41   * Set a transient state for the thread so it is pulled off the Ready chains.
42   * This will prevent it from being scheduled no matter what happens in an
43   * ISR.
44   */
45  _Thread_Set_transient( the_thread );
46
47  /*
48   *  Do not bother recomputing all the priority related information if
49   *  we are not REALLY changing priority.
50   */
51 if ( the_thread->current_priority != new_priority )
52    _Thread_Set_priority( the_thread, new_priority );
53
54  _ISR_Disable( level );
55
56  /*
57   *  If the thread has more than STATES_TRANSIENT set, then it is blocked,
58   *  If it is blocked on a thread queue, then we need to requeue it.
59   */
60  state = the_thread->current_state;
61  if ( state != STATES_TRANSIENT ) {
62    /* Only clear the transient state if it wasn't set already */
63    if ( ! _States_Is_transient( original_state ) )
64      the_thread->current_state = _States_Clear( STATES_TRANSIENT, state );
65
66    /*
67     * The thread may have new blocking states added by interrupt service
68     * routines after the change into the transient state.  This will not
69     * result in a _Scheduler_Block() operation.  Make sure we select an heir
70     * now.
71     */
72    _Scheduler_Schedule( the_thread );
73
74    _ISR_Enable( level );
75    if ( _States_Is_waiting_on_thread_queue( state ) ) {
76      _Thread_queue_Requeue( the_thread->Wait.queue, the_thread );
77    }
78    return;
79  }
80
81  /* Only clear the transient state if it wasn't set already */
82  if ( ! _States_Is_transient( original_state ) ) {
83    /*
84     *  Interrupts are STILL disabled.
85     *  We now know the thread will be in the READY state when we remove
86     *  the TRANSIENT state.  So we have to place it on the appropriate
87     *  Ready Queue with interrupts off.
88     */
89    the_thread->current_state = _States_Clear( STATES_TRANSIENT, state );
90
91    if ( prepend_it )
92      _Scheduler_Enqueue_first( the_thread );
93    else
94      _Scheduler_Enqueue( the_thread );
95  }
96
97  _ISR_Flash( level );
98
99  /*
100   *  We altered the set of thread priorities.  So let's figure out
101   *  who is the heir and if we need to switch to them.
102   */
103  _Scheduler_Schedule( the_thread );
104
105  _ISR_Enable( level );
106}
Note: See TracBrowser for help on using the repository browser.