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
RevLine 
[1b475860]1/**
2 * @file
3 *
4 * @brief Changes the Priority of a Thread
[05df0a8]5 *
[1b475860]6 * @ingroup ScoreThread
7 */
8
9/*
[108c4b0]10 *  COPYRIGHT (c) 1989-2011.
[05df0a8]11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
[dcf3687]14 *  found in the file LICENSE in this distribution or at
[c499856]15 *  http://www.rtems.org/license/LICENSE.
[05df0a8]16 */
17
[a8eed23]18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
[5618c37a]22#include <rtems/score/threadimpl.h>
[c6e21ee1]23#include <rtems/score/schedulerimpl.h>
[a112364]24#include <rtems/score/threadqimpl.h>
[05df0a8]25
26void _Thread_Change_priority(
27  Thread_Control   *the_thread,
28  Priority_Control  new_priority,
[484a769]29  bool              prepend_it
[05df0a8]30)
31{
[96d0b64]32  /*
33   *  Do not bother recomputing all the priority related information if
34   *  we are not REALLY changing priority.
35   */
[f39f667a]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 );
[96d0b64]63    }
[f39f667a]64    _ISR_Enable( level );
[96d0b64]65
[f39f667a]66    _Thread_queue_Requeue( the_thread->Wait.queue, the_thread );
[d9aca5f5]67  }
[05df0a8]68}
Note: See TracBrowser for help on using the repository browser.