source: rtems/cpukit/rtems/src/tasksetpriority.c @ 3be0c9a

4.115
Last change on this file since 3be0c9a was 3be0c9a, checked in by Sebastian Huber <sebastian.huber@…>, on 11/22/12 at 13:51:25

score: Add and use <rtems/score/userextimpl.h>

This file contains the parts of <rtems/score/userext.h> that are only
necessary for the RTEMS implementation.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 *  RTEMS Task Manager
3 *
4 *
5 *  COPYRIGHT (c) 1989-2007.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 */
12
13#if HAVE_CONFIG_H
14#include "config.h"
15#endif
16
17#include <rtems/system.h>
18#include <rtems/rtems/status.h>
19#include <rtems/rtems/support.h>
20#include <rtems/rtems/modes.h>
21#include <rtems/score/object.h>
22#include <rtems/score/stack.h>
23#include <rtems/score/states.h>
24#include <rtems/rtems/tasks.h>
25#include <rtems/score/thread.h>
26#include <rtems/score/threadq.h>
27#include <rtems/score/tod.h>
28#include <rtems/score/wkspace.h>
29#include <rtems/score/apiext.h>
30#include <rtems/score/sysstate.h>
31
32/*
33 *  rtems_task_set_priority
34 *
35 *  This directive changes the priority of the specified thread.
36 *  The specified thread can be any thread in the system including
37 *  the requesting thread.
38 *
39 *  Input parameters:
40 *    id           - thread id (0 indicates requesting thread)
41 *    new_priority - thread priority (0 indicates current priority)
42 *    old_priority - pointer to previous priority
43 *
44 *  Output parameters:
45 *    old_priority      - previous priority
46 *    RTEMS_SUCCESSFUL - if successful
47 *    error code        - if unsuccessful
48 */
49
50rtems_status_code rtems_task_set_priority(
51  rtems_id             id,
52  rtems_task_priority  new_priority,
53  rtems_task_priority *old_priority
54)
55{
56  register Thread_Control *the_thread;
57  Objects_Locations        location;
58
59  if ( new_priority != RTEMS_CURRENT_PRIORITY &&
60       !_RTEMS_tasks_Priority_is_valid( new_priority ) )
61    return RTEMS_INVALID_PRIORITY;
62
63  if ( !old_priority )
64    return RTEMS_INVALID_ADDRESS;
65
66  the_thread = _Thread_Get( id, &location );
67  switch ( location ) {
68
69    case OBJECTS_LOCAL:
70      /* XXX need helper to "convert" from core priority */
71      *old_priority = the_thread->current_priority;
72      if ( new_priority != RTEMS_CURRENT_PRIORITY ) {
73        the_thread->real_priority = new_priority;
74        if ( the_thread->resource_count == 0 ||
75             the_thread->current_priority > new_priority )
76          _Thread_Change_priority( the_thread, new_priority, false );
77      }
78      _Thread_Enable_dispatch();
79      return RTEMS_SUCCESSFUL;
80
81#if defined(RTEMS_MULTIPROCESSING)
82    case OBJECTS_REMOTE:
83      _Thread_Executing->Wait.return_argument = old_priority;
84      return _RTEMS_tasks_MP_Send_request_packet(
85          RTEMS_TASKS_MP_SET_PRIORITY_REQUEST,
86          id,
87          new_priority,
88          0,          /* Not used */
89          0           /* Not used */
90      );
91#endif
92
93    case OBJECTS_ERROR:
94      break;
95  }
96
97  return RTEMS_INVALID_ID;
98}
Note: See TracBrowser for help on using the repository browser.