source: rtems/c/src/exec/rtems/src/tasksetpriority.c @ 861e94d9

4.104.114.84.95
Last change on this file since 861e94d9 was 861e94d9, checked in by Joel Sherrill <joel.sherrill@…>, on 11/02/99 at 15:35:58

Added comment to make sure Classic API priority to Core priority
is added in the future.

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