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

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: wait.c,v 1.7 1997/01/01 03:46:18 ldp Exp $
  4.     $Log: wait.c,v $
  5.     Revision 1.7  1997/01/01 03:46:18  ldp
  6.     Committed Amiga native (support) code
  7.  
  8.     Changed clib to proto
  9.  
  10.     Revision 1.6  1996/12/10 13:51:55  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:21  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_LH1(ULONG, Wait,
  36.  
  37. /*  SYNOPSIS */
  38.     AROS_LHA(ULONG, signalSet, D0),
  39.  
  40. /*  LOCATION */
  41.     struct ExecBase *, SysBase, 53, Exec)
  42.  
  43. /*  FUNCTION
  44.     Wait until some signals are sent to the current task. If any signal
  45.     of the specified set is already set when entering this function it
  46.     returns immediately. Since almost any event in the OS can send a
  47.     signal to your task if you specify it to do so signals are a very
  48.     powerful mechanism.
  49.  
  50.     INPUTS
  51.     signalSet - The set of signals to wait for.
  52.  
  53.     RESULT
  54.     The set of active signals.
  55.  
  56.     NOTES
  57.     Naturally it's not allowed to wait in supervisor mode.
  58.  
  59.     Calling Wait() breaks an active Disable() or Forbid().
  60.  
  61.     EXAMPLE
  62.  
  63.     BUGS
  64.  
  65.     SEE ALSO
  66.     Signal(), SetSignal(), AllocSignal(), FreeSignal()
  67.  
  68.     INTERNALS
  69.  
  70.     HISTORY
  71.  
  72. ******************************************************************************/
  73. {
  74.     AROS_LIBFUNC_INIT
  75.  
  76.     ULONG rcvd;
  77.     struct Task *me;
  78.  
  79.     /* Get pointer to current task - I'll need it very often */
  80.     me=SysBase->ThisTask;
  81.  
  82.     /* Protect the task lists against access by other tasks. */
  83.     Disable();
  84.  
  85.     /* If at least one of the signals is already set do not wait. */
  86.     while(!(me->tc_SigRecvd&signalSet))
  87.     {
  88.     /* Set the wait signal mask */
  89.     me->tc_SigWait=signalSet;
  90.  
  91.     /*
  92.         Clear TDNestCnt (because Switch() will not care about it),
  93.         but memorize it first. IDNestCnt is handled by Switch().
  94.         This could as well be stored in a local variable which makes
  95.         the tc_TDNestCnt field somehow redundant.
  96.     */
  97.     me->tc_TDNestCnt=SysBase->TDNestCnt;
  98.     SysBase->TDNestCnt=-1;
  99.  
  100.     /* Move current task to the waiting list. */
  101.     me->tc_State=TS_WAIT;
  102.     Enqueue(&SysBase->TaskWait,&me->tc_Node);
  103.  
  104.     /* And switch to the next ready task. */
  105.     Switch();
  106.     /*
  107.         OK. Somebody awakened me. This means that either the
  108.         signals are there or it's just a finished task exception.
  109.         Test again to be sure (see above).
  110.     */
  111.  
  112.     /* Restore TDNestCnt. */
  113.     SysBase->TDNestCnt=me->tc_TDNestCnt;
  114.     }
  115.     /* Get active signals. */
  116.     rcvd=me->tc_SigRecvd&signalSet;
  117.  
  118.     /* And clear them. */
  119.     me->tc_SigRecvd&=~signalSet;
  120.  
  121.     /* All done. */
  122.     Enable();
  123.     return rcvd;
  124.     AROS_LIBFUNC_EXIT
  125. }
  126.  
  127.