home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / exec / settaskpri.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-09  |  2.7 KB  |  121 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: settaskpri.c,v 1.7 1997/01/01 03:46:16 ldp Exp $
  4.     $Log: settaskpri.c,v $
  5.     Revision 1.7  1997/01/01 03:46:16  ldp
  6.     Committed Amiga native (support) code
  7.  
  8.     Changed clib to proto
  9.  
  10.     Revision 1.6  1996/12/10 13:51:54  aros
  11.     Moved all #include's in the first column so makedepend can see it.
  12.  
  13.     Revision 1.5  1996/10/24 15:50:58  aros
  14.     Use the official AROS macros over the __AROS versions.
  15.  
  16.     Revision 1.4  1996/08/13 13:56:08  digulla
  17.     Replaced AROS_LA by AROS_LHA
  18.     Replaced some AROS_LH*I by AROS_LH*
  19.     Sorted and added includes
  20.  
  21.     Revision 1.3  1996/08/01 17:41:20  digulla
  22.     Added standard header for all files
  23.  
  24.     Desc:
  25.     Lang: english
  26. */
  27. #include <exec/execbase.h>
  28. #include <aros/libcall.h>
  29. #include <proto/exec.h>
  30.  
  31. /*****************************************************************************
  32.  
  33.     NAME */
  34.  
  35.     AROS_LH2(BYTE, SetTaskPri,
  36.  
  37. /*  SYNOPSIS */
  38.     AROS_LHA(struct Task *, task,      A1),
  39.     AROS_LHA(LONG,          priority,  D0),
  40.  
  41. /*  LOCATION */
  42.     struct ExecBase *, SysBase, 50, Exec)
  43.  
  44. /*  FUNCTION
  45.     Change the priority of a given task. As a general rule the higher
  46.     the priority the more CPU time a task gets. Useful values are within
  47.     -127 to 5.
  48.  
  49.     INPUTS
  50.     task     - Pointer to task structure.
  51.     priority - New priority of the task.
  52.  
  53.     RESULT
  54.     Old task priority.
  55.  
  56.     NOTES
  57.  
  58.     EXAMPLE
  59.  
  60.     BUGS
  61.  
  62.     SEE ALSO
  63.  
  64.     INTERNALS
  65.  
  66.     HISTORY
  67.  
  68. ******************************************************************************/
  69. {
  70.     AROS_LIBFUNC_INIT
  71.  
  72.     BYTE old;
  73.  
  74.     /* Always Disable() when doing something with task lists. */
  75.     Disable();
  76.  
  77.     /* Get returncode */
  78.     old=task->tc_Node.ln_Pri;
  79.  
  80.     /* Set new value. */
  81.     task->tc_Node.ln_Pri=priority;
  82.  
  83.     /* Check if the task is willing to run. */
  84.     if(task->tc_State!=TS_WAIT)
  85.     {
  86.     /* If it is in the ready list remove and reinsert it. */
  87.     if(task->tc_State==TS_READY)
  88.     {
  89.         Remove(&task->tc_Node);
  90.         Enqueue(&SysBase->TaskReady,&task->tc_Node);
  91.     }
  92.  
  93.     /*
  94.         I could check the task priorities here to determine if
  95.         the following is really necessary, but OTOH priority
  96.         changes are rare and the hassle isn't really worth it.
  97.  
  98.         This should be reconsidered, because of Executive [ldp].
  99.     */
  100.  
  101.     /* Are taskswitches allowed? */
  102.     if(SysBase->TDNestCnt>=0||SysBase->IDNestCnt>0)
  103.         /* No. Store it for later. */
  104.         SysBase->AttnResched|=0x80;
  105.     else
  106.     {
  107.         /* Switches are allowed. Move the current task away. */
  108.         SysBase->ThisTask->tc_State=TS_READY;
  109.         Enqueue(&SysBase->TaskReady,&SysBase->ThisTask->tc_Node);
  110.  
  111.         /* And force a reschedule. */
  112.         Switch();
  113.     }
  114.     }
  115.  
  116.     /* All done. */
  117.     Enable();
  118.     return old;
  119.     AROS_LIBFUNC_EXIT
  120. } /* SetTaskPri */
  121.