source: rtems/cpukit/score/src/threadchangepriority.c @ 57947f1

4.115
Last change on this file since 57947f1 was 57947f1, checked in by Sebastian Huber <sebastian.huber@…>, on 03/23/15 at 14:05:32

score: Add thread lock

Update #2273.

  • Property mode set to 100644
File size: 1.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-2014.
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_lock_Context  lock_context;
33  ISR_lock_Control *lock;
34
35  lock = _Thread_Lock_acquire( the_thread, &lock_context );
36
37  /*
38   *  Do not bother recomputing all the priority related information if
39   *  we are not REALLY changing priority.
40   */
41  if ( the_thread->current_priority != new_priority ) {
42    uint32_t  my_generation;
43    ISR_Level level;
44
45    my_generation = the_thread->Priority.generation + 1;
46    the_thread->current_priority = new_priority;
47    the_thread->Priority.generation = my_generation;
48
49    (*the_thread->Priority.change_handler)(
50      the_thread,
51      new_priority,
52      the_thread->Priority.change_handler_context
53    );
54
55    _Thread_Lock_release( lock, &lock_context );
56
57    _ISR_Disable( level );
58
59    if ( the_thread->Priority.generation == my_generation ) {
60      if ( _States_Is_ready( the_thread->current_state ) ) {
61        _Scheduler_Change_priority(
62          the_thread,
63          new_priority,
64          prepend_it
65        );
66      } else {
67        _Scheduler_Update_priority( the_thread, new_priority );
68      }
69    }
70
71    _ISR_Enable( level );
72  } else {
73    _Thread_Lock_release( lock, &lock_context );
74  }
75}
Note: See TracBrowser for help on using the repository browser.