mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-28 20:55:11 +00:00
Traced refcell and mutex wrappers for debugging
This commit is contained in:
parent
aec6b9e5e1
commit
7fd4ad025a
2 changed files with 105 additions and 0 deletions
|
@ -133,6 +133,8 @@ pub mod categories {
|
||||||
(path, "path", "Searching/using paths");
|
(path, "path", "Searching/using paths");
|
||||||
|
|
||||||
(screen, "screen", "Screen repaints");
|
(screen, "screen", "Screen repaints");
|
||||||
|
|
||||||
|
(refcell, "refcell", "Refcell dynamic borrowing");
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
|
use crate::flog::FLOG;
|
||||||
|
use std::cell::{Ref, RefMut};
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
use std::sync::MutexGuard;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RelaxedAtomicBool(AtomicBool);
|
pub struct RelaxedAtomicBool(AtomicBool);
|
||||||
|
@ -23,3 +26,103 @@ impl Clone for RelaxedAtomicBool {
|
||||||
Self(AtomicBool::new(self.load()))
|
Self(AtomicBool::new(self.load()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct DebugRef<'a, T>(Ref<'a, T>);
|
||||||
|
|
||||||
|
impl<'a, T> DebugRef<'a, T> {
|
||||||
|
pub fn new(r: Ref<'a, T>) -> Self {
|
||||||
|
FLOG!(
|
||||||
|
refcell,
|
||||||
|
"CREATE DebugRef",
|
||||||
|
std::backtrace::Backtrace::capture()
|
||||||
|
);
|
||||||
|
Self(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T> Drop for DebugRef<'a, T> {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
FLOG!(
|
||||||
|
refcell,
|
||||||
|
"DROP DebugRef",
|
||||||
|
std::backtrace::Backtrace::capture()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T> std::ops::Deref for DebugRef<'a, T> {
|
||||||
|
type Target = T;
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct DebugRefMut<'a, T>(RefMut<'a, T>);
|
||||||
|
|
||||||
|
impl<'a, T> DebugRefMut<'a, T> {
|
||||||
|
pub fn new(r: RefMut<'a, T>) -> Self {
|
||||||
|
FLOG!(
|
||||||
|
refcell,
|
||||||
|
"CREATE DebugRefMut",
|
||||||
|
std::backtrace::Backtrace::capture()
|
||||||
|
);
|
||||||
|
Self(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T> Drop for DebugRefMut<'a, T> {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
FLOG!(
|
||||||
|
refcell,
|
||||||
|
"DROP DebugRefMut",
|
||||||
|
std::backtrace::Backtrace::capture()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<'a, T> std::ops::Deref for DebugRefMut<'a, T> {
|
||||||
|
type Target = T;
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T> std::ops::DerefMut for DebugRefMut<'a, T> {
|
||||||
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
|
&mut self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct DebugMutexGuard<'a, T>(MutexGuard<'a, T>);
|
||||||
|
|
||||||
|
impl<'a, T> DebugMutexGuard<'a, T> {
|
||||||
|
pub fn new(r: MutexGuard<'a, T>) -> Self {
|
||||||
|
FLOG!(
|
||||||
|
refcell,
|
||||||
|
"CREATE DebugMutexGuard",
|
||||||
|
std::backtrace::Backtrace::capture()
|
||||||
|
);
|
||||||
|
Self(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T> Drop for DebugMutexGuard<'a, T> {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
FLOG!(
|
||||||
|
refcell,
|
||||||
|
"DROP DebugMutexGuard",
|
||||||
|
std::backtrace::Backtrace::capture()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T> std::ops::Deref for DebugMutexGuard<'a, T> {
|
||||||
|
type Target = T;
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<'a, T> std::ops::DerefMut for DebugMutexGuard<'a, T> {
|
||||||
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
|
&mut self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue