4 years, 6 months ago.

Is there a way to know if your current context is in an ISR?

I wrote a mailbox adapter that wakes up a consumer thread when mail is pushed, however, in certain cases my mailbox can be full before my consumer thread free's the memory. I want to add something in that yields the current thread, so that my consumer thread is able to free up the mailbox before it returns to my production thread. This approach would not be able to work if the production method is called from the ISR, so I only want to do so if we are not in an ISR context. Is there a way to go about checking this?

1 Answer

4 years, 6 months ago.

I saw some exaples where they read the threadID, if it is 0, you are in an ISR.

Accepted Answer

Would you be able to direct me to those examples?

posted by Tom nicetry 27 Oct 2019

ah, nevermind I see it in the ThisThread reference.

'thread ID for reference by other functions or nullptr in case of error or in ISR context.'

is exactly what I need.

posted by Tom nicetry 27 Oct 2019