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

4.115
Last change on this file since f39f667a was f39f667a, checked in by Sebastian Huber <sebastian.huber@…>, on 05/14/14 at 11:50:48

score: Simplify _Thread_Change_priority()

The function to change a thread priority was too complex. Simplify it
with a new scheduler operation. This increases the average case
performance due to the simplified logic. The interrupt disabled
critical section is a bit prolonged since now the extract, update and
enqueue steps are executed atomically. This should however not impact
the worst-case interrupt latency since at least for the Deterministic
Priority Scheduler this sequence can be carried out with a wee bit of
instructions and no loops.

Add _Scheduler_Change_priority() to replace the sequence of

  • _Thread_Set_transient(),
  • _Scheduler_Extract(),
  • _Scheduler_Enqueue(), and
  • _Scheduler_Enqueue_first().

Delete STATES_TRANSIENT, _States_Is_transient() and
_Thread_Set_transient() since this state is now superfluous.

With this change it is possible to get rid of the
SCHEDULER_SMP_NODE_IN_THE_AIR state. This considerably simplifies the
implementation of the new SMP locking protocols.

  • Property mode set to 100644
File size: 1.6 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  /*
33   *  Do not bother recomputing all the priority related information if
34   *  we are not REALLY changing priority.
35   */
36  if ( the_thread->current_priority != new_priority ) {
37    ISR_Level                level;
38    const Scheduler_Control *scheduler;
39
40    _ISR_Disable( level );
41
42    scheduler = _Scheduler_Get( the_thread );
43    the_thread->current_priority = new_priority;
44
45    if ( _States_Is_ready( the_thread->current_state ) ) {
46      _Scheduler_Change_priority(
47        scheduler,
48        the_thread,
49        new_priority,
50        prepend_it
51      );
52
53      _ISR_Flash( level );
54
55      /*
56       *  We altered the set of thread priorities.  So let's figure out
57       *  who is the heir and if we need to switch to them.
58       */
59      scheduler = _Scheduler_Get( the_thread );
60      _Scheduler_Schedule( scheduler, the_thread );
61    } else {
62      _Scheduler_Update( scheduler, the_thread );
63    }
64    _ISR_Enable( level );
65
66    _Thread_queue_Requeue( the_thread->Wait.queue, the_thread );
67  }
68}
Note: See TracBrowser for help on using the repository browser.