-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
Export low-level common interfaces for mutex, condvar, etc. #68163
Comments
What's your use case for this? These APIs might be replaced in the future, and libstd might stop using OS primitives for this completely. |
The // Just like the std::sync:Mutex.
struct Mutex<T> {
sys_mutex: ...,
cell: UnsafeCell<T>
}
impl<T> Mutex<T> {
pub fn lock(self) -> Locked<T> {
// do actual low-level OS mutex lock
self.sys_mutex.lock();
return Locked { locked_mutex: self };
}
}
struct Locked<T> {
locked_mutex: Mutex<T>
}
impl<T> Locked<T> {
pub fn unlock(self) -> Mutex<T> {
// Do low-level OS mutex unlock
self.locked_mutex.sys_mutex.unlock();
return self.locked_mutex;
}
}
impl<T> Deref for Locked<T> { ... }
impl<T> DerefMut for Locked<T> { ... } Of course it's possible I just don't know how to do what I want. I found that, with the |
It sounds like what you want is an interface for raw (non-guard) locking/unlocking of the mutex. This sounds more reasonable to expose than |
Sure, it doesn't have to be the |
How would you ever be able to call |
I only posted a rough sketch of an implementation. Really I'd want to wrap the whole thing in an Then when unlocking, But then, with that setup you can still double-lock, by cloning it again in the same thread and locking that thing. Hm... |
You can base your API off of parking_lot's RawMutex etc to avoid blocking on this request, BTW. |
I'd like to work directly with
std::sys_common
mutex and condvar types. Is there any way to do this short of a custom rustc build with a modified standard library?The text was updated successfully, but these errors were encountered: