From ab3e7b984a14cbc4b491578a36f0e4bdd37b9d45 Mon Sep 17 00:00:00 2001 From: NicJA Date: Sat, 11 Mar 2017 14:42:50 +0000 Subject: [PATCH] protect access to the msgport list in waitport. git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@54074 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- rom/exec/waitport.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/rom/exec/waitport.c b/rom/exec/waitport.c index 34ddda6171..3605feaf06 100644 --- a/rom/exec/waitport.c +++ b/rom/exec/waitport.c @@ -1,10 +1,14 @@ /* - Copyright © 1995-2001, The AROS Development Team. All rights reserved. + Copyright © 1995-2017, The AROS Development Team. All rights reserved. $Id$ Desc: Wait for a message on a port. Lang: english */ + +#define DEBUG 0 +#include + #include "exec_intern.h" #include #include @@ -50,21 +54,44 @@ ASSERT_VALID_PTR(port); /* - No Disable() necessary here since emptiness can be checked - without and nobody is allowed to change the signal bit as soon + On uniprocessors systems, Disable() is not necessary since emptiness + can be checked without it - and nobody is allowed to change the signal bit as soon as the current task entered WaitPort() (and probably did not yet have a chance to Disable()). */ + D(bug("[Exec] WaitPort(0x%p)\n", port);) /* Is messageport empty? */ - while (IsListEmpty (&port->mp_MsgList)) +#if defined(__AROSEXEC_SMP__) + Disable(); + EXEC_SPINLOCK_LOCK(&port->mp_SpinLock, NULL, SPINLOCK_MODE_READ); +#endif + while (IsListEmpty(&port->mp_MsgList)) { +#if defined(__AROSEXEC_SMP__) + EXEC_SPINLOCK_UNLOCK(&port->mp_SpinLock); + Enable(); +#endif + D(bug("[Exec] WaitPort: Msg list empty, waiting for activity...\n");) + /* Yes. Wait for the signal to arrive. Remember that signals may arrive without a message so check again. */ Wait(1<mp_SigBit); + + D(bug("[Exec] WaitPort: Msgport signal received ...\n");) +#if defined(__AROSEXEC_SMP__) + Disable(); + EXEC_SPINLOCK_LOCK(&port->mp_SpinLock, NULL, SPINLOCK_MODE_READ); +#endif } +#if defined(__AROSEXEC_SMP__) + EXEC_SPINLOCK_UNLOCK(&port->mp_SpinLock); + Enable(); +#endif + + D(bug("[Exec] WaitPort: Returning...\n");) /* Return the first node in the list. */ return (struct Message *)port->mp_MsgList.lh_Head; -- 2.11.4.GIT