-
Notifications
You must be signed in to change notification settings - Fork 177
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
Don't hold lock in input_intercept
callback and don't expose xkb::
types in safe API
#1533
Conversation
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.
Seems sensible, this deadlock has been bugging me a lot.
Hopefully we can improve things here more in the future, since none of this seems perfect, but the changes here at least clean up confusing behavior in the API around mutex locking (and the technical soundness issue of providing safe xkb accessors) without any significant change to the API. |
It's cleaner to make the `unsafe impl Send` more fine-grained, and this should help with some future changes. Since `XkbContextHandler` is public, this fixes a soundness issue in the public API, since it was possible with a safe call to get an `xkb::Keymap` and `xkb::State`, and clone those. Potentially violating the safety assumption of the `Send` implementation.
Using composition like this seems like a cleaner solution than a trait with default implementations.
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.
Needs a rebase, but other than that, I'd say this is ready to go.
It is definitely an improvement over the current state of things.
Holding a mutex during the callback causes a deadlock if something invoked by the callback tries to call a `KeyboardHandle` method. Or if the callback locks another mutex, which in another thread may be held while the keyboard mutex is locked. This is bad, and the mutex here should generally be a hidden implementation detail. Or if absolutely necessarily this restriction should be documented. This requirements to make this work aren't ideal, but probably aren't a problem. We have to create a copy of `mods_state` on the stack. `Xkb` needs to be store in an `Arc<Mutex<_>>` for finer-grained locking. And `modified_syms()` and `raw_syms()` need to return `Vec`s instead of slices. The `Vec`s could be changed back to slices in the type signatures if we used `OnceCell` to cache the return value, but that probably doesn't matter that much in practice.
No longer needed now that this isn't part of a trait.
See commits messages for descriptions of the changes here. The last commit is potentially more controversial than the earlier ones; if it's an issue, I think the
Xkb
changes in the others are a good improvement at least.