Skip to content

Instantly share code, notes, and snippets.

@ackintosh
Created July 7, 2024 22:53
Show Gist options
  • Save ackintosh/a5c9beec771f749422f390c9ad87499e to your computer and use it in GitHub Desktop.
Save ackintosh/a5c9beec771f749422f390c9ad87499e to your computer and use it in GitHub Desktop.
struct MonitorMutex {
inner: Mutex<RateLimiter>,
}
impl MonitorMutex {
fn new(limiter: RateLimiter) -> Self {
MonitorMutex {
inner: Mutex::new(limiter),
}
}
fn lock(&self) -> MutexGuard<RateLimiter> {
let start = Instant::now();
let guard = self.inner.lock();
let duration = start.elapsed().as_nanos() as u64;
println!("MonitorMutex:{}", duration);
guard
}
}
impl Deref for MonitorMutex {
type Target = Mutex<RateLimiter>;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl DerefMut for MonitorMutex {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment