# Patch for missing #if in tasks.c

**URL:** <https://forums.freertos.org/t/patch-for-missing-if-in-tasks-c/471>\
**Category:** Kernel\
**Created:** [May 30, 2011, 8:09am UTC](https://forums.freertos.org/t/patch-for-missing-if-in-tasks-c/471 "2011-05-30T08:09:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 30, 2011, 8:09am UTC](https://forums.freertos.org/t/patch-for-missing-if-in-tasks-c/471/1 "2011-05-30T08:09:55Z")

</div>

**[pmunts](https://sourceforge.net/u/pmunts/)** wrote on [Monday, May 30, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/186d0407/#176d):

tasks.c is missing #if ( configGENERATE\_RUN\_TIME\_STATS == 1 ) bracketing the call to portCONFIGURE\_TIMER\_FOR\_RUN\_TIME\_STATS() at line 1122.

– tasks.c (revision 2690)  
+++ tasks.c (revision 2692)  
@@ -1116,11 +1116,13 @@  
xSchedulerRunning = pdTRUE;  
xTickCount = ( portTickType ) 0;

+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #if ( configGENERATE\_RUN\_TIME\_STATS == 1 )  
/\* If configGENERATE\_RUN\_TIME\_STATS is defined then the following  
macro must be defined to configure the timer/counter used to generate  
the run time counter time base. \*/  
portCONFIGURE\_TIMER\_FOR\_RUN\_TIME\_STATS();  
-  
+ #endif  
+  
/\* Setting up the timer tick is hardware specific and thus in the  
portable interface. \*/  
if( xPortStartScheduler() )

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [May 30, 2011, 8:54am UTC](https://forums.freertos.org/t/patch-for-missing-if-in-tasks-c/471/2 "2011-05-30T08:54:38Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, May 30, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/186d0407/#7ee4):

I don’t understand this patch and can only assume you are using an old version of FreeRTOS or have modified the code yourself.&nbsp; If an #endif was missing, nothing would compile, surely?

The code between lines 1104 and 1135 looks like this, there are no conditional compilations.

```
	if( xReturn == pdPASS )
	{
		/* Interrupts are turned off here, to ensure a tick does not occur
		before or during the call to xPortStartScheduler(). The stacks of
		the created tasks contain a status word with interrupts switched on
		so interrupts will automatically get re-enabled when the first task
		starts to run.
		STEPPING THROUGH HERE USING A DEBUGGER CAN CAUSE BIG PROBLEMS IF THE
		DEBUGGER ALLOWS INTERRUPTS TO BE PROCESSED. */
		portDISABLE_INTERRUPTS();
		xSchedulerRunning = pdTRUE;
		xTickCount = ( portTickType ) 0;
		/* If configGENERATE_RUN_TIME_STATS is defined then the following
		macro must be defined to configure the timer/counter used to generate
		the run time counter time base. */
		portCONFIGURE_TIMER_FOR_RUN_TIME_STATS();
		
		/* Setting up the timer tick is hardware specific and thus in the
		portable interface. */
		if( xPortStartScheduler() )
		{
			/* Should not reach here as if the scheduler is running the
			function will not return. */
		}
		else
		{
			/* Should only reach here if a task calls xTaskEndScheduler(). */
		}
	}

```

regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 30, 2011, 10:50am UTC](https://forums.freertos.org/t/patch-for-missing-if-in-tasks-c/471/3 "2011-05-30T10:50:22Z")

</div>

**[pmunts](https://sourceforge.net/u/pmunts/)** wrote on [Monday, May 30, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/186d0407/#fd19):

I am using 7.0.1.&nbsp; It is the added #if that is the key thing, not a missing #endif.&nbsp; You should not try to call portCONFIGURE\_TIMER\_FOR\_RUN\_TIME\_STATS() (which is at tasks.c line 1122) if configGENERATE\_RUN\_TIME\_STATS is not defined.&nbsp; Of course, defining portCONFIGURE\_TIMER\_FOR\_RUN\_TIME\_STATS as a null macro in FreeRTOSConfig.h works just as well, but it seems cleaner to me not to try to call it in the first place.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 30, 2011, 12:59pm UTC](https://forums.freertos.org/t/patch-for-missing-if-in-tasks-c/471/4 "2011-05-30T12:59:39Z")

</div>

**[davedoors](https://sourceforge.net/u/davedoors/)** wrote on [Monday, May 30, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/186d0407/#ed74):

If portCONFIGURE\_TIMER\_FOR\_RUN\_TIME\_STATS() is not defined then it will get automatically removed by code in FreeRTOS.h

```
#ifndef portCONFIGURE_TIMER_FOR_RUN_TIME_STATS
	#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()
#endif

```

If you have a problem compiling then it is likely the header files are not included in the correct order, although it should not be a problem compiling tasks.c. Have you made **any** changes to the code?
