diff options
author | Dylan Reid <dgreid@chromium.org> | 2020-04-22 17:26:00 +0000 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-04-23 19:50:08 +0000 |
commit | 1160f456a4f21eb7ff11630fdeed224c3b4c56b4 (patch) | |
tree | 77aeabe5cfe166d2b75bcfed5db7d273626acf5c | |
parent | a7b6a1c897205d8320482eb506167c5df66647b2 (diff) | |
download | crosvm-1160f456a4f21eb7ff11630fdeed224c3b4c56b4.tar crosvm-1160f456a4f21eb7ff11630fdeed224c3b4c56b4.tar.gz crosvm-1160f456a4f21eb7ff11630fdeed224c3b4c56b4.tar.bz2 crosvm-1160f456a4f21eb7ff11630fdeed224c3b4c56b4.tar.lz crosvm-1160f456a4f21eb7ff11630fdeed224c3b4c56b4.tar.xz crosvm-1160f456a4f21eb7ff11630fdeed224c3b4c56b4.tar.zst crosvm-1160f456a4f21eb7ff11630fdeed224c3b4c56b4.zip |
sys_util: timerfd: Methods don't need to me mut
Because TimerFd is a wrapper around a 'File' that is never modified there isn't a need for a mutable borrow. The kernel already handles the interior mutability of the underlying file descriptor. Change-Id: I7ae068cc54050b0021d00620b561335b2ae0ba16 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2161625 Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Dylan Reid <dgreid@chromium.org>
-rw-r--r-- | src/linux.rs | 2 | ||||
-rw-r--r-- | sys_util/src/timerfd.rs | 10 |
2 files changed, 6 insertions, 6 deletions
diff --git a/src/linux.rs b/src/linux.rs index 8690ff7..c8eb478 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -1767,7 +1767,7 @@ fn run_control( } // Balance available memory between guest and host every second. - let mut balancemem_timer = TimerFd::new().map_err(Error::CreateTimerFd)?; + let balancemem_timer = TimerFd::new().map_err(Error::CreateTimerFd)?; if Path::new(LOWMEM_AVAILABLE).exists() { // Create timer request balloon stats every 1s. poll_ctx diff --git a/sys_util/src/timerfd.rs b/sys_util/src/timerfd.rs index 8e5d91b..f2a3ff8 100644 --- a/sys_util/src/timerfd.rs +++ b/sys_util/src/timerfd.rs @@ -34,7 +34,7 @@ impl TimerFd { /// Sets the timer to expire after `dur`. If `interval` is not `None` it represents /// the period for repeated expirations after the initial expiration. Otherwise /// the timer will expire just once. Cancels any existing duration and repeating interval. - pub fn reset(&mut self, dur: Duration, interval: Option<Duration>) -> Result<()> { + pub fn reset(&self, dur: Duration, interval: Option<Duration>) -> Result<()> { // Safe because we are zero-initializing a struct with only primitive member fields. let mut spec: libc::itimerspec = unsafe { mem::zeroed() }; spec.it_value.tv_sec = dur.as_secs() as libc::time_t; @@ -61,7 +61,7 @@ impl TimerFd { /// Waits until the timer expires. The return value represents the number of times the timer /// has expired since the last time `wait` was called. If the timer has not yet expired once /// this call will block until it does. - pub fn wait(&mut self) -> Result<u64> { + pub fn wait(&self) -> Result<u64> { let mut count = 0u64; // Safe because this will only modify |buf| and we check the return value. @@ -96,7 +96,7 @@ impl TimerFd { } /// Disarms the timer. - pub fn clear(&mut self) -> Result<()> { + pub fn clear(&self) -> Result<()> { // Safe because we are zero-initializing a struct with only primitive member fields. let spec: libc::itimerspec = unsafe { mem::zeroed() }; @@ -222,7 +222,7 @@ mod tests { #[test] fn one_shot() { - let mut tfd = TimerFd::new().expect("failed to create timerfd"); + let tfd = TimerFd::new().expect("failed to create timerfd"); assert_eq!(tfd.is_armed().unwrap(), false); let dur = Duration::from_millis(200); @@ -239,7 +239,7 @@ mod tests { #[test] fn repeating() { - let mut tfd = TimerFd::new().expect("failed to create timerfd"); + let tfd = TimerFd::new().expect("failed to create timerfd"); let dur = Duration::from_millis(200); let interval = Duration::from_millis(100); |