source: rtems/cpukit/score/src/threadchangepriority.c @ 4fc370e

4.115
Last change on this file since 4fc370e was 1b475860, checked in by Christopher Kerl <zargyyoyo@…>, on 11/29/12 at 19:39:17

score misc: Score misc: Clean up Doxygen #6 (GCI 2012)

This patch is a task from GCI 2012 which improves the Doxygen
comments in the RTEMS source.

http://www.google-melange.com/gci/task/view/google/gci2012/7976215

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