2 Copyright © 1995-2010, 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 ******************************************************************************/
67 /* Get pointer to current task - I'll need it very often */
70 //D(bug("[Exec] Wait(0x%08lX) called by %s\n", signalSet, me->tc_Node.ln_Name));
71 /* Protect the task lists against access by other tasks. */
74 /* If at least one of the signals is already set do not wait. */
75 while(!(me->tc_SigRecvd&signalSet))
77 //D(bug("[Exec] Signals are not set, putting the task to sleep\n"));
78 /* Set the wait signal mask */
79 me->tc_SigWait=signalSet;
81 /* Move current task to the waiting list. */
83 Enqueue(&SysBase->TaskWait,&me->tc_Node);
85 /* temporarly release all our spinlocks */
86 spincount=ResetSpin(&(PrivExecBase(SysBase)->LibList_spinlock), 0);
88 D(bug("[Exec] Wait() task %p released %d %p spinlocks\n", FindTask(NULL), spincount, &(PrivExecBase(SysBase)->LibList_spinlock)));
90 /* And switch to the next ready task. */
94 OK. Somebody awakened me. This means that either the
95 signals are there or it's just a finished task exception.
96 Test again to be sure (see above).
99 /* Get active signals. */
100 rcvd=me->tc_SigRecvd&signalSet;
102 /* And clear them. */
103 me->tc_SigRecvd&=~signalSet;
106 D(bug("[Exec] Wait() needs back spinlock %p %d times for task %p.\n", &(PrivExecBase(SysBase)->LibList_spinlock), spincount), FindTask(NULL));
111 /* get our locks back ! */
114 LockSpin(&(PrivExecBase(SysBase)->LibList_spinlock));
115 D(bug("[Exec] Wait() aquired back spinlock %p number %d\n", &(PrivExecBase(SysBase)->LibList_spinlock), spincount, FindTask(NULL)));