remove definition of ARM_PERIIOBASE
[AROS.git] / rom / exec / childwait.c
blob68c74d980d3eaeec50216fe930c870f223e7665b
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 ChildWait() - Wait for a task to finish it processing.
6 */
7 #include "exec_intern.h"
8 #include <proto/exec.h>
10 /*****************************************************************************
12 NAME */
14 AROS_LH1(IPTR, ChildWait,
16 /* SYNOPSIS */
17 AROS_LHA(ULONG, tid, D0),
19 /* LOCATION */
20 struct ExecBase *, SysBase, 126, Exec)
22 /* FUNCTION
23 Wait for either a specific child task, or any child task to finish.
24 If you specify tid = 0, then this call will return when any child
25 task exits, otherwise it will not return until the requested task
26 finishes.
28 Note that the tid is NOT the task control block (ie struct Task *),
29 rather it is the value of the ETask et_UniqueID field. Passing in a
30 Task pointer will cause your Task to deadlock.
32 You must call ChildFree() on the returned task before calling
33 ChildWait() again. Ie.
35 struct ETask *et;
37 et = ChildWait(0);
38 ChildFree(et->et_UniqueID);
40 INPUTS
41 tid - The UniqueID of a task.
43 RESULT
44 Returns either the ETask structure of the child, or one of the
45 CHILD_* values on error.
47 This allows you to work out which of the children has exited.
49 NOTES
50 This function will work correctly only for child tasks that are
51 processes created with NP_NotifyOnDeath set to TRUE.
53 Calling ChildWait() on a task that isn't your child will result in
54 a deadlock.
56 EXAMPLE
58 BUGS
59 Be careful with the return result of this function.
61 SEE ALSO
63 INTERNALS
65 *****************************************************************************/
67 AROS_LIBFUNC_INIT
69 struct Task *this = FindTask(NULL);
70 struct ETask *et;
71 struct ETask *child;
74 ChildWait() will wait for either a specific or any child task to
75 finish. We we get it we return the task unique id to the caller.
77 Firstly, are we a new-style Task?
79 if ((this->tc_Flags & TF_ETASK) == 0)
80 return CHILD_NOTNEW;
82 et = this->tc_UnionETask.tc_ETask;
85 Scanning this list is unsafe, I need to Forbid(). Note that the
86 Wait() below will break the Forbid() condition. This is how I need
87 it to be.
89 Forbid();
91 /* We do not return until the condition is met */
92 for (;;)
94 /* Check if it has returned already. This will also take the first. */
95 ForeachNode(&et->et_TaskMsgPort.mp_MsgList, child)
97 if (tid == 0 || child->et_UniqueID == tid)
98 goto child_exited;
101 /* No matching children, we have to wait */
102 SetSignal(0, SIGF_CHILD);
103 Wait(SIGF_CHILD);
106 child_exited:
107 Permit();
108 return (IPTR)child;
110 AROS_LIBFUNC_EXIT
111 } /* ChildWait */