jeromecwright wrote on Wednesday, March 08, 2017:
Some of my team have been questioning how thread safe the *fromISR() functions are.
Currently we use these lightweight API calls in some module interfaces in the case that they are called from high priority interrupts.
They also referenced examples 1 and 2 from the lightweight API section here:
http://www.freertos.org/message_passing_performance.html#light
Although these examples seem to be legacy code (Version 4.8 ~ ). It does mention
“We have done nothing between Listing 1 and Listing 2 to ensure interrupt safety. This is therefore still not appropriate usage if the queue is also accessed from an ISR.”
That said, the third example (using the return value to indicate an opportunity to yield) seems to be up to date. And a quick look into the functions save & disable interrupts on entry then restore the register status on exit, which prevents further interrupts. However there is also a critical section in this example placed around the *fromISR() function.
1. Is this third example thread safe? Can it be called from an ISR without the need to create a critical section or manage the thread interactions between queue resources?
I see no reason that the *fromISR() functions cannot be called from tasks as well, just the yield behaviour needs to be managed by the application designer.
2. Is it true that the main difference between the *fromISR() function and the normal API is the control over the yield?
The main reason I would like to do this is for the purpose of re-usability in application code. Having different functions based on whether the queue is being added to from an ISR or a low prio task adds to redundancy, or the need to create wrappers.
Thanks,
Jerome.