source: rtems/cpukit/rtems/src/tasksetpriority.c @ 6c7caa1a

4.11
Last change on this file since 6c7caa1a was 6c7caa1a, checked in by Sebastian Huber <sebastian.huber@…>, on May 28, 2014 at 11:37:54 AM

score: Add and use _Thread_Owns_resources()

  • Property mode set to 100644
File size: 2.0 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  Objects_Locations        location;
32
33  if ( new_priority != RTEMS_CURRENT_PRIORITY &&
34       !_RTEMS_tasks_Priority_is_valid( new_priority ) )
35    return RTEMS_INVALID_PRIORITY;
36
37  if ( !old_priority )
38    return RTEMS_INVALID_ADDRESS;
39
40  the_thread = _Thread_Get( id, &location );
41  switch ( location ) {
42
43    case OBJECTS_LOCAL:
44      *old_priority = _RTEMS_tasks_Priority_from_Core(
45                        the_thread->current_priority
46                      );
47      if ( new_priority != RTEMS_CURRENT_PRIORITY ) {
48        the_thread->real_priority = _RTEMS_tasks_Priority_to_Core(
49                                      new_priority
50                                    );
51        if ( !_Thread_Owns_resources( the_thread ) ||
52             the_thread->current_priority > new_priority )
53          _Thread_Change_priority( the_thread, new_priority, false );
54      }
55      _Objects_Put( &the_thread->Object );
56      return RTEMS_SUCCESSFUL;
57
58#if defined(RTEMS_MULTIPROCESSING)
59    case OBJECTS_REMOTE:
60      _Thread_Executing->Wait.return_argument = old_priority;
61      return _RTEMS_tasks_MP_Send_request_packet(
62          RTEMS_TASKS_MP_SET_PRIORITY_REQUEST,
63          id,
64          new_priority,
65          0,          /* Not used */
66          0           /* Not used */
67      );
68#endif
69
70    case OBJECTS_ERROR:
71      break;
72  }
73
74  return RTEMS_INVALID_ID;
75}
Note: See TracBrowser for help on using the repository browser.