-
Notifications
You must be signed in to change notification settings - Fork 459
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
[WIP] Add push/pop lockless #363
base: master
Are you sure you want to change the base?
Conversation
/// assert_eq!(q.push(10), Ok(())); | ||
/// assert_eq!(q.push(20), Err(PushError(20))); | ||
/// ``` | ||
pub fn push_lockless(&self, value: T) -> Result<(), PushError<T>> { |
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 code is very much similar to push()
. Do you think can we somehow merge the code of the two functions?
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, I did think this and tried to merge them. Unfortunately it made the tests hang... So I will have another go at that when I have time. Before it is merged that should be done though.
@Restioson I have a high-level question about your use case with interrupts pushing keyboard events into the queue. So if your interrupt handler is defined like this: fn handler(event: KeyboardEvent) {
queue.push(event);
} What happens if an event handler (call it A) is interrupted before That sounds wrong to me so I wonder how keyboard drivers handle situations like these? Are you sure this is the way to go? My guess would be that event handlers shouldn't be interruptable and maybe the hardware guarantees so, but I've no idea if what I'm saying is true. |
Yes, interrupt handlers cannot be interrupted (interrupts are disabled by the os). This is because if nesting is allowed, excessive nesting depth could cause a stackoverflow. However, the local APIC is able to buffer one IRQ to be dispatched if the cpu has disabled interrupts, which will be dispatched when the cpu re-enables them. I do believe that I still need the function though, for instance in case the push interrupts a pop from the handler. And nevertheless, it could be useful for others. |
@Restioson Thanks for clarifying! And just a couple more questions to see if I understood the problem domain correctly:
|
|
In that case, the way to go would really be #338, which is ~5 times faster than It's unfortunate that the SPSC queue cannot be used in your use case without |
Aren't those slated to be removed? Perhaps a RefCell. I will consider it though. Do you still think that this has a use case? |
Possibly -- I'm not sure. The alternative to
I don't think so. The SPSC queue is really designed to be wait-free and applicable in embedded systems, device drivers, and similar use cases. Others queues are a bit more high-level and can't provide strong progress guarantees without jumping through hoops or having tricky caveats. |
Sorry, I haven't had much time to work on this because of exams... I will get back to it when they are finished though. |
This PR will add non-deadlocking push/pop operations to queues -- they will never deadlock even if a concurrent push/pop stalls for whatever reason indefinitely.