revert between 56095 -> 55830 in arch
[AROS.git] / rom / exec / waitport.c
blob3605feaf06f26e15cf55e5dac193d545fab6fdb7
1 /*
2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Wait for a message on a port.
6 Lang: english
7 */
9 #define DEBUG 0
10 #include <aros/debug.h>
12 #include "exec_intern.h"
13 #include <exec/ports.h>
14 #include <aros/libcall.h>
15 #include <proto/exec.h>
17 /*****************************************************************************
19 NAME */
21 AROS_LH1(struct Message *, WaitPort,
23 /* SYNOPSIS */
24 AROS_LHA(struct MsgPort *, port, A0),
26 /* LOCATION */
27 struct ExecBase *, SysBase, 64, Exec)
29 /* FUNCTION
30 Wait until a message arrives at the given port. If there is already
31 a message in it this function returns immediately.
33 INPUTS
34 port - Pointer to messageport.
36 RESULT
37 Pointer to the first message that arrived at the port. The message
38 is _not_ removed from the port. GetMsg() does this for you.
40 NOTES
42 EXAMPLE
44 BUGS
46 SEE ALSO
47 WaitPort(), GetMsg()
49 INTERNALS
51 ******************************************************************************/
53 AROS_LIBFUNC_INIT
55 ASSERT_VALID_PTR(port);
57 On uniprocessors systems, Disable() is not necessary since emptiness
58 can be checked without it - and nobody is allowed to change the signal bit as soon
59 as the current task entered WaitPort() (and probably did not yet
60 have a chance to Disable()).
62 D(bug("[Exec] WaitPort(0x%p)\n", port);)
64 /* Is messageport empty? */
65 #if defined(__AROSEXEC_SMP__)
66 Disable();
67 EXEC_SPINLOCK_LOCK(&port->mp_SpinLock, NULL, SPINLOCK_MODE_READ);
68 #endif
69 while (IsListEmpty(&port->mp_MsgList))
71 #if defined(__AROSEXEC_SMP__)
72 EXEC_SPINLOCK_UNLOCK(&port->mp_SpinLock);
73 Enable();
74 #endif
75 D(bug("[Exec] WaitPort: Msg list empty, waiting for activity...\n");)
78 Yes. Wait for the signal to arrive. Remember that signals may
79 arrive without a message so check again.
81 Wait(1<<port->mp_SigBit);
83 D(bug("[Exec] WaitPort: Msgport signal received ...\n");)
84 #if defined(__AROSEXEC_SMP__)
85 Disable();
86 EXEC_SPINLOCK_LOCK(&port->mp_SpinLock, NULL, SPINLOCK_MODE_READ);
87 #endif
89 #if defined(__AROSEXEC_SMP__)
90 EXEC_SPINLOCK_UNLOCK(&port->mp_SpinLock);
91 Enable();
92 #endif
94 D(bug("[Exec] WaitPort: Returning...\n");)
96 /* Return the first node in the list. */
97 return (struct Message *)port->mp_MsgList.lh_Head;
99 AROS_LIBFUNC_EXIT
100 } /* WaitPort() */