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

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: signal.c,v 1.7 1997/01/01 03:46:16 ldp Exp $
  4.     $Log: signal.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:09  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(void, Signal,
  36.  
  37. /*  SYNOPSIS */
  38.     AROS_LHA(struct Task *,     task,      A1),
  39.     AROS_LHA(ULONG,             signalSet, D0),
  40.  
  41. /*  LOCATION */
  42.     struct ExecBase *, SysBase, 54, Exec)
  43.  
  44. /*  FUNCTION
  45.     Send some signals to a given task. If the task is currently waiting
  46.     on these signals, has a higher priority as the current one and if
  47.     taskswitches are allowed the new task begins to run immediately.
  48.  
  49.     INPUTS
  50.     task      - Pointer to task structure.
  51.     signalSet - The set of signals to send to the task.
  52.  
  53.     RESULT
  54.  
  55.     NOTES
  56.     This function may be used from interrupts.
  57.  
  58.     EXAMPLE
  59.  
  60.     BUGS
  61.  
  62.     SEE ALSO
  63.     AllocSignal(), FreeSignal(), Wait(), SetSignal(), SetExcept()
  64.  
  65.     INTERNALS
  66.  
  67.     HISTORY
  68.  
  69. ******************************************************************************/
  70. {
  71.     AROS_LIBFUNC_INIT
  72.  
  73.     /* Protect the task lists against other tasks that may use Signal(). */
  74.     Disable();
  75.  
  76.     /* Set the signals in the task structure. */
  77.     task->tc_SigRecvd|=signalSet;
  78.  
  79.     /* Do those bits raise exceptions? */
  80.     if(task->tc_SigExcept&task->tc_SigRecvd)
  81.     {
  82.     /* Yes. Set the exception flag. */
  83.     task->tc_Flags|=TF_EXCEPT;
  84.  
  85.     /* task is running? Raise the exception or defer it for later. */
  86.     if(task->tc_State==TS_RUN)
  87.     {
  88.         /* Are taskswitches allowed? (Don't count own Disable() here) */
  89.         if(SysBase->TDNestCnt>=0||SysBase->IDNestCnt>0)
  90.         /* No. Store it for later. */
  91.         SysBase->AttnResched|=0x80;
  92.         else
  93.         {
  94.         /* Switches are allowed. Move the current task away. */
  95.         SysBase->ThisTask->tc_State=TS_READY;
  96.         Enqueue(&SysBase->TaskReady,&SysBase->ThisTask->tc_Node);
  97.  
  98.         /* And force a rescedule. */
  99.         Switch();
  100.         }
  101.  
  102.         /* All done. */
  103.         Enable();
  104.         return;
  105.     }
  106.     }
  107.  
  108.     /*
  109.     Is the task receiving the signals waiting on them
  110.     (or on a exception) ?
  111.     */
  112.     if(task->tc_State==TS_WAIT&&
  113.        (task->tc_SigRecvd&(task->tc_SigWait|task->tc_SigExcept)))
  114.     {
  115.     /* Yes. Move him to the ready list. */
  116.     task->tc_State=TS_READY;
  117.     Remove(&task->tc_Node);
  118.     Enqueue(&SysBase->TaskReady,&task->tc_Node);
  119.  
  120.     /* Has it a higher priority as the current one? */
  121.     if(task->tc_Node.ln_Pri>SysBase->ThisTask->tc_Node.ln_Pri)
  122.         /*
  123.         Yes. A taskswitch is necessary. Prepare one if possible.
  124.         (If the current task is not running it is already moved)
  125.         */
  126.         if(SysBase->ThisTask->tc_State==TS_RUN)
  127.         {
  128.         /* Are taskswitches allowed? */
  129.         if(SysBase->TDNestCnt>=0||SysBase->IDNestCnt>0)
  130.             /* No. Store it for later. */
  131.             SysBase->AttnResched|=0x80;
  132.         else
  133.         {
  134.             /* Switches are allowed. Move the current task away. */
  135.             SysBase->ThisTask->tc_State=TS_READY;
  136.             Enqueue(&SysBase->TaskReady,&SysBase->ThisTask->tc_Node);
  137.  
  138.             /* And force a rescedule. */
  139.             Switch();
  140.         }
  141.         }
  142.     }
  143.  
  144.     Enable();
  145.     AROS_LIBFUNC_EXIT
  146. }
  147.  
  148.