mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Avoid locking in the signal handler
This commit is contained in:
parent
99804eb5a6
commit
5bcd2f5642
1 changed files with 43 additions and 38 deletions
|
@ -25,9 +25,13 @@ struct Print {
|
|||
|
||||
impl fmt::Debug for Print {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
// Safety: we’re in a signal handler that is about to call `libc::_exit`.
|
||||
// Potential data races from using `*_unsynchronized` functions are perhaps
|
||||
// less bad than potential deadlocks?
|
||||
unsafe {
|
||||
let mut print_fn_frame = 0;
|
||||
let mut frame_count = 0;
|
||||
backtrace::trace(|frame| {
|
||||
backtrace::trace_unsynchronized(|frame| {
|
||||
let found = frame.symbol_address() as usize == self.print_fn_address;
|
||||
if found {
|
||||
print_fn_frame = frame_count;
|
||||
|
@ -42,7 +46,7 @@ impl fmt::Debug for Print {
|
|||
f.add_context()?;
|
||||
let mut result = Ok(());
|
||||
let mut frame_count = 0;
|
||||
backtrace::trace(|frame| {
|
||||
backtrace::trace_unsynchronized(|frame| {
|
||||
let skip = frame_count < print_fn_frame;
|
||||
frame_count += 1;
|
||||
if skip {
|
||||
|
@ -51,7 +55,7 @@ impl fmt::Debug for Print {
|
|||
|
||||
let mut frame_fmt = f.frame();
|
||||
let mut any_symbol = false;
|
||||
backtrace::resolve_frame(frame, |symbol| {
|
||||
backtrace::resolve_frame_unsynchronized(frame, |symbol| {
|
||||
any_symbol = true;
|
||||
if let Err(e) = frame_fmt.symbol(frame, symbol) {
|
||||
result = Err(e)
|
||||
|
@ -68,6 +72,7 @@ impl fmt::Debug for Print {
|
|||
f.finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn print_path(fmt: &mut fmt::Formatter, path: BytesOrWideString) -> fmt::Result {
|
||||
match path {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue