Re-enabled use of AROS.Boot file due to lack of general enthusiasm for
[tangerine.git] / arch / i386-pc / exec / wait.c
blob42ca588578ca905dfe3c9eb08252d9f569c8c853
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 extern void Exec_Switch();
19 AROS_LH1(ULONG, Wait,
21 /* SYNOPSIS */
22 AROS_LHA(ULONG, signalSet, D0),
24 /* LOCATION */
25 struct ExecBase *, SysBase, 53, Exec)
27 /* FUNCTION
28 Wait until some signals are sent to the current task. If any signal
29 of the specified set is already set when entering this function it
30 returns immediately. Since almost any event in the OS can send a
31 signal to your task if you specify it to do so signals are a very
32 powerful mechanism.
34 INPUTS
35 signalSet - The set of signals to wait for.
37 RESULT
38 The set of active signals.
40 NOTES
41 Naturally it's not allowed to wait in supervisor mode.
43 Calling Wait() breaks an active Disable() or Forbid().
45 EXAMPLE
47 BUGS
49 SEE ALSO
50 Signal(), SetSignal(), AllocSignal(), FreeSignal()
52 INTERNALS
54 HISTORY
56 ******************************************************************************/
58 AROS_LIBFUNC_INIT
60 ULONG rcvd;
61 struct Task *me;
63 /* Get pointer to current task - I'll need it very often */
64 me = FindTask (NULL);
66 /* Protect the task lists against access by other tasks. */
67 Disable();
69 /* If at least one of the signals is already set do not wait. */
70 while(!(me->tc_SigRecvd&signalSet))
72 BYTE old_TDNestCnt;
74 /* Set the wait signal mask */
75 me->tc_SigWait=signalSet;
78 Clear TDNestCnt (because Switch() will not care about it),
79 but memorize it first. IDNestCnt is handled by Switch().
80 This could as well be stored in a local variable which makes
81 the tc_TDNestCnt field somehow redundant.
83 old_TDNestCnt=SysBase->TDNestCnt;
84 SysBase->TDNestCnt=-1;
86 /* Move current task to the waiting list. */
87 me->tc_State=TS_WAIT;
90 remove it from what!?
91 sheutlin
93 // me->tc_Node.ln_Pred->ln_Succ = me->tc_Node.ln_Succ;
94 // me->tc_Node.ln_Succ->ln_Pred = me->tc_Node.ln_Pred;
96 Enqueue(&SysBase->TaskWait,&me->tc_Node);
98 /* And switch to the next ready task. */
99 Supervisor(__AROS_GETVECADDR(SysBase,9));
101 // Reschedule(me);
104 OK. Somebody awakened me. This means that either the
105 signals are there or it's just a finished task exception.
106 Test again to be sure (see above).
109 /* Restore TDNestCnt. */
110 SysBase->TDNestCnt=old_TDNestCnt;
112 /* Get active signals. */
113 rcvd=me->tc_SigRecvd&signalSet;
115 /* And clear them. */
116 me->tc_SigRecvd&=~signalSet;
118 /* All done. */
119 Enable();
121 return rcvd;
122 AROS_LIBFUNC_EXIT