Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maybe a race condition!? #5

Closed
imla opened this issue Jan 23, 2021 · 1 comment
Closed

maybe a race condition!? #5

imla opened this issue Jan 23, 2021 · 1 comment

Comments

@imla
Copy link

imla commented Jan 23, 2021

in file IRsmallDecoder.h not sure but I think it is better to reverse the order of below lines!!

91 _irCopyingData=false; //an ATOMIC_BLOCK would be better, but it's not supported on many boards
92 _irDataAvailable=false;

@LuisMiCa
Copy link
Owner

Yes, there is an issue there, it's not critical but it creates the possibility of an undefined behavior:

A) If the Interrupt Service Routine interrupts right before the _irDataAvailable=false; while been triggered by the final bit of a valid IR signal, it will set _irDataAvailable to TRUE and, right after the end of the ISR, that variable will be set to FALSE. Effectively discarding that newly received signal and proceeding with the previously received signal.

B) If that interruption happens right after the _irDataAvailable=false;, it will change that variable to TRUE, signalling that there is already a new signal ready to be retrieved. The next time the dataAvailable() method is called, it will retrieve that new signal (if it wasn't already discarded by another signal).

The chances of getting any of these possibilities are very slim and the worst consequence is the discarding of signals. Something that may happen anyway if the duration of the main program loop is longer than the signal repetition period (more than 100ms in most cases).

So, by switching the order of the two lines you mentioned, the decoder behaviour will become more deterministic. I will make sure to include this change in the next update (I'm not sure when that will be).

Thank you for your suggestion

LuisMiCa added a commit that referenced this issue Jan 15, 2022
Solves Issue #5.
There was a very small possibility of some codes being dismissed when
the main loop took as long as the decoder took to receive a full code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants