source: rtems/c/src/exec/rtems/src/tasksetpriority.c @ df49c60

4.104.114.84.95
Last change on this file since df49c60 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

  • Property mode set to 100644
File size: 2.7 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.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15#include <rtems/system.h>
16#include <rtems/rtems/status.h>
17#include <rtems/rtems/support.h>
18#include <rtems/rtems/modes.h>
19#include <rtems/score/object.h>
20#include <rtems/score/stack.h>
21#include <rtems/score/states.h>
22#include <rtems/rtems/tasks.h>
23#include <rtems/score/thread.h>
24#include <rtems/score/threadq.h>
25#include <rtems/score/tod.h>
26#include <rtems/score/userext.h>
27#include <rtems/score/wkspace.h>
28#include <rtems/score/apiext.h>
29#include <rtems/score/sysstate.h>
30
31/*PAGE
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  Objects_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_REMOTE:
70#if defined(RTEMS_MULTIPROCESSING)
71      _Thread_Executing->Wait.return_argument = old_priority;
72      return _RTEMS_tasks_MP_Send_request_packet(
73          RTEMS_TASKS_MP_SET_PRIORITY_REQUEST,
74          id,
75          new_priority,
76          0,          /* Not used */
77          0           /* Not used */
78      );
79#endif
80
81    case OBJECTS_ERROR:
82      return RTEMS_INVALID_ID;
83
84    case OBJECTS_LOCAL:
85      /* XXX convert from core priority */
86      *old_priority = the_thread->current_priority;
87      if ( new_priority != RTEMS_CURRENT_PRIORITY ) {
88        the_thread->real_priority = new_priority;
89        if ( the_thread->resource_count == 0 ||
90             the_thread->current_priority > new_priority )
91          _Thread_Change_priority( the_thread, new_priority, FALSE );
92      }
93      _Thread_Enable_dispatch();
94      return RTEMS_SUCCESSFUL;
95  }
96
97  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
98}
Note: See TracBrowser for help on using the repository browser.