-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Use the parking_lot locking primitives #56410
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
Changes from all commits
7b0ad27
1aab11d
e313500
20ab8d2
7cafa6d
7c42fc8
3b23add
f58fc9b
81a1e21
5a3dd8a
d354b95
8edc128
4f0f8e1
a0b366c
8dfad4b
d6fab63
fc379ee
142bda2
eaaca60
0d679ef
e8e355e
55f1ed2
c6c6fb1
f1a805b
0b1a6e9
a562580
b50a20e
6ad5485
0070390
c294204
c301ce0
dd30a55
e0fd309
0048440
e49bbd1
f40d609
56c2805
7124cae
6695be8
795285f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,3 +47,7 @@ | |
[submodule "src/doc/embedded-book"] | ||
path = src/doc/embedded-book | ||
url = https://github.com/rust-embedded/book.git | ||
[submodule "src/parking_lot"] | ||
path = src/parking_lot | ||
url = https://github.com/faern/parking_lot | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where should this be pointing before merging? Back to @Amanieu's repo, or will that be moved to the @rust-lang organization, like what I think is the plan for hashbrown? |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,12 @@ use core::panic::{BoxMeUp, PanicInfo, Location}; | |
use crate::any::Any; | ||
use crate::fmt; | ||
use crate::intrinsics; | ||
use crate::lock_api::RawRwLock as _; | ||
use crate::mem; | ||
use crate::parking_lot::RawRwLock; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So everything else uses std's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, that's because it needs the Seems like another agument to make the rest also use parking_lot's stuff directly, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But they are not equivalent. See my other comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, so this one file here is where we are okay with not having guards? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose so. It's how the standard library is currently implemented. So someone must have thought it was okay at some point. Well, here and in one place SGX also uses |
||
use crate::ptr; | ||
use crate::raw; | ||
use crate::sys::stdio::panic_output; | ||
use crate::sys_common::rwlock::RWLock; | ||
use crate::sys_common::thread_info; | ||
use crate::sys_common::util; | ||
use crate::thread; | ||
|
@@ -54,7 +55,7 @@ enum Hook { | |
Custom(*mut (dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send)), | ||
} | ||
|
||
static HOOK_LOCK: RWLock = RWLock::new(); | ||
static HOOK_LOCK: RawRwLock = RawRwLock::INIT; | ||
static mut HOOK: Hook = Hook::Default; | ||
|
||
/// Registers a custom panic hook, replacing any that was previously registered. | ||
|
@@ -97,10 +98,10 @@ pub fn set_hook(hook: Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send>) { | |
} | ||
|
||
unsafe { | ||
HOOK_LOCK.write(); | ||
HOOK_LOCK.lock_exclusive(); | ||
let old_hook = HOOK; | ||
HOOK = Hook::Custom(Box::into_raw(hook)); | ||
HOOK_LOCK.write_unlock(); | ||
HOOK_LOCK.unlock_exclusive(); | ||
|
||
if let Hook::Custom(ptr) = old_hook { | ||
Box::from_raw(ptr); | ||
|
@@ -142,10 +143,10 @@ pub fn take_hook() -> Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send> { | |
} | ||
|
||
unsafe { | ||
HOOK_LOCK.write(); | ||
HOOK_LOCK.lock_exclusive(); | ||
let hook = HOOK; | ||
HOOK = Hook::Default; | ||
HOOK_LOCK.write_unlock(); | ||
HOOK_LOCK.unlock_exclusive(); | ||
|
||
match hook { | ||
Hook::Default => Box::new(default_hook), | ||
|
@@ -463,7 +464,7 @@ fn rust_panic_with_hook(payload: &mut dyn BoxMeUp, | |
message, | ||
Location::internal_constructor(file, line, col), | ||
); | ||
HOOK_LOCK.read(); | ||
HOOK_LOCK.lock_shared(); | ||
match HOOK { | ||
// Some platforms know that printing to stderr won't ever actually | ||
// print anything, and if that's the case we can skip the default | ||
|
@@ -478,7 +479,7 @@ fn rust_panic_with_hook(payload: &mut dyn BoxMeUp, | |
(*ptr)(&info); | ||
} | ||
}; | ||
HOOK_LOCK.read_unlock(); | ||
HOOK_LOCK.unlock_shared(); | ||
} | ||
|
||
if panics > 1 { | ||
|
Uh oh!
There was an error while loading. Please reload this page.