123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #[cfg(feature = "singleton")]
- use crate::util::AmoOnceRef;
- pub trait Timer: Send + Sync {
-
-
-
-
-
-
-
- fn set_timer(&self, stime_value: u64);
- }
- #[cfg(feature = "singleton")]
- static TIMER: AmoOnceRef<dyn Timer> = AmoOnceRef::new();
- #[cfg(feature = "singleton")]
- pub fn init_timer(timer: &'static dyn Timer) {
- if !TIMER.try_call_once(timer) {
- panic!("load sbi module when already loaded")
- }
- }
- #[cfg(feature = "singleton")]
- #[inline]
- pub(crate) fn probe_timer() -> bool {
- TIMER.get().is_some()
- }
- #[cfg(feature = "singleton")]
- #[inline]
- pub(crate) fn set_timer(time_value: u64) -> bool {
- if let Some(timer) = TIMER.get() {
- timer.set_timer(time_value);
- true
- } else {
- false
- }
- }
|