move VMWare SVGA driver to generic location
[AROS.git] / rom / exec / wait.c
blob7bf44a95b1d439820f838248144dafdaeabc597d
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Wait for some signal.
6 Lang: english
7 */
8 #include <exec/execbase.h>
9 #include <aros/libcall.h>
10 #include <proto/exec.h>
12 /*****************************************************************************
14 NAME */
16 AROS_LH1(ULONG, Wait,
18 /* SYNOPSIS */
19 AROS_LHA(ULONG, signalSet, D0),
21 /* LOCATION */
22 struct ExecBase *, SysBase, 53, Exec)
24 /* FUNCTION
25 Wait until some signals are sent to the current task. If any signal
26 of the specified set is already set when entering this function it
27 returns immediately. Since almost any event in the OS can send a
28 signal to your task if you specify it to do so signals are a very
29 powerful mechanism.
31 INPUTS
32 signalSet - The set of signals to wait for.
34 RESULT
35 The set of active signals.
37 NOTES
38 Naturally it's not allowed to wait in supervisor mode.
40 Calling Wait() breaks an active Disable() or Forbid().
42 EXAMPLE
44 BUGS
46 SEE ALSO
47 Signal(), SetSignal(), AllocSignal(), FreeSignal()
49 INTERNALS
51 ******************************************************************************/
53 AROS_LIBFUNC_INIT
55 ULONG rcvd;
56 struct Task *me;
58 /* Get pointer to current task - I'll need it very often */
59 me = FindTask (NULL);
61 /* Protect the task lists against access by other tasks. */
62 Disable();
64 /* If at least one of the signals is already set do not wait. */
65 while(!(me->tc_SigRecvd&signalSet))
67 BYTE old_TDNestCnt;
69 /* Set the wait signal mask */
70 me->tc_SigWait=signalSet;
73 Clear TDNestCnt (because Switch() will not care about it),
74 but memorize it first. IDNestCnt is handled by Switch().
75 This could as well be stored in a local variable which makes
76 the tc_TDNestCnt field somehow redundant.
78 old_TDNestCnt=SysBase->TDNestCnt;
79 SysBase->TDNestCnt=-1;
81 /* Move current task to the waiting list. */
82 me->tc_State=TS_WAIT;
83 Enqueue(&SysBase->TaskWait,&me->tc_Node);
85 /* And switch to the next ready task. */
86 Switch();
88 OK. Somebody awakened me. This means that either the
89 signals are there or it's just a finished task exception.
90 Test again to be sure (see above).
93 /* Restore TDNestCnt. */
94 SysBase->TDNestCnt=old_TDNestCnt;
96 /* Get active signals. */
97 rcvd=me->tc_SigRecvd&signalSet;
99 /* And clear them. */
100 me->tc_SigRecvd&=~signalSet;
102 /* All done. */
103 Enable();
105 return rcvd;
106 AROS_LIBFUNC_EXIT
107 } /* Wait() */