use super::TRACKER;
pub fn track_refcell_new<T>(
#[cfg_attr(not(feature = "track"), allow(unused_variables))] name: &str,
value: std::cell::RefCell<T>,
) -> std::cell::RefCell<T> {
#[cfg(feature = "track")]
{
let mut tracker = TRACKER.lock();
tracker.record_refcell_new(name);
}
value
}
#[inline(always)]
pub fn track_refcell_borrow<'a, T>(
#[cfg_attr(not(feature = "track"), allow(unused_variables))] borrow_id: &str,
#[cfg_attr(not(feature = "track"), allow(unused_variables))] refcell_id: &str,
#[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
value: std::cell::Ref<'a, T>,
) -> std::cell::Ref<'a, T> {
#[cfg(feature = "track")]
{
let mut tracker = TRACKER.lock();
tracker.record_refcell_borrow(borrow_id, refcell_id, false, location);
}
value
}
#[inline(always)]
pub fn track_refcell_borrow_mut<'a, T>(
#[cfg_attr(not(feature = "track"), allow(unused_variables))] borrow_id: &str,
#[cfg_attr(not(feature = "track"), allow(unused_variables))] refcell_id: &str,
#[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
value: std::cell::RefMut<'a, T>,
) -> std::cell::RefMut<'a, T> {
#[cfg(feature = "track")]
{
let mut tracker = TRACKER.lock();
tracker.record_refcell_borrow(borrow_id, refcell_id, true, location);
}
value
}
#[inline(always)]
pub fn track_refcell_drop(
#[cfg_attr(not(feature = "track"), allow(unused_variables))] borrow_id: &str,
#[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
) {
#[cfg(feature = "track")]
{
let mut tracker = TRACKER.lock();
tracker.record_refcell_drop(borrow_id, location);
}
}
#[inline(always)]
pub fn track_cell_new<T>(
#[cfg_attr(not(feature = "track"), allow(unused_variables))] name: &str,
value: std::cell::Cell<T>,
) -> std::cell::Cell<T> {
#[cfg(feature = "track")]
{
let mut tracker = TRACKER.lock();
tracker.record_cell_new(name);
}
value
}
#[inline(always)]
pub fn track_cell_get<T: Copy>(
#[cfg_attr(not(feature = "track"), allow(unused_variables))] cell_id: &str,
#[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
value: T,
) -> T {
#[cfg(feature = "track")]
{
let mut tracker = TRACKER.lock();
tracker.record_cell_get(cell_id, location);
}
value
}
#[inline(always)]
pub fn track_cell_set(
#[cfg_attr(not(feature = "track"), allow(unused_variables))] cell_id: &str,
#[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
) {
#[cfg(feature = "track")]
{
let mut tracker = TRACKER.lock();
tracker.record_cell_set(cell_id, location);
}
}
#[inline(always)]
pub fn track_once_cell_new<T>(
#[cfg_attr(not(feature = "track"), allow(unused_variables))] name: &str,
#[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
value: std::cell::OnceCell<T>,
) -> std::cell::OnceCell<T> {
#[cfg(feature = "track")]
{
let mut tracker = TRACKER.lock();
tracker.record_once_cell_new(name, "OnceCell", location);
}
value
}
#[inline(always)]
pub fn track_once_lock_new<T>(
#[cfg_attr(not(feature = "track"), allow(unused_variables))] name: &str,
#[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
value: std::sync::OnceLock<T>,
) -> std::sync::OnceLock<T> {
#[cfg(feature = "track")]
{
let mut tracker = TRACKER.lock();
tracker.record_once_cell_new(name, "OnceLock", location);
}
value
}
#[inline(always)]
pub fn track_once_cell_set<T>(
#[cfg_attr(not(feature = "track"), allow(unused_variables))] cell_id: &str,
#[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
result: Result<(), T>,
) -> Result<(), T> {
#[cfg(feature = "track")]
{
let mut tracker = TRACKER.lock();
tracker.record_once_cell_set(cell_id, result.is_ok(), location);
}
result
}
#[inline(always)]
pub fn track_once_cell_get<'a, T>(
#[cfg_attr(not(feature = "track"), allow(unused_variables))] cell_id: &str,
#[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
value: Option<&'a T>,
) -> Option<&'a T> {
#[cfg(feature = "track")]
{
let mut tracker = TRACKER.lock();
tracker.record_once_cell_get(cell_id, value.is_some(), location);
}
value
}
#[inline(always)]
pub fn track_once_cell_get_or_init<'a, T>(
#[cfg_attr(not(feature = "track"), allow(unused_variables))] cell_id: &str,
#[cfg_attr(not(feature = "track"), allow(unused_variables))] was_initialized: bool,
#[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
value: &'a T,
) -> &'a T {
#[cfg(feature = "track")]
{
let mut tracker = TRACKER.lock();
tracker.record_once_cell_get_or_init(cell_id, was_initialized, location);
}
value
}