Browse Source

rust: timer: add bindings to timer_mod_ns and timer_expire_time_ns

These are needed to implement ToMigrationStateShared for timers,
and thus allow including them in Migratable<> structs.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
pull/316/head
Paolo Bonzini 4 months ago
parent
commit
709beed426
  1. 16
      rust/util/src/timer.rs

16
rust/util/src/timer.rs

@ -10,7 +10,8 @@ use std::{
use common::{callbacks::FnCall, Opaque};
use crate::bindings::{
self, qemu_clock_get_ns, timer_del, timer_init_full, timer_mod, QEMUClockType,
self, qemu_clock_get_ns, timer_del, timer_expire_time_ns, timer_init_full, timer_mod,
timer_mod_ns, QEMUClockType,
};
/// A safe wrapper around [`bindings::QEMUTimer`].
@ -88,6 +89,19 @@ impl Timer {
}
}
pub fn expire_time_ns(&self) -> Option<i64> {
// SAFETY: the only way to obtain a Timer safely is via methods that
// take a Pin<&mut Self>, therefore the timer is pinned
let ret = unsafe { timer_expire_time_ns(self.as_ptr()) };
i64::try_from(ret).ok()
}
pub fn modify_ns(&self, expire_time: u64) {
// SAFETY: the only way to obtain a Timer safely is via methods that
// take a Pin<&mut Self>, therefore the timer is pinned
unsafe { timer_mod_ns(self.as_mut_ptr(), expire_time.try_into().unwrap()) }
}
pub fn modify(&self, expire_time: u64) {
// SAFETY: the only way to obtain a Timer safely is via methods that
// take a Pin<&mut Self>, therefore the timer is pinned

Loading…
Cancel
Save