source: rtems/cpukit/rtems/src/tasksetpriority.c @ eaef4657

4.104.11
Last change on this file since eaef4657 was eaef4657, checked in by Ralf Corsepius <ralf.corsepius@…>, on Jan 6, 2009 at 5:05:03 AM

Eliminate TRUE/FALSE.

  • 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 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/rtems/status.h>
21#include <rtems/rtems/support.h>
22#include <rtems/rtems/modes.h>
23#include <rtems/score/object.h>
24#include <rtems/score/stack.h>
25#include <rtems/score/states.h>
26#include <rtems/rtems/tasks.h>
27#include <rtems/score/thread.h>
28#include <rtems/score/threadq.h>
29#include <rtems/score/tod.h>
30#include <rtems/score/userext.h>
31#include <rtems/score/wkspace.h>
32#include <rtems/score/apiext.h>
33#include <rtems/score/sysstate.h>
34
35/*PAGE
36 *
37 *  rtems_task_set_priority
38 *
39 *  This directive changes the priority of the specified thread.
40 *  The specified thread can be any thread in the system including
41 *  the requesting thread.
42 *
43 *  Input parameters:
44 *    id           - thread id (0 indicates requesting thread)
45 *    new_priority - thread priority (0 indicates current priority)
46 *    old_priority - pointer to previous priority
47 *
48 *  Output parameters:
49 *    old_priority      - previous priority
50 *    RTEMS_SUCCESSFUL - if successful
51 *    error code        - if unsuccessful
52 */
53
54rtems_status_code rtems_task_set_priority(
55  Objects_Id           id,
56  rtems_task_priority  new_priority,
57  rtems_task_priority *old_priority
58)
59{
60  register Thread_Control *the_thread;
61  Objects_Locations               location;
62
63  if ( new_priority != RTEMS_CURRENT_PRIORITY &&
64       !_RTEMS_tasks_Priority_is_valid( new_priority ) )
65    return RTEMS_INVALID_PRIORITY;
66
67  if ( !old_priority )
68    return RTEMS_INVALID_ADDRESS;
69
70  the_thread = _Thread_Get( id, &location );
71  switch ( location ) {
72
73    case OBJECTS_LOCAL:
74      /* XXX need helper to "convert" from core priority */
75      *old_priority = the_thread->current_priority;
76      if ( new_priority != RTEMS_CURRENT_PRIORITY ) {
77        the_thread->real_priority = new_priority;
78        if ( the_thread->resource_count == 0 ||
79             the_thread->current_priority > new_priority )
80          _Thread_Change_priority( the_thread, new_priority, false );
81      }
82      _Thread_Enable_dispatch();
83      return RTEMS_SUCCESSFUL;
84
85#if defined(RTEMS_MULTIPROCESSING)
86    case OBJECTS_REMOTE:
87      _Thread_Executing->Wait.return_argument = old_priority;
88      return _RTEMS_tasks_MP_Send_request_packet(
89          RTEMS_TASKS_MP_SET_PRIORITY_REQUEST,
90          id,
91          new_priority,
92          0,          /* Not used */
93          0           /* Not used */
94      );
95#endif
96
97    case OBJECTS_ERROR:
98      break;
99  }
100
101  return RTEMS_INVALID_ID;
102}
Note: See TracBrowser for help on using the repository browser.