Embedded_RingBuf_CPP icon indicating copy to clipboard operation
Embedded_RingBuf_CPP copied to clipboard

Breaks inside RB_ATOMIC code block

Open slaff opened this issue 6 years ago • 1 comments

The current RB_ATOMIC_* definitions for ESP8266 look like this

#define RB_ATOMIC_START do { uint32_t _savedIS = xt_rsil(15) ;
#define RB_ATOMIC_END xt_wsr_ps(_savedIS); } while(0);

If I have a code like this one:

do {

RB_ATOMIC_START 
{
     // .. do something
     if(condition) {
                break;
     }
     // .. do something
}
RB_ATOMIC_END

}
while(0)

The break inside the RB_ATOMIC code will be "silenced" and the code will misbehave. Isn't it better to have a definition without do { and } while(9) ?

Related to https://github.com/NicoHood/IRLremote/pull/20

slaff avatar Mar 16 '18 13:03 slaff

Yeah, you are right. If you break inside one of these blocks it will keep interrupts on.

The dev version of the library uses a new way to mask and unmask interrupts: https://github.com/wizard97/SimplyAtomic it takes advantage of gcc's cleanup attribute thing. I believe with the dev version will be able to safely use breaks.

wizard97 avatar Mar 16 '18 16:03 wizard97