Minor fixes to comments.
[AROS.git] / rom / exec / wait.c
blobfadbf7cefaddc2c238cb5aeef5892b69def45e77
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Wait for some signal.
6 Lang: english
7 */
8 #define DEBUG 0
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 /*****************************************************************************
20 NAME */
22 AROS_LH1(ULONG, Wait,
24 /* SYNOPSIS */
25 AROS_LHA(ULONG, signalSet, D0),
27 /* LOCATION */
28 struct ExecBase *, SysBase, 53, Exec)
30 /* FUNCTION
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
35 powerful mechanism.
37 INPUTS
38 signalSet - The set of signals to wait for.
40 RESULT
41 The set of active signals.
43 NOTES
44 Naturally it's not allowed to wait in supervisor mode.
46 Calling Wait() breaks an active Disable() or Forbid().
48 EXAMPLE
50 BUGS
52 SEE ALSO
53 Signal(), SetSignal(), AllocSignal(), FreeSignal()
55 INTERNALS
57 HISTORY
59 ******************************************************************************/
61 AROS_LIBFUNC_INIT
63 ULONG rcvd;
64 struct Task *me;
66 /* Get pointer to current task - I'll need it very often */
67 me = FindTask (NULL);
69 D(bug("[Exec] Wait(0x%08lX) called by %s\n", signalSet, me->tc_Node.ln_Name));
70 /* Protect the task lists against access by other tasks. */
71 Disable();
73 /* If at least one of the signals is already set do not wait. */
74 while(!(me->tc_SigRecvd&signalSet))
76 D(bug("[Exec] Signals are not set, putting the task to sleep\n"));
77 /* Set the wait signal mask */
78 me->tc_SigWait=signalSet;
81 Clear TDNestCnt (because Switch() will not care about it),
82 but memorize it first. IDNestCnt is handled by Switch().
84 me->tc_TDNestCnt=SysBase->TDNestCnt;
85 SysBase->TDNestCnt=-1;
87 /* Move current task to the waiting list. */
88 me->tc_State=TS_WAIT;
89 Enqueue(&SysBase->TaskWait,&me->tc_Node);
91 /* And switch to the next ready task. */
92 KrnSwitch();
95 OK. Somebody awakened me. This means that either the
96 signals are there or it's just a finished task exception.
97 Test again to be sure (see above).
100 /* Restore TDNestCnt. */
101 SysBase->TDNestCnt=me->tc_TDNestCnt;
103 /* Get active signals. */
104 rcvd=me->tc_SigRecvd&signalSet;
106 /* And clear them. */
107 me->tc_SigRecvd&=~signalSet;
109 /* All done. */
110 Enable();
112 return rcvd;
114 AROS_LIBFUNC_EXIT