Allow no timer callbacks

Today I again had an application were the only interesting information about a specific FreeRTOS software time is whether it is running or not (blocking a specific path as long as a timeout has not expired). So I don’t need a callback.
But currently the code on expiration in timers.c is

        /* Call the timer callback. */
        traceTIMER_EXPIRED( pxTimer );
        pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer ); 

Instead of

            /* Call the timer callback. */
            traceTIMER_EXPIRED( pxTimer );
            if(pxTimer->pxCallbackFunction != NULL)
            {
                pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer ); 
            }

Which means I need to create an empty function to prevent a crash at that point.
Wouldn’t it be more stable and comfortable, with a very negligible performance impact, to use the later? As soon as there is one timer which doesn’t nee a callback it also saves code space.

If you’re only interested in a timeout maybe it’s better to just use
vTaskSetTimeOutState / xTaskCheckForTimeOut
instead of using a timer (which in turn only makes sense with an associated action ie. callback being set).

2 Likes

You are right, apparently I didn’t see this interface before because it was marked as “only for advanced users”.