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

Add clear() to queue and use isNotEmpty #857

Closed

Conversation

strongly-typed
Copy link
Collaborator

No description provided.

modm::atomic::Queue<T, N>::clear()
{
this->head = 0;
this->tail = 0;
Copy link
Member

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?

Copy link
Collaborator Author

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?

Copy link
Member

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).

Copy link
Member

@chris-durand chris-durand May 3, 2022

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.

@salkinium
Copy link
Member

salkinium commented Jul 24, 2022

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.

@salkinium salkinium closed this Jul 24, 2022
@strongly-typed strongly-typed deleted the feature/queue_clear branch September 2, 2022 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants