-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Reorganise std::unstable::mutex to add an RAII unlocker to the mutex & replace LittleLock #12235
Conversation
Could you add a test for |
I feel like this should also rename Currently To solve this, we could have |
Whoops. I imagine |
It allows for static mutexes (yay C libraries). |
This is not sound without the revised destructor rules, from what I can see. On phone so cannot look up the relevant issue. |
@nikomatsakis I'm not sure I understand... this doesn't add or remove destructors from any types (but does add an entirely new type with a destructor). |
This looks great to me, nice work! r=me with comments fixed |
@@ -65,7 +65,7 @@ pub struct GreenTask { | |||
pool_id: uint, | |||
|
|||
// See the comments in the scheduler about why this is necessary | |||
nasty_deschedule_lock: Mutex, | |||
nasty_deschedule_lock: StaticNativeMutex, |
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.
While you're at it, can you make this a NativeMutex
?
This automatically unlocks its lock when it goes out of scope, and provides a safe(ish) method to call .wait.
This better reflects its purpose and design.
This obsoletes LittleLock, and so it is removed.
This helps people remember to save the return value to keep the mutex locked as appropriate.
- adds a `LockGuard` type returned by `.lock` and `.trylock` that unlocks the mutex in the destructor - renames `mutex::Mutex` to `StaticNativeMutex` - adds a `NativeMutex` type with a destructor - removes `LittleLock` - adds `#[must_use]` to `sync::mutex::Guard` to remind people to use it
@huonw I think I was wrong, I believe it is ok so long as the fields of all types with an unsafe dtor are private, to prevent surprise mutations -- but it all makes me a bit nervous. We need to finish #8861 (and perhaps #6834), since this kind of ad-hoc rule breakery is hard to verify and a bit creepy. |
Fix release year in CHANGELOG.md Fixes a typo in rust-lang#12224 CC: `@xFrednet` `@Manishearth` --- changelog: none
LockGuard
type returned by.lock
and.trylock
that unlocks the mutex in the destructormutex::Mutex
toStaticNativeMutex
NativeMutex
type with a destructorLittleLock
#[must_use]
tosync::mutex::Guard
to remind people to use it