From f3be99cd03f89ad8e26b9488f29a359afb7395ac Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Tue, 17 May 2022 15:30:08 -0700 Subject: [PATCH] base: unix: timer: use mark_waited() in wait_for() Remove some duplicated code that called read() on the timerfd in an almost identical way in two functions by reusing mark_waited() within wait_for(). BUG=None TEST=cargo test -p base timer -- --include-ignored Change-Id: I3bf4a6eb3c777aa9314c408281e4d60ff218fd2a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3652891 Tested-by: kokoro Reviewed-by: Anton Romanov Commit-Queue: Daniel Verkamp --- base/src/sys/unix/timer.rs | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/base/src/sys/unix/timer.rs b/base/src/sys/unix/timer.rs index 85acba2cad..7fc875f16f 100644 --- a/base/src/sys/unix/timer.rs +++ b/base/src/sys/unix/timer.rs @@ -126,27 +126,11 @@ impl Timer { return Ok(WaitResult::Timeout); } - let mut count = 0u64; - - // Safe because this will only modify |buf| and we check the return value. - let ret = unsafe { - libc::read( - self.as_raw_descriptor(), - &mut count as *mut _ as *mut libc::c_void, - mem::size_of_val(&count), - ) - }; - // EAGAIN is a valid error in the case where another thread has called timerfd_settime // in between this thread calling ppoll and read. Since the ppoll returned originally // without any revents it means the timer did expire, so we treat this as a // WaitResult::Expired. - if ret < 0 { - let error = Error::last(); - if error.errno() != EAGAIN { - return Err(error); - } - } + let _ = self.mark_waited()?; Ok(WaitResult::Expired) }