Introduce the portSOFTWARE_BARRIER macro which thus far is only used by the Win32 demo to hold execution up in case a simulated interrupt is executing simultaneously. That should never happen as all threads should execute on the same core, but we have had numerous reports that this and other Win32 port changes we have made fixed these issues - although we have not been able to replicate them ourselves.
diff --git a/FreeRTOS/Source/include/FreeRTOS.h b/FreeRTOS/Source/include/FreeRTOS.h index 28668de..c2ebf24 100644 --- a/FreeRTOS/Source/include/FreeRTOS.h +++ b/FreeRTOS/Source/include/FreeRTOS.h
@@ -257,6 +257,10 @@ #define portMEMORY_BARRIER() #endif +#ifndef portSOFTWARE_BARRIER + #define portSOFTWARE_BARRIER() +#endif + /* The timers module relies on xTaskGetSchedulerState(). */ #if configUSE_TIMERS == 1
diff --git a/FreeRTOS/Source/portable/MSVC-MingW/port.c b/FreeRTOS/Source/portable/MSVC-MingW/port.c index 3966331..3c685b9 100644 --- a/FreeRTOS/Source/portable/MSVC-MingW/port.c +++ b/FreeRTOS/Source/portable/MSVC-MingW/port.c
@@ -75,7 +75,7 @@ * attempt to obtain pvInterruptEventMutex if a critical section is used inside * an interrupt handler itself. */ -static volatile BaseType_t xInsideInterrupt = pdFALSE; +volatile BaseType_t xInsideInterrupt = pdFALSE; /* * Called when the process exits to let Windows know the high timer resolution @@ -394,7 +394,7 @@ xInsideInterrupt = pdFALSE; WaitForMultipleObjects( sizeof( pvObjectList ) / sizeof( void * ), pvObjectList, TRUE, INFINITE ); - /* /* Cannot be in a critical section to get here. Tasks that exist a + /* Cannot be in a critical section to get here. Tasks that exist a critical section will block on a yield mutex to wait for an interrupt to process if an interrupt was set pending while the task was inside the critical section. xInsideInterrupt prevents interrupts that contain
diff --git a/FreeRTOS/Source/portable/MSVC-MingW/portmacro.h b/FreeRTOS/Source/portable/MSVC-MingW/portmacro.h index 5f54128..51b96f2 100644 --- a/FreeRTOS/Source/portable/MSVC-MingW/portmacro.h +++ b/FreeRTOS/Source/portable/MSVC-MingW/portmacro.h
@@ -74,6 +74,11 @@ #define portYIELD() vPortGenerateSimulatedInterrupt( portINTERRUPT_YIELD ) + +extern volatile BaseType_t xInsideInterrupt; +#define portSOFTWARE_BARRIER() while( xInsideInterrupt != pdFALSE ) + + /* Simulated interrupts return pdFALSE if no context switch should be performed, or a non-zero number if a context switch should be performed. */ #define portYIELD_FROM_ISR( x ) ( void ) x
diff --git a/FreeRTOS/Source/tasks.c b/FreeRTOS/Source/tasks.c index 5129bf9..2004433 100644 --- a/FreeRTOS/Source/tasks.c +++ b/FreeRTOS/Source/tasks.c
@@ -2113,7 +2113,17 @@ BaseType_t. Please read Richard Barry's reply in the following link to a post in the FreeRTOS support forum before reporting this as a bug! - http://goo.gl/wu4acr */ + + /* portSOFRWARE_BARRIER() is only implemented for emulated/simulated ports that + do not otherwise exhibit real time behaviour. */ + portSOFTWARE_BARRIER(); + + /* The scheduler is suspended if uxSchedulerSuspended is non-zero. An increment + is used to allow calls to vTaskSuspendAll() to nest. */ ++uxSchedulerSuspended; + + /* Enforces ordering for ports and optimised compilers that may otherwise place + the above increment elsewhere. */ portMEMORY_BARRIER(); } /*----------------------------------------------------------*/