-
Notifications
You must be signed in to change notification settings - Fork 148
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
Add clear() to queue and use isNotEmpty #857
Add clear() to queue and use isNotEmpty #857
Conversation
modm::atomic::Queue<T, N>::clear() | ||
{ | ||
this->head = 0; | ||
this->tail = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not interrupt safe though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhmm, would a modm::atomic::Lock l;
improve the situation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but only if clear is called from outside an interrupt. If clear is called inside an interrupt, there's no guarantee that the code outside the interrupt won't write these members back with their tmp
values.
The atomic queue is not truly atomic, it's merely a single-producer, single-consumer queue that works one sided with non-nested interrupts. It's really very AVR specific, and should be rewritten completely for Cortex-M (or better, imported from an existing project).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The single-producer, single-consumer queue in boost lockfree also has a non-thread safe reset()
. It is basically equivalent to the proposed clear()
method.
The proposed uses in the UART interrupts would not work in that case. Not sure if it is a good idea to add it. It could easily be misused.
I'm closing this PR and instead added to my TODO list a task to find a good queue library with a number of different use-cases on Cortex-M/AVR. |
No description provided.