2 Copyright © 1995-2015, 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>
14 #include <proto/kernel.h>
16 #include "exec_intern.h"
18 /*****************************************************************************
25 AROS_LHA(ULONG
, signalSet
, D0
),
28 struct ExecBase
*, SysBase
, 53, Exec
)
31 Wait until some signals are sent to the current task. If any signal
32 of the specified set is already set when entering this function it
33 returns immediately. Since almost any event in the OS can send a
34 signal to your task if you specify it to do so signals are a very
38 signalSet - The set of signals to wait for.
41 The set of active signals.
44 Naturally it's not allowed to wait in supervisor mode.
46 Calling Wait() breaks an active Disable() or Forbid().
53 Signal(), SetSignal(), AllocSignal(), FreeSignal()
59 ******************************************************************************/
66 /* Get pointer to current task - I'll need it very often */
69 D(bug("[Exec] Wait(0x%08lX)\n", signalSet
));
71 /* If at least one of the signals is already set do not wait. */
72 while (!(me
->tc_SigRecvd
& signalSet
))
74 #if defined(__AROSEXEC_SMP__)
75 if (me
->tc_State
!= TS_WAIT
)
78 D(bug("[Exec] Moving '%s' @ 0x%p to Task Wait queue\n", me
->tc_Node
.ln_Name
, me
));
79 D(bug("[Exec] Task state = %08x\n", me
->tc_State
));
80 /* Set the wait signal mask */
81 me
->tc_SigWait
= signalSet
;
84 Clear TDNestCnt (because Switch() will not care about it),
85 but memorize it first. IDNestCnt is handled by Switch().
87 me
->tc_TDNestCnt
= TDNESTCOUNT_GET
;
90 /* Protect the task lists against access by other tasks. */
91 #if defined(__AROSEXEC_SMP__)
92 EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase
)->TaskRunningSpinLock
, SPINLOCK_MODE_WRITE
);
96 #if defined(__AROSEXEC_SMP__)
98 EXEC_SPINLOCK_UNLOCK(&PrivExecBase(SysBase
)->TaskRunningSpinLock
);
100 EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase
)->TaskWaitSpinLock
, SPINLOCK_MODE_WRITE
);
103 /* Move current task to the waiting list. */
104 me
->tc_State
= TS_WAIT
;
105 Enqueue(&SysBase
->TaskWait
, &me
->tc_Node
);
106 #if defined(__AROSEXEC_SMP__)
107 EXEC_SPINLOCK_UNLOCK(&PrivExecBase(SysBase
)->TaskWaitSpinLock
);
109 /* And switch to the next ready task. */
113 OK. Somebody awakened me. This means that either the
114 signals are there or it's just a finished task exception.
115 Test again to be sure (see above).
118 /* Restore TDNestCnt. */
119 TDNESTCOUNT_SET(me
->tc_TDNestCnt
);
122 #if defined(__AROSEXEC_SMP__)
126 /* Get active signals. */
127 rcvd
= (me
->tc_SigRecvd
& signalSet
);
129 /* And clear them. */
130 me
->tc_SigRecvd
&= ~signalSet
;