Ticker ISR context not returing nullptr when calling ThisThread::get_id()

Hi,

I’ve designed a producer/consumer system that yields a thread if a consumers queue is full. Obviously, I can only do this if I am not producing in an ISR context, so I check for this before yielding.

The mbed-os-5.15 documentation says this:

where it specifies that nullptr is returned if in ISR context.

Simple enough right? Well I am doing some testing to ensure things work correctly and I noticed I was getting an MBED OS ERROR 306, Not allowed in ISR context.

This appears to be occurring because I am yielding an ISR.

I then wanted to validate that the ThisThread::get_id() call was actually returning nullptr in my ticker callback function, and it was not!

Is a ticker ISR’s thread id a special case where it is not considered to be in ISR context? Any help would be appreciated.

This is a snippet of my code where I try allocating memory from Mail, and yield the calling thread (the producer) if we are not in ISR context:

template<typename T, uint32_t queue_sz>
T* MailManager<T, queue_sz>::alloc() {
    if (_callback == nullptr) return nullptr;
    T* mail;

    // yield this thread so consumer thread (_thread) can empty mailbox before
    // putting more mail in, only do this if not in ISR, get_id returns nullptr

    if (ThisThread::get_id() != nullptr) {
        while ((mail = _mailbox.alloc()) == nullptr) {
            ThisThread::yield();
        }
    }
    else {
        mail = _mailbox.alloc();
    }
    return mail;
}

Hello,

I am also trying to use the ThisThread::get_id() to determine if a call to a function is made at ISR context or at Thread context.

However, it appears that the documentation for ThisThread::get_id() is incorrect and that it does not return nullptr when called from an ISR.

I have confirmed that for the Ticker attached callback and the InterruptIn attached callback, ThisThread::get_id() is not returning nullptr.

Regards,
Andrew.

This test on MBED 6.14 on Nucleo STM32F429I target.

Just to follow up on this issue, I was able to use IsIrqMode(), which worked for my use case (still on mbed -os-5.15)