Paul, I'm merging in changes from TeensyDuino 1.20 release for Teensy 3.x into my baseline code.. I saw that there is new yield.cpp code. There was a comment in that code that asked if it needed to be atomic. Maybe the code doesn't absolutely need to be atomic depending on how perfectly reentrant the serial code is that gets called. But since it's easier to be safe why not avoid the question? It's an easy/efficient fix to do it right as per reworked version I did.
Hey, I have to say I really appreciate how good your code is. Too many people write less than stellar code these days.
Hey, I have to say I really appreciate how good your code is. Too many people write less than stellar code these days.
Code:
void yield(void) __attribute__ ((weak));
void yield(void)
{
#ifdef ORIGINAL
static uint8_t running=0;
if (running) return; // TODO: does this need to be atomic?
running = 1;
if (Serial.available()) serialEvent();
if (Serial1.available()) serialEvent1();
if (Serial2.available()) serialEvent2();
if (Serial3.available()) serialEvent3();
running = 0;
#else /* NEW VERSION */
static bool running=false;
bool was_running;
__disable_irq();
was_running = running;
running = true;
__enable_irq();
if (was_running) return;
if (Serial.available()) serialEvent();
if (Serial1.available()) serialEvent1();
if (Serial2.available()) serialEvent2();
if (Serial3.available()) serialEvent3();
running = false;
#endif /* FIXED */
};