Created
July 7, 2024 22:53
-
-
Save ackintosh/a5c9beec771f749422f390c9ad87499e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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