home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / aros / source / exec / tasks / src / settaskpri.c < prev   
Encoding:
C/C++ Source or Header  |  1996-07-16  |  2.2 KB  |  103 lines

  1. /*
  2.     $Id: settaskpri.c 1.1 1995/12/17 21:37:10 digulla Exp digulla $
  3.     $Log: settaskpri.c $
  4.  * Revision 1.1  1995/12/17  21:37:10  digulla
  5.  * Initial revision
  6.  *
  7.     Desc:
  8.     Lang: english
  9. */
  10. #include "exec_intern.h"
  11.  
  12. /*****************************************************************************
  13.  
  14.     NAME */
  15.     #include <clib/exec_protos.h>
  16.  
  17.     __AROS_LH2(BYTE, SetTaskPri,
  18.  
  19. /*  SYNOPSIS */
  20.     __AROS_LA(struct Task *, task, A1),
  21.     __AROS_LA(long         , priority, D0),
  22.  
  23. /*  LOCATION */
  24.     struct ExecBase *, SysBase, 50, Exec)
  25.  
  26. /*  FUNCTION
  27.     Change the priority of a given task. As a general rule the higher
  28.     the priority the more CPU time a task gets. Useful values are within
  29.     -127 to 5.
  30.  
  31.     INPUTS
  32.     task     - Pointer to task structure.
  33.     priority - New priority of the task.
  34.  
  35.     RESULT
  36.     Old task priority.
  37.  
  38.     NOTES
  39.  
  40.     EXAMPLE
  41.  
  42.     BUGS
  43.  
  44.     SEE ALSO
  45.  
  46.     INTERNALS
  47.  
  48.     HISTORY
  49.     29-10-95    digulla automatically created from
  50.                 exec_lib.fd and clib/exec_protos.h
  51.     17-12-95    digulla Incorporated code by Matthias Fleischner
  52.  
  53. *****************************************************************************/
  54. {
  55.     __AROS_FUNC_INIT
  56.     BYTE old;
  57.  
  58.     /* Always Disable() when doing something with task lists. */
  59.     Disable();
  60.  
  61.     /* Get returncode */
  62.     old=task->tc_Node.ln_Pri;
  63.  
  64.     /* Set new value. */
  65.     task->tc_Node.ln_Pri=priority;
  66.  
  67.     /* Check if the task is willing to run. */
  68.     if(task->tc_State!=TS_WAIT)
  69.     {
  70.     /* If it is in the ready list remove and reinsert it. */
  71.     if(task->tc_State==TS_READY)
  72.     {
  73.         Remove(&task->tc_Node);
  74.         Enqueue(&SysBase->TaskReady,&task->tc_Node);
  75.     }
  76.  
  77.     /*
  78.         I could check the task priorities here to determine if
  79.         the following is really necessary, but OTOH priority
  80.         changes are rare and the hassle isn't really worth it.
  81.     */
  82.  
  83.     /* Are taskswitches allowed? */
  84.     if(SysBase->TDNestCnt>=0||SysBase->IDNestCnt>0)
  85.         /* No. Store it for later. */
  86.         SysBase->AttnResched|=0x80;
  87.     else
  88.     {
  89.         /* Switches are allowed. Move the current task away. */
  90.         SysBase->ThisTask->tc_State=TS_READY;
  91.         Enqueue(&SysBase->TaskReady,&SysBase->ThisTask->tc_Node);
  92.  
  93.         /* And force a rescedule. */
  94.         Switch();
  95.     }
  96.     }
  97.  
  98.     /* All done. */
  99.     Enable();
  100.     return old;
  101.     __AROS_FUNC_EXIT
  102. } /* SetTaskPri */
  103.