use alloc::sync::Arc;
use ax_tracepoint::{ExtTracePoint, TracePoint};
use super::KernelTraceAux;
use crate::sync::NoPreemptMutex;
#[derive(Clone)]
pub struct KernelExtTracePoint {
state: Arc<NoPreemptMutex<ExtTracePoint<KernelTraceAux>>>,
}
impl KernelExtTracePoint {
pub(super) fn new(state: ExtTracePoint<KernelTraceAux>) -> Self {
Self {
state: Arc::new(NoPreemptMutex::new(state)),
}
}
pub fn read<R>(&self, operation: impl FnOnce(&ExtTracePoint<KernelTraceAux>) -> R) -> R {
operation(&self.state.lock())
}
pub fn update<R>(&self, operation: impl FnOnce(&mut ExtTracePoint<KernelTraceAux>) -> R) -> R {
let mut state = self.state.lock();
let result = operation(&mut state);
state.trace_point().set_callback_gate(state.has_callbacks());
result
}
pub fn trace_point(&self) -> &'static TracePoint<KernelTraceAux> {
self.read(ExtTracePoint::trace_point)
}
}