bhm: Fix a warning in the Linux sampler (#30924)

Use curly braces instead of an explicit drop to control the end of a
borrow.
This commit is contained in:
Martin Robinson 2023-12-28 12:20:47 +01:00 committed by GitHub
parent 7305c59304
commit bd052f536e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -207,59 +207,59 @@ impl Sampler for LinuxSampler {
// Safety: non-exclusive reference only // Safety: non-exclusive reference only
// since sampled threads are accessing this concurrently // since sampled threads are accessing this concurrently
let shared_state = unsafe { &*SHARED_STATE.0.get() }; let result;
shared_state {
.msg2 let shared_state = unsafe { &*SHARED_STATE.0.get() };
.as_ref() shared_state
.unwrap() .msg2
.wait_through_intr() .as_ref()
.expect("msg2 failed"); .unwrap()
.wait_through_intr()
.expect("msg2 failed");
let context = CONTEXT.load(Ordering::SeqCst); let context = CONTEXT.load(Ordering::SeqCst);
let mut cursor = mem::MaybeUninit::uninit(); let mut cursor = mem::MaybeUninit::uninit();
let ret = unsafe { unw_init_local(cursor.as_mut_ptr(), context) }; let ret = unsafe { unw_init_local(cursor.as_mut_ptr(), context) };
let result = if ret == UNW_ESUCCESS { result = if ret == UNW_ESUCCESS {
let mut native_stack = NativeStack::new(); let mut native_stack = NativeStack::new();
loop { loop {
let ip = match get_register(cursor.as_mut_ptr(), RegNum::Ip) { let ip = match get_register(cursor.as_mut_ptr(), RegNum::Ip) {
Ok(ip) => ip, Ok(ip) => ip,
Err(_) => break, Err(_) => break,
}; };
let sp = match get_register(cursor.as_mut_ptr(), RegNum::Sp) { let sp = match get_register(cursor.as_mut_ptr(), RegNum::Sp) {
Ok(sp) => sp, Ok(sp) => sp,
Err(_) => break, Err(_) => break,
}; };
if native_stack if native_stack
.process_register(ip as *mut _, sp as *mut _) .process_register(ip as *mut _, sp as *mut _)
.is_err() || .is_err() ||
!step(cursor.as_mut_ptr()).unwrap_or(false) !step(cursor.as_mut_ptr()).unwrap_or(false)
{ {
break; break;
}
} }
} Ok(native_stack)
Ok(native_stack) } else {
} else { Err(())
Err(()) };
};
// signal the thread to continue. // signal the thread to continue.
shared_state shared_state
.msg3 .msg3
.as_ref() .as_ref()
.unwrap() .unwrap()
.post() .post()
.expect("msg3 failed"); .expect("msg3 failed");
// wait for thread to continue. // wait for thread to continue.
shared_state shared_state
.msg4 .msg4
.as_ref() .as_ref()
.unwrap() .unwrap()
.wait_through_intr() .wait_through_intr()
.expect("msg4 failed"); .expect("msg4 failed");
}
// No-op, but marks the end of the shared borrow
drop(shared_state);
clear_shared_state(); clear_shared_state();