2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
5 Desc: Wait for some signal.
10 #include <aros/debug.h>
11 #include <exec/execbase.h>
12 #include <aros/libcall.h>
13 #include <proto/exec.h>
15 #include "exec_intern.h"
16 #if defined(__AROSEXEC_SMP__)
20 /*****************************************************************************
27 AROS_LHA(ULONG
, signalSet
, D0
),
30 struct ExecBase
*, SysBase
, 53, Exec
)
33 Wait until some signals are sent to the current task. If any signal
34 of the specified set is already set when entering this function it
35 returns immediately. Since almost any event in the OS can send a
36 signal to your task if you specify it to do so signals are a very
40 signalSet - The set of signals to wait for.
43 The set of active signals.
46 Naturally it's not allowed to wait in supervisor mode.
48 Calling Wait() breaks an active Disable() or Forbid().
55 Signal(), SetSignal(), AllocSignal(), FreeSignal()
61 ******************************************************************************/
65 struct Task
*thisTask
= GET_THIS_TASK
;
68 D(bug("[Exec] Wait(%08lX)\n", signalSet
);)
71 /* If at least one of the signals is already set do not wait. */
72 while (!(thisTask
->tc_SigRecvd
& signalSet
))
74 /* Set the wait signal mask */
75 thisTask
->tc_SigWait
= signalSet
;
77 D(bug("[Exec] Moving '%s' @ 0x%p to Task Wait queue\n", thisTask
->tc_Node
.ln_Name
, thisTask
);)
78 D(bug("[Exec] Task state = %08x\n", thisTask
->tc_State
);)
81 Clear TDNestCnt (because Switch() will not care about it),
82 but memorize it first. IDNestCnt is handled by Switch().
84 thisTask
->tc_TDNestCnt
= TDNESTCOUNT_GET
;
87 thisTask
->tc_State
= TS_WAIT
;
88 // nb: on smp builds switch will move us.
89 #if !defined(__AROSEXEC_SMP__)
90 /* Move current task to the waiting list. */
91 Enqueue(&SysBase
->TaskWait
, &thisTask
->tc_Node
);
94 /* And switch to the next ready task. */
98 OK. Somebody awakened us. This means that either the
99 signals are there or it's just a finished task exception.
100 Test again to be sure (see above).
103 /* Restore TDNestCnt. */
104 TDNESTCOUNT_SET(thisTask
->tc_TDNestCnt
);
106 /* Get active signals. */
107 rcvd
= (thisTask
->tc_SigRecvd
& signalSet
);
109 /* And clear them. */
110 #if defined(__AROSEXEC_SMP__)
111 __AROS_ATOMIC_AND_L(thisTask
->tc_SigRecvd
, ~signalSet
);
113 thisTask
->tc_SigRecvd
&= ~signalSet
;