Shorten critical section in micros()#552
Conversation
The timer registers have to be read with interrupts disabled. All other computations can be done after interrupts have been enabled again.
|
Memory usage change @ 7b7d61d
Click for full report table
Click for full report CSV |
This comment was marked as resolved.
This comment was marked as resolved.
|
Dear @CLAassistant: As you noticed in your first comment, I have already signed the Contributor License Agreement. Do I really need to sign it multiple times? Will this help this pull request get attention from a human? |
|
Hi @edgar-bonet. Thanks so much for your pull request. I apologize for the inconvenience. We made a small change to the contributor license agreement: https://gist.github.com/ArduinoBot/69c5b68e989a47174b83b2bad2f4ecbf/revisions For this reason, it is necessary for contributors to agree to the CLA once again. I apologize for any inconvenience. Please let me know if you have any questions or concerns. |
|
@per1234: Oh, I see. I guess I was just surprised that @CLAassistant asked for a signature just a few minutes after me signing the CLA. I guess that was just bad timing. Anyway, I just signed it again. I hope @CLAassistant will notice. |
|
I see now. I didn't notice that the comment you were referring to was a new one, as opposed to one that was made at the time you originally submitted the PR. There was a glitch in the CLA Assistant service that caused it to make a redundant comment. The service's code only updates the first comment once the CLA is signed, so this is why the duplicate comment remained with the outdated content. I confirm that we have indeed received your agreement to the CLA. Sorry for any confusion this caused. |
The critical section in
micros()is longer than it needs to be. The interrupt flag register has to be read within the critical section, but testing whether the overflow count should be incremented can be done with interrupts enabled.Without this pull request, compiling for an UNO I get this critical section:
With the pull request applied, this becomes:
which saves us between 2 and 7 cycles of critical section.