2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
5 Desc: Wait for a message on a port.
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 /*****************************************************************************
21 AROS_LH1(struct Message
*, WaitPort
,
24 AROS_LHA(struct MsgPort
*, port
, A0
),
27 struct ExecBase
*, SysBase
, 64, Exec
)
30 Wait until a message arrives at the given port. If there is already
31 a message in it this function returns immediately.
34 port - Pointer to messageport.
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.
51 ******************************************************************************/
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__)
67 EXEC_SPINLOCK_LOCK(&port
->mp_SpinLock
, NULL
, SPINLOCK_MODE_READ
);
69 while (IsListEmpty(&port
->mp_MsgList
))
71 #if defined(__AROSEXEC_SMP__)
72 EXEC_SPINLOCK_UNLOCK(&port
->mp_SpinLock
);
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__)
86 EXEC_SPINLOCK_LOCK(&port
->mp_SpinLock
, NULL
, SPINLOCK_MODE_READ
);
89 #if defined(__AROSEXEC_SMP__)
90 EXEC_SPINLOCK_UNLOCK(&port
->mp_SpinLock
);
94 D(bug("[Exec] WaitPort: Returning...\n");)
96 /* Return the first node in the list. */
97 return (struct Message
*)port
->mp_MsgList
.lh_Head
;