source: rtems/cpukit/rtems/src/tasksetpriority.c @ 4d76300a

5
Last change on this file since 4d76300a was 4d76300a, checked in by Sebastian Huber <sebastian.huber@…>, on 05/11/16 at 08:21:57

rtems: Avoid Giant lock for some task operations

Avoid Giant lock for rtems_task_set_priority(), rtems_task_suspend() and
rtems_task_resume().

Update #2555.

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief RTEMS Set Task Priority
5 *  @ingroup ClassicTasks
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2014.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/rtems/tasksimpl.h>
22#include <rtems/score/threadimpl.h>
23
24rtems_status_code rtems_task_set_priority(
25  rtems_id             id,
26  rtems_task_priority  new_priority,
27  rtems_task_priority *old_priority
28)
29{
30  Thread_Control   *the_thread;
31  ISR_lock_Context  lock_context;
32  Per_CPU_Control  *cpu_self;
33
34  if ( new_priority != RTEMS_CURRENT_PRIORITY &&
35       !_RTEMS_tasks_Priority_is_valid( new_priority ) )
36    return RTEMS_INVALID_PRIORITY;
37
38  if ( !old_priority )
39    return RTEMS_INVALID_ADDRESS;
40
41  the_thread = _Thread_Get_interrupt_disable( id, &lock_context );
42
43  if ( the_thread == NULL ) {
44#if defined(RTEMS_MULTIPROCESSING)
45    return _RTEMS_tasks_MP_Set_priority( id, new_priority, old_priority );
46#else
47    return RTEMS_INVALID_ID;
48#endif
49  }
50
51  cpu_self = _Thread_Dispatch_disable_critical( &lock_context );
52  _ISR_lock_ISR_enable( &lock_context );
53
54  if ( new_priority != RTEMS_CURRENT_PRIORITY ) {
55    _Thread_Set_priority(
56      the_thread,
57      _RTEMS_tasks_Priority_to_Core( new_priority ),
58      old_priority,
59      false
60    );
61    *old_priority = _RTEMS_tasks_Priority_from_Core( *old_priority );
62  } else {
63    *old_priority = _RTEMS_tasks_Priority_from_Core(
64      the_thread->current_priority
65    );
66  }
67
68  _Thread_Dispatch_enable( cpu_self );
69  return RTEMS_SUCCESSFUL;
70}
Note: See TracBrowser for help on using the repository browser.