From c04b07470701dc147178230e736c53b2bbaf2f6c Mon Sep 17 00:00:00 2001
From: Richard Barry <ribarry@amazon.com>
Date: Fri, 7 Jun 2013 12:16:58 +0000
Subject: [PATCH] Convert the remaining ports to use xTaskIncrementTick() in
 place of vTaskIncremenTick().

---
 FreeRTOS/Source/portable/IAR/STR91x/port.c          |  9 ++-------
 FreeRTOS/Source/portable/MPLAB/PIC18F/port.c        |  5 +----
 FreeRTOS/Source/portable/MPLAB/PIC24_dsPIC/port.c   |  8 ++++----
 .../portable/Paradigm/Tern_EE/large_untested/port.c | 12 +++++++-----
 .../Source/portable/Paradigm/Tern_EE/small/port.c   | 12 +++++++-----
 FreeRTOS/Source/portable/RVDS/ARM7_LPC21xx/port.c   |  2 +-
 .../Source/portable/RVDS/ARM7_LPC21xx/portASM.s     |  4 ++--
 FreeRTOS/Source/portable/RVDS/ARM_CM3/port.c        | 13 +++++--------
 FreeRTOS/Source/portable/RVDS/ARM_CM4F/port.c       | 13 +++++--------
 FreeRTOS/Source/portable/Renesas/RX100/port.c       | 12 ++++--------
 FreeRTOS/Source/portable/Renesas/RX200/port.c       | 12 ++++--------
 FreeRTOS/Source/portable/Renesas/RX600/port.c       | 10 ++++------
 .../Source/portable/Renesas/SH2A_FPU/portasm.src    |  6 +++---
 .../Source/portable/Rowley/MSP430F449/portext.asm   |  2 +-
 FreeRTOS/Source/portable/SDCC/Cygnal/port.c         |  8 +++++---
 FreeRTOS/Source/portable/Softune/MB91460/port.c     |  4 ++--
 FreeRTOS/Source/portable/Softune/MB96340/port.c     |  8 +++++---
 FreeRTOS/Source/portable/Tasking/ARM_CM4F/port.c    | 11 +++++------
 .../portable/WizC/PIC18/Drivers/Tick/isrTick.c      |  5 +----
 .../Source/portable/oWatcom/16BitDOS/Flsh186/port.c | 11 ++++++-----
 FreeRTOS/Source/portable/oWatcom/16BitDOS/PC/port.c | 11 ++++++-----
 21 files changed, 80 insertions(+), 98 deletions(-)

diff --git a/FreeRTOS/Source/portable/IAR/STR91x/port.c b/FreeRTOS/Source/portable/IAR/STR91x/port.c
index 24f3f4ef4..6be44ea15 100644
--- a/FreeRTOS/Source/portable/IAR/STR91x/port.c
+++ b/FreeRTOS/Source/portable/IAR/STR91x/port.c
@@ -415,16 +415,11 @@ keyword. */
 		TIM2->OC1R += s_nPulseLength;
 		
 		/* Increment the tick counter. */
-		vTaskIncrementTick();
-		
-		#if configUSE_PREEMPTION == 1
+		if( xTaskIncrementTick() != pdFALSE )
 		{
-			/* The new tick value might unblock a task.  Ensure the highest task that
-			is ready to execute is the task that will execute when the tick ISR
-			exits. */
+			/* Select a new task to run. */
 			vTaskSwitchContext();
 		}
-		#endif
 		
 		/* Clear the interrupt in the watchdog. */
 		TIM2->SR &= ~TIM_FLAG_OC1;
diff --git a/FreeRTOS/Source/portable/MPLAB/PIC18F/port.c b/FreeRTOS/Source/portable/MPLAB/PIC18F/port.c
index 6c8f28d36..44d540e08 100644
--- a/FreeRTOS/Source/portable/MPLAB/PIC18F/port.c
+++ b/FreeRTOS/Source/portable/MPLAB/PIC18F/port.c
@@ -611,14 +611,11 @@ static void prvTickISR( void )
 	PIR1bits.CCP1IF = 0;
 
 	/* Maintain the tick count. */
-	vTaskIncrementTick();
-
-	#if configUSE_PREEMPTION == 1
+	if( xTaskIncrementTick() != pdFALSE )
 	{
 		/* Switch to the highest priority task that is ready to run. */
 		vTaskSwitchContext();
 	}
-	#endif
 
 	portRESTORE_CONTEXT();
 }
diff --git a/FreeRTOS/Source/portable/MPLAB/PIC24_dsPIC/port.c b/FreeRTOS/Source/portable/MPLAB/PIC24_dsPIC/port.c
index d67b42520..afaf56189 100644
--- a/FreeRTOS/Source/portable/MPLAB/PIC24_dsPIC/port.c
+++ b/FreeRTOS/Source/portable/MPLAB/PIC24_dsPIC/port.c
@@ -358,9 +358,9 @@ void __attribute__((__interrupt__, auto_psv)) _T1Interrupt( void )
 	/* Clear the timer interrupt. */
 	IFS0bits.T1IF = 0;
 
-	vTaskIncrementTick();
-
-	#if configUSE_PREEMPTION == 1
+	if( xTaskIncrementTick() != pdFALSE )
+	{
 		portYIELD();
-	#endif
+	}
 }
+
diff --git a/FreeRTOS/Source/portable/Paradigm/Tern_EE/large_untested/port.c b/FreeRTOS/Source/portable/Paradigm/Tern_EE/large_untested/port.c
index caf5ab44e..49577a52b 100644
--- a/FreeRTOS/Source/portable/Paradigm/Tern_EE/large_untested/port.c
+++ b/FreeRTOS/Source/portable/Paradigm/Tern_EE/large_untested/port.c
@@ -220,10 +220,11 @@ is being used. */
 	static void __interrupt __far prvPreemptiveTick( void )
 	{
 		/* Get the scheduler to update the task states following the tick. */
-		vTaskIncrementTick();
-
-		/* Switch in the context of the next task to be run. */
-		portSWITCH_CONTEXT();
+		if( xTaskIncrementTick() != pdFALSE )
+		{
+			/* Switch in the context of the next task to be run. */
+			portSWITCH_CONTEXT();
+		}
 
 		/* Reset interrupt. */
 		outport( portEIO_REGISTER, portCLEAR_INTERRUPT );
@@ -233,7 +234,8 @@ is being used. */
 	{
 		/* Same as preemptive tick, but the cooperative scheduler is being used
 		so we don't have to switch in the context of the next task. */
-		vTaskIncrementTick();
+		xTaskIncrementTick();
+		
 		/* Reset interrupt. */
 		outport( portEIO_REGISTER, portCLEAR_INTERRUPT );
 	}
diff --git a/FreeRTOS/Source/portable/Paradigm/Tern_EE/small/port.c b/FreeRTOS/Source/portable/Paradigm/Tern_EE/small/port.c
index 7b3e85c2d..c093e465f 100644
--- a/FreeRTOS/Source/portable/Paradigm/Tern_EE/small/port.c
+++ b/FreeRTOS/Source/portable/Paradigm/Tern_EE/small/port.c
@@ -204,10 +204,11 @@ is being used. */
 	static void __interrupt __far prvPreemptiveTick( void )
 	{
 		/* Get the scheduler to update the task states following the tick. */
-		vTaskIncrementTick();
-
-		/* Switch in the context of the next task to be run. */
-		portEND_SWITCHING_ISR();
+		if( xTaskIncrementTick() != pdFALSE )
+		{
+			/* Switch in the context of the next task to be run. */
+			portEND_SWITCHING_ISR();
+		}
 
 		/* Reset interrupt. */
 		outport( portEIO_REGISTER, portCLEAR_INTERRUPT );
@@ -217,7 +218,8 @@ is being used. */
 	{
 		/* Same as preemptive tick, but the cooperative scheduler is being used
 		so we don't have to switch in the context of the next task. */
-		vTaskIncrementTick();
+		xTaskIncrementTick();
+		
 		/* Reset interrupt. */
 		outport( portEIO_REGISTER, portCLEAR_INTERRUPT );
 	}
diff --git a/FreeRTOS/Source/portable/RVDS/ARM7_LPC21xx/port.c b/FreeRTOS/Source/portable/RVDS/ARM7_LPC21xx/port.c
index 088303ccf..a8c8f5d38 100644
--- a/FreeRTOS/Source/portable/RVDS/ARM7_LPC21xx/port.c
+++ b/FreeRTOS/Source/portable/RVDS/ARM7_LPC21xx/port.c
@@ -236,7 +236,7 @@ void vPortEndScheduler( void )
 	{
 		/* Increment the tick count - this may make a delaying task ready
 		to run - but a context switch is not performed. */		
-		vTaskIncrementTick();
+		xTaskIncrementTick();
 
 		T0IR = portTIMER_MATCH_ISR_BIT;				/* Clear the timer event */
 		VICVectAddr = portCLEAR_VIC_INTERRUPT;		/* Acknowledge the Interrupt */
diff --git a/FreeRTOS/Source/portable/RVDS/ARM7_LPC21xx/portASM.s b/FreeRTOS/Source/portable/RVDS/ARM7_LPC21xx/portASM.s
index f146bbe94..95995e360 100644
--- a/FreeRTOS/Source/portable/RVDS/ARM7_LPC21xx/portASM.s
+++ b/FreeRTOS/Source/portable/RVDS/ARM7_LPC21xx/portASM.s
@@ -54,7 +54,7 @@
 	INCLUDE portmacro.inc
 
 	IMPORT	vTaskSwitchContext
-	IMPORT	vTaskIncrementTick
+	IMPORT	xTaskIncrementTick
 
 	EXPORT	vPortYieldProcessor
 	EXPORT	vPortStartFirstTask
@@ -127,7 +127,7 @@ vPreemptiveTick
 
 	portSAVE_CONTEXT					; Save the context of the current task.	
 
-	LDR R0, =vTaskIncrementTick			; Increment the tick count.  
+	LDR R0, =xTaskIncrementTick			; Increment the tick count.  
 	MOV LR, PC							; This may make a delayed task ready
 	BX R0								; to run.
 	
diff --git a/FreeRTOS/Source/portable/RVDS/ARM_CM3/port.c b/FreeRTOS/Source/portable/RVDS/ARM_CM3/port.c
index c721f1fe3..78161f51b 100644
--- a/FreeRTOS/Source/portable/RVDS/ARM_CM3/port.c
+++ b/FreeRTOS/Source/portable/RVDS/ARM_CM3/port.c
@@ -325,13 +325,6 @@ __asm void xPortPendSVHandler( void )
 
 void xPortSysTickHandler( void )
 {
-	#if configUSE_PREEMPTION == 1
-	{
-		/* If using preemption, also force a context switch. */
-		portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;
-	}
-	#endif
-
 	/* Only reset the systick load register if configUSE_TICKLESS_IDLE is set to
 	1.  If it is set to 0 tickless idle is not being used.  If it is set to a
 	value other than 0 or 1 then a timer other than the SysTick is being used
@@ -342,7 +335,11 @@ void xPortSysTickHandler( void )
 
 	( void ) portSET_INTERRUPT_MASK_FROM_ISR();
 	{
-		vTaskIncrementTick();
+		if( xTaskIncrementTick() != pdFALSE )
+		{
+			/* Pend a context switch. */
+			portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;
+		}
 	}
 	portCLEAR_INTERRUPT_MASK_FROM_ISR( 0 );
 }
diff --git a/FreeRTOS/Source/portable/RVDS/ARM_CM4F/port.c b/FreeRTOS/Source/portable/RVDS/ARM_CM4F/port.c
index 345f386bf..69a1111b3 100644
--- a/FreeRTOS/Source/portable/RVDS/ARM_CM4F/port.c
+++ b/FreeRTOS/Source/portable/RVDS/ARM_CM4F/port.c
@@ -388,13 +388,6 @@ __asm void xPortPendSVHandler( void )
 
 void xPortSysTickHandler( void )
 {
-	#if configUSE_PREEMPTION == 1
-	{
-		/* If using preemption, also force a context switch. */
-		portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;
-	}
-	#endif
-
 	/* Only reset the systick load register if configUSE_TICKLESS_IDLE is set to
 	1.  If it is set to 0 tickless idle is not being used.  If it is set to a
 	value other than 0 or 1 then a timer other than the SysTick is being used
@@ -405,7 +398,11 @@ void xPortSysTickHandler( void )
 
 	( void ) portSET_INTERRUPT_MASK_FROM_ISR();
 	{
-		vTaskIncrementTick();
+		if( xTaskIncrementTick() != pdFALSE )
+		{
+			/* Pend a context switch. */
+			portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;
+		}
 	}
 	portCLEAR_INTERRUPT_MASK_FROM_ISR( 0 );
 }
diff --git a/FreeRTOS/Source/portable/Renesas/RX100/port.c b/FreeRTOS/Source/portable/Renesas/RX100/port.c
index 7026dff16..06edb0e79 100644
--- a/FreeRTOS/Source/portable/Renesas/RX100/port.c
+++ b/FreeRTOS/Source/portable/Renesas/RX100/port.c
@@ -350,17 +350,13 @@ void prvTickISR( void )
 	necessitates. */
 	set_ipl( configMAX_SYSCALL_INTERRUPT_PRIORITY );
 	{
-		vTaskIncrementTick();
+		if( xTaskIncrementTick() != pdFALSE )
+		{
+			taskYIELD();
+		}
 	}
 	set_ipl( configKERNEL_INTERRUPT_PRIORITY );
 
-	/* Only select a new task if the preemptive scheduler is being used. */
-	#if( configUSE_PREEMPTION == 1 )
-	{
-		taskYIELD();
-	}
-	#endif
-
 	#if configUSE_TICKLESS_IDLE == 1
 	{
 		/* The CPU woke because of a tick. */
diff --git a/FreeRTOS/Source/portable/Renesas/RX200/port.c b/FreeRTOS/Source/portable/Renesas/RX200/port.c
index e276426e4..896f1ae73 100644
--- a/FreeRTOS/Source/portable/Renesas/RX200/port.c
+++ b/FreeRTOS/Source/portable/Renesas/RX200/port.c
@@ -267,16 +267,12 @@ void vTickISR( void )
 	necessitates. */
 	set_ipl( configMAX_SYSCALL_INTERRUPT_PRIORITY );
 	{
-		vTaskIncrementTick();
+		if( xTaskIncrementTick() != pdFALSE )
+		{
+			taskYIELD();
+		}
 	}
 	set_ipl( configKERNEL_INTERRUPT_PRIORITY );
-	
-	/* Only select a new task if the preemptive scheduler is being used. */
-	#if( configUSE_PREEMPTION == 1 )
-	{
-		taskYIELD();
-	}
-	#endif
 }
 /*-----------------------------------------------------------*/
 
diff --git a/FreeRTOS/Source/portable/Renesas/RX600/port.c b/FreeRTOS/Source/portable/Renesas/RX600/port.c
index 2a0c2bff5..cb8792633 100644
--- a/FreeRTOS/Source/portable/Renesas/RX600/port.c
+++ b/FreeRTOS/Source/portable/Renesas/RX600/port.c
@@ -268,14 +268,12 @@ void vTickISR( void )
 	necessitates. */
 	set_ipl( configMAX_SYSCALL_INTERRUPT_PRIORITY );
 	{
-		vTaskIncrementTick();
+		if( xTaskIncrementTick() != pdFALSE )
+		{
+			taskYIELD();
+		}
 	}
 	set_ipl( configKERNEL_INTERRUPT_PRIORITY );
-
-	/* Only select a new task if the preemptive scheduler is being used. */
-	#if( configUSE_PREEMPTION == 1 )
-		taskYIELD();
-	#endif
 }
 /*-----------------------------------------------------------*/
 
diff --git a/FreeRTOS/Source/portable/Renesas/SH2A_FPU/portasm.src b/FreeRTOS/Source/portable/Renesas/SH2A_FPU/portasm.src
index 111410162..33933e661 100644
--- a/FreeRTOS/Source/portable/Renesas/SH2A_FPU/portasm.src
+++ b/FreeRTOS/Source/portable/Renesas/SH2A_FPU/portasm.src
@@ -53,7 +53,7 @@
 
 	.import _pxCurrentTCB
 	.import _vTaskSwitchContext
-	.import _vTaskIncrementTick
+	.import _xTaskIncrementTick
 
 	.export _vPortStartFirstTask
 	.export _ulPortGetGBR
@@ -89,7 +89,7 @@ _vPortPreemptiveTick
 
 	portSAVE_CONTEXT
 	
-	mov.l	#_vTaskIncrementTick, r0
+	mov.l	#_xTaskIncrementTick, r0
 	jsr		@r0
 	nop
 
@@ -105,7 +105,7 @@ _vPortCooperativeTick
 
 	portSAVE_CONTEXT
 	
-	mov.l	#_vTaskIncrementTick, r0
+	mov.l	#_xTaskIncrementTick, r0
 	jsr		@r0
 	nop
 
diff --git a/FreeRTOS/Source/portable/Rowley/MSP430F449/portext.asm b/FreeRTOS/Source/portable/Rowley/MSP430F449/portext.asm
index 1d27d00c1..85c9421ac 100644
--- a/FreeRTOS/Source/portable/Rowley/MSP430F449/portext.asm
+++ b/FreeRTOS/Source/portable/Rowley/MSP430F449/portext.asm
@@ -89,7 +89,7 @@
 _vTickISR:
 		portSAVE_CONTEXT
 				
-		call	#_vTaskIncrementTick
+		call	#_xTaskIncrementTick
 
 		#if configUSE_PREEMPTION == 1
 			call	#_vTaskSwitchContext
diff --git a/FreeRTOS/Source/portable/SDCC/Cygnal/port.c b/FreeRTOS/Source/portable/SDCC/Cygnal/port.c
index eecf4969e..d087f4a78 100644
--- a/FreeRTOS/Source/portable/SDCC/Cygnal/port.c
+++ b/FreeRTOS/Source/portable/SDCC/Cygnal/port.c
@@ -405,8 +405,10 @@ void vPortYield( void ) _naked
 		portSAVE_CONTEXT();
 		portCOPY_STACK_TO_XRAM();
 
-		vTaskIncrementTick();
-		vTaskSwitchContext();
+		if( xTaskIncrementTick() != pdFALSE )
+		{
+			vTaskSwitchContext();
+		}
 		
 		portCLEAR_INTERRUPT_FLAG();
 		portCOPY_XRAM_TO_STACK();
@@ -418,7 +420,7 @@ void vPortYield( void ) _naked
 		/* When using the cooperative scheduler the timer 2 ISR is only 
 		required to increment the RTOS tick count. */
 
-		vTaskIncrementTick();
+		xTaskIncrementTick();
 		portCLEAR_INTERRUPT_FLAG();
 	}
 #endif
diff --git a/FreeRTOS/Source/portable/Softune/MB91460/port.c b/FreeRTOS/Source/portable/Softune/MB91460/port.c
index c4163cc79..12cef3d7b 100644
--- a/FreeRTOS/Source/portable/Softune/MB91460/port.c
+++ b/FreeRTOS/Source/portable/Softune/MB91460/port.c
@@ -292,7 +292,7 @@ const unsigned short usReloadValue = ( unsigned short ) ( ( ( configPER_CLOCK_HZ
 	LDI #_tmcsr0, R0
 	AND R1,@R0								;Clear RLT0 interrupt flag
 
-	CALL32	 _vTaskIncrementTick,R12		;Increment Tick
+	CALL32	 _xTaskIncrementTick,R12		;Increment Tick
 	CALL32	 _vTaskSwitchContext,R12		;Switch context if required
 
 	ANDCCR #0xEF							;Disable Interrupts
@@ -314,7 +314,7 @@ const unsigned short usReloadValue = ( unsigned short ) ( ( ( configPER_CLOCK_HZ
 	{
 		/* Clear RLT0 interrupt flag */
 		TMCSR0_UF = 0; 
-		vTaskIncrementTick();
+		xTaskIncrementTick();
 	}
 
 #endif
diff --git a/FreeRTOS/Source/portable/Softune/MB96340/port.c b/FreeRTOS/Source/portable/Softune/MB96340/port.c
index 852d2c1dd..f902514ff 100644
--- a/FreeRTOS/Source/portable/Softune/MB96340/port.c
+++ b/FreeRTOS/Source/portable/Softune/MB96340/port.c
@@ -474,8 +474,10 @@ void vPortEndScheduler( void )
 		
 		/* Increment the tick count then switch to the highest priority task
 		that is ready to run. */
-		vTaskIncrementTick();
-		vTaskSwitchContext();
+		if( xTaskIncrementTick() != pdFALSE )
+		{
+			vTaskSwitchContext();
+		}
 
 		/* Disable interrupts so that portRESTORE_CONTEXT() is not interrupted */
 		__DI();
@@ -499,7 +501,7 @@ void vPortEndScheduler( void )
 		/* Clear RLT0 interrupt flag */
 		TMCSR0_UF = 0;  
 		
-		vTaskIncrementTick();
+		xTaskIncrementTick();
 	}
 
 #endif
diff --git a/FreeRTOS/Source/portable/Tasking/ARM_CM4F/port.c b/FreeRTOS/Source/portable/Tasking/ARM_CM4F/port.c
index fe4b582b1..cdadbe120 100644
--- a/FreeRTOS/Source/portable/Tasking/ARM_CM4F/port.c
+++ b/FreeRTOS/Source/portable/Tasking/ARM_CM4F/port.c
@@ -237,14 +237,13 @@ void SysTick_Handler( void )
 {
 unsigned long ulDummy;
 
-	/* If using preemption, also force a context switch. */
-	#if configUSE_PREEMPTION == 1
-		*(portNVIC_INT_CTRL) = portNVIC_PENDSVSET;
-	#endif
-
 	ulDummy = portSET_INTERRUPT_MASK_FROM_ISR();
 	{
-		vTaskIncrementTick();
+		if( xTaskIncrementTick() != pdFALSE )
+		{
+			/* Pend a context switch. */
+			*(portNVIC_INT_CTRL) = portNVIC_PENDSVSET;
+		}
 	}
 	portCLEAR_INTERRUPT_MASK_FROM_ISR( ulDummy );
 }
diff --git a/FreeRTOS/Source/portable/WizC/PIC18/Drivers/Tick/isrTick.c b/FreeRTOS/Source/portable/WizC/PIC18/Drivers/Tick/isrTick.c
index 85fc11ee4..9dabd621a 100644
--- a/FreeRTOS/Source/portable/WizC/PIC18/Drivers/Tick/isrTick.c
+++ b/FreeRTOS/Source/portable/WizC/PIC18/Drivers/Tick/isrTick.c
@@ -109,9 +109,7 @@ Changes from V3.0.1
 		/*
 	 	 * Maintain the tick count.
 	 	 */
-		vTaskIncrementTick();
-		
-		#if configUSE_PREEMPTION == 1
+		if( xTaskIncrementTick() != pdFALSE )
 		{
 			/*
 		 	 * Ask for a switch to the highest priority task
@@ -119,7 +117,6 @@ Changes from V3.0.1
 		 	 */
 			uxSwitchRequested = pdTRUE;
 		}
-		#endif
 	}
 }
 
diff --git a/FreeRTOS/Source/portable/oWatcom/16BitDOS/Flsh186/port.c b/FreeRTOS/Source/portable/oWatcom/16BitDOS/Flsh186/port.c
index 33b5844c8..051aaaf82 100644
--- a/FreeRTOS/Source/portable/oWatcom/16BitDOS/Flsh186/port.c
+++ b/FreeRTOS/Source/portable/oWatcom/16BitDOS/Flsh186/port.c
@@ -197,10 +197,11 @@ kernel is being used. */
 	static void __interrupt __far prvPreemptiveTick( void )
 	{
 		/* Get the scheduler to update the task states following the tick. */
-		vTaskIncrementTick();
-
-		/* Switch in the context of the next task to be run. */
-		portSWITCH_CONTEXT();
+		if( xTaskIncrementTick() != pdFALSE )
+		{
+			/* Switch in the context of the next task to be run. */
+			portSWITCH_CONTEXT();
+		}
 
 		/* Reset the PIC ready for the next time. */
 		portRESET_PIC();
@@ -210,7 +211,7 @@ kernel is being used. */
 	{
 		/* Same as preemptive tick, but the cooperative scheduler is being used
 		so we don't have to switch in the context of the next task. */
-		vTaskIncrementTick();
+		xTaskIncrementTick();
 		portRESET_PIC();
 	}
 #endif
diff --git a/FreeRTOS/Source/portable/oWatcom/16BitDOS/PC/port.c b/FreeRTOS/Source/portable/oWatcom/16BitDOS/PC/port.c
index 930981c6a..d6557ef2c 100644
--- a/FreeRTOS/Source/portable/oWatcom/16BitDOS/PC/port.c
+++ b/FreeRTOS/Source/portable/oWatcom/16BitDOS/PC/port.c
@@ -228,10 +228,11 @@ is being used. */
 	static void __interrupt __far prvPreemptiveTick( void )
 	{
 		/* Get the scheduler to update the task states following the tick. */
-		vTaskIncrementTick();
-
-		/* Switch in the context of the next task to be run. */
-		portSWITCH_CONTEXT();
+		if( xTaskIncrementTick() != pdFALSE )
+		{
+			/* Switch in the context of the next task to be run. */
+			portSWITCH_CONTEXT();
+		}
 
 		/* Reset the PIC ready for the next time. */
 		prvPortResetPIC();
@@ -241,7 +242,7 @@ is being used. */
 	{
 		/* Same as preemptive tick, but the cooperative scheduler is being used
 		so we don't have to switch in the context of the next task. */
-		vTaskIncrementTick();
+		xTaskIncrementTick();
 		prvPortResetPIC();
 	}
 #endif