Detabbed
[AROS.git] / rom / dos / waitpkt.c
blobcdfaceb47e48a0c671778a0e9d9b9236a204a0e5
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 #include <aros/debug.h>
10 #include <dos/notify.h>
11 #include <proto/exec.h>
13 #include "dos_intern.h"
15 /*****************************************************************************
17 NAME */
18 #include <proto/dos.h>
20 AROS_LH0I(struct DosPacket *, WaitPkt,
22 /* SYNOPSIS */
23 /* void */
25 /* LOCATION */
26 struct DosLibrary *, DOSBase, 42, Dos)
28 /* FUNCTION
30 Wait for a packet to arrive at your process' pr_MsgPort. It will call
31 pr_PktWait if such a function is installed.
33 INPUTS
35 RESULT
37 The packet we received.
39 NOTES
41 The packet will be released from the port.
43 This function should NOT be used. It's there only for AmigaOS
44 compatibility.
46 EXAMPLE
48 BUGS
50 SEE ALSO
52 INTERNALS
54 *****************************************************************************/
56 AROS_LIBFUNC_INIT
58 struct Process *me = (struct Process *)FindTask(NULL);
60 ASSERT_VALID_PROCESS(me);
62 return internal_WaitPkt(&me->pr_MsgPort);
64 AROS_LIBFUNC_EXIT
65 } /* WaitPkt */
67 struct DosPacket *internal_WaitPkt(struct MsgPort *msgPort)
69 struct Message *msg = NULL;
70 struct Process *me = (struct Process *)FindTask(NULL);
72 if (__is_process(me))
75 * Call the packet wait function if the user has one installed.
76 * Unfortunately, in case of IOFS the user gets something completely different than
77 * a packet, but we cannot do anything about that...
79 if (me->pr_PktWait)
81 msg = AROS_UFC3(struct Message *, me->pr_PktWait,
82 AROS_UFCA(APTR, me->pr_PktWait, A0),
83 AROS_UFCA(struct MsgPort *, msgPort, A1),
84 AROS_UFCA(struct ExecBase *, SysBase, A6));
88 if (!msg)
90 /* Make sure we have a packet -- we may be woken up even if there is
91 not a packet for us as SIGF_DOS may be used and we may have another
92 message port that waits for packets, too. */
93 while ((msg = GetMsg(msgPort)) == NULL)
95 Wait(1 << msgPort->mp_SigBit);
99 D(bug("[DOS] WaitPkt(): got DOS packet 0x%p in message 0x%p\n", msg->mn_Node.ln_Name, msg));
100 return (struct DosPacket *)msg->mn_Node.ln_Name;