revert between 56095 -> 55830 in arch
[AROS.git] / rom / exec / getmsg.c
blobc9ec04e8a9ca2be893ae767052ac93c77aa611bf
1 /*
2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Get a message from a message port.
6 Lang: english
7 */
9 #define DEBUG 0
10 #include <aros/debug.h>
12 #include <exec/execbase.h>
13 #include <exec/ports.h>
14 #include <aros/libcall.h>
15 #include <proto/exec.h>
17 #include "exec_intern.h"
19 /*****************************************************************************
21 NAME */
23 AROS_LH1(struct Message *, GetMsg,
25 /* SYNOPSIS */
26 AROS_LHA(struct MsgPort *, port, A0),
28 /* LOCATION */
29 struct ExecBase *, SysBase, 62, Exec)
31 /* FUNCTION
32 Get a message from a given messageport. This function doesn't wait
33 and returns NULL if the messageport is empty. Therefore it's
34 generally a good idea to WaitPort() or Wait() on the given port first.
36 INPUTS
37 port - Pointer to messageport
39 RESULT
40 Pointer to message removed from the port.
42 NOTES
44 EXAMPLE
46 BUGS
48 SEE ALSO
49 WaitPort(), PutMsg()
51 INTERNALS
53 ******************************************************************************/
55 AROS_LIBFUNC_INIT
57 struct Message *msg;
59 D(bug("[Exec] GetMsg(0x%p)\n", port);)
61 ASSERT_VALID_PTR(port);
64 * Protect the message list, and get the first node.
66 Disable();
67 #if defined(__AROSEXEC_SMP__)
68 EXEC_SPINLOCK_LOCK(&port->mp_SpinLock, NULL, SPINLOCK_MODE_WRITE);
69 #endif
70 msg=(struct Message *)RemHead(&port->mp_MsgList);
71 #if defined(__AROSEXEC_SMP__)
72 EXEC_SPINLOCK_UNLOCK(&port->mp_SpinLock);
73 #endif
74 Enable();
76 /* All done. */
77 ASSERT_VALID_PTR_OR_NULL(msg);
79 return msg;
80 AROS_LIBFUNC_EXIT
81 } /* GetMsg() */