Loading system/gd/rust/common/src/time.rs +7 −32 Original line number Diff line number Diff line Loading @@ -2,8 +2,6 @@ ///Tokio's time use nix::sys::time::TimeSpec; use nix::sys::timerfd::{ClockId, Expiration, TimerFd, TimerFlags, TimerSetTimeFlags}; use nix::unistd::close; use std::os::unix::io::AsRawFd; use std::time::Duration; use tokio::io::unix::AsyncFd; Loading @@ -16,18 +14,14 @@ impl Alarm { /// Construct a new alarm pub fn new() -> Self { let timer = TimerFd::new(get_clock(), TimerFlags::empty()).unwrap(); Self { fd: AsyncFd::new(timer).unwrap(), } Self { fd: AsyncFd::new(timer).unwrap() } } /// Reset the alarm to duration, starting from now pub fn reset(&mut self, duration: Duration) { self.fd.get_ref() .set( Expiration::OneShot(TimeSpec::from(duration)), TimerSetTimeFlags::empty(), ) self.fd .get_ref() .set(Expiration::OneShot(TimeSpec::from(duration)), TimerSetTimeFlags::empty()) .unwrap(); } Loading @@ -50,25 +44,12 @@ impl Default for Alarm { } } impl Drop for Alarm { fn drop(&mut self) { close(self.fd.as_raw_fd()).unwrap(); } } /// Similar to tokio's interval, except the first tick does *not* complete immediately pub fn interval(period: Duration) -> Interval { let timer = TimerFd::new(get_clock(), TimerFlags::empty()).unwrap(); timer .set( Expiration::Interval(TimeSpec::from(period)), TimerSetTimeFlags::empty(), ) .unwrap(); timer.set(Expiration::Interval(TimeSpec::from(period)), TimerSetTimeFlags::empty()).unwrap(); Interval { fd: AsyncFd::new(timer).unwrap(), } Interval { fd: AsyncFd::new(timer).unwrap() } } /// Future returned by interval() Loading @@ -85,12 +66,6 @@ impl Interval { } } impl Drop for Interval { fn drop(&mut self) { close(self.fd.as_raw_fd()).unwrap(); } } fn get_clock() -> ClockId { if cfg!(target_os = "android") { ClockId::CLOCK_BOOTTIME_ALARM Loading Loading
system/gd/rust/common/src/time.rs +7 −32 Original line number Diff line number Diff line Loading @@ -2,8 +2,6 @@ ///Tokio's time use nix::sys::time::TimeSpec; use nix::sys::timerfd::{ClockId, Expiration, TimerFd, TimerFlags, TimerSetTimeFlags}; use nix::unistd::close; use std::os::unix::io::AsRawFd; use std::time::Duration; use tokio::io::unix::AsyncFd; Loading @@ -16,18 +14,14 @@ impl Alarm { /// Construct a new alarm pub fn new() -> Self { let timer = TimerFd::new(get_clock(), TimerFlags::empty()).unwrap(); Self { fd: AsyncFd::new(timer).unwrap(), } Self { fd: AsyncFd::new(timer).unwrap() } } /// Reset the alarm to duration, starting from now pub fn reset(&mut self, duration: Duration) { self.fd.get_ref() .set( Expiration::OneShot(TimeSpec::from(duration)), TimerSetTimeFlags::empty(), ) self.fd .get_ref() .set(Expiration::OneShot(TimeSpec::from(duration)), TimerSetTimeFlags::empty()) .unwrap(); } Loading @@ -50,25 +44,12 @@ impl Default for Alarm { } } impl Drop for Alarm { fn drop(&mut self) { close(self.fd.as_raw_fd()).unwrap(); } } /// Similar to tokio's interval, except the first tick does *not* complete immediately pub fn interval(period: Duration) -> Interval { let timer = TimerFd::new(get_clock(), TimerFlags::empty()).unwrap(); timer .set( Expiration::Interval(TimeSpec::from(period)), TimerSetTimeFlags::empty(), ) .unwrap(); timer.set(Expiration::Interval(TimeSpec::from(period)), TimerSetTimeFlags::empty()).unwrap(); Interval { fd: AsyncFd::new(timer).unwrap(), } Interval { fd: AsyncFd::new(timer).unwrap() } } /// Future returned by interval() Loading @@ -85,12 +66,6 @@ impl Interval { } } impl Drop for Interval { fn drop(&mut self) { close(self.fd.as_raw_fd()).unwrap(); } } fn get_clock() -> ClockId { if cfg!(target_os = "android") { ClockId::CLOCK_BOOTTIME_ALARM Loading