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;
}