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

4.104.114.84.95
Last change on this file since e7541849 was 1095ec1, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/18/05 at 09:03:45

Include config.h.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 *  RTEMS Task Manager
3 *
4 *
5 *  COPYRIGHT (c) 1989-1999.
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_REMOTE:
74#if defined(RTEMS_MULTIPROCESSING)
75      _Thread_Executing->Wait.return_argument = old_priority;
76      return _RTEMS_tasks_MP_Send_request_packet(
77          RTEMS_TASKS_MP_SET_PRIORITY_REQUEST,
78          id,
79          new_priority,
80          0,          /* Not used */
81          0           /* Not used */
82      );
83#endif
84
85    case OBJECTS_ERROR:
86      return RTEMS_INVALID_ID;
87
88    case OBJECTS_LOCAL:
89      /* XXX convert from core priority */
90      *old_priority = the_thread->current_priority;
91      if ( new_priority != RTEMS_CURRENT_PRIORITY ) {
92        the_thread->real_priority = new_priority;
93        if ( the_thread->resource_count == 0 ||
94             the_thread->current_priority > new_priority )
95          _Thread_Change_priority( the_thread, new_priority, FALSE );
96      }
97      _Thread_Enable_dispatch();
98      return RTEMS_SUCCESSFUL;
99  }
100
101  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
102}
Note: See TracBrowser for help on using the repository browser.