From 253274185ea77d92ce09ea156d77596b3ab31973 Mon Sep 17 00:00:00 2001 From: Chloe Martin Date: Mon, 18 Nov 2024 13:46:39 -0500 Subject: [PATCH] define some types --- msim/src/sim/runtime/mod.rs | 5 +++-- msim/src/sim/task.rs | 16 ++++++++-------- msim/src/sim/time/mod.rs | 1 + msim/src/sim/time/timer.rs | 2 +- rust-toolchain.toml | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/msim/src/sim/runtime/mod.rs b/msim/src/sim/runtime/mod.rs index e7a1168..b69056f 100644 --- a/msim/src/sim/runtime/mod.rs +++ b/msim/src/sim/runtime/mod.rs @@ -4,7 +4,7 @@ use super::*; use crate::assert_send_sync; use crate::context::TaskEnterGuard; use crate::net::NetSim; -use crate::task::{JoinHandle, NodeId}; +use crate::task::{InitFn, JoinHandle, NodeId}; use ::rand::Rng; use std::{ any::TypeId, @@ -372,7 +372,7 @@ pub struct NodeBuilder<'a> { handle: &'a Handle, name: Option, ip: Option, - init: Option>, + init: Option, } impl<'a> NodeBuilder<'a> { @@ -483,6 +483,7 @@ impl NodeHandle { /// Join the node. /// TODO: unimplemented + #[expect(clippy::result_unit_err)] pub fn join(self) -> Result<(), ()> { warn!("TODO: implement NodeHandle::join()"); Ok(()) diff --git a/msim/src/sim/task.rs b/msim/src/sim/task.rs index 2c73f5a..cb25783 100644 --- a/msim/src/sim/task.rs +++ b/msim/src/sim/task.rs @@ -73,7 +73,9 @@ struct PanicWrapper { restart_after: Option, } -struct PanicHookGuard(Option) + Sync + Send + 'static>>); +type PanicFn = Box) + Sync + Send + 'static>; + +struct PanicHookGuard(Option); impl PanicHookGuard { fn new() -> Self { @@ -337,11 +339,13 @@ pub(crate) struct TaskHandle { } assert_send_sync!(TaskHandle); +pub(crate) type InitFn = Arc; + struct Node { info: Arc, paused: Vec, /// A function to spawn the initial task. - init: Option>, + init: Option, } impl TaskHandle { @@ -392,11 +396,7 @@ impl TaskHandle { } /// Create a new node. - pub fn create_node( - &self, - name: Option, - init: Option>, - ) -> TaskNodeHandle { + pub fn create_node(&self, name: Option, init: Option) -> TaskNodeHandle { let id = NodeId(self.next_node_id.fetch_add(1, Ordering::SeqCst)); let name = name.unwrap_or_else(|| format!("node-{}", id.0)); let info = Arc::new(TaskInfo::new(id, name)); @@ -690,7 +690,7 @@ impl AbortHandle { ret } - fn inner(&self) -> Box>> { + fn inner(&self) -> Arc> { unsafe { ErasablePtr::unerase(self.inner) } } } diff --git a/msim/src/sim/time/mod.rs b/msim/src/sim/time/mod.rs index ace6cd4..89c4ee3 100644 --- a/msim/src/sim/time/mod.rs +++ b/msim/src/sim/time/mod.rs @@ -543,6 +543,7 @@ define_sys_interceptor!( // used by Instant libc::CLOCK_MONOTONIC | libc::CLOCK_MONOTONIC_RAW | libc::CLOCK_MONOTONIC_COARSE => { // Instant is the same layout as timespec on linux + #[allow(clippy::missing_transmute_annotations)] ts.write(std::mem::transmute(time.now_instant())); } diff --git a/msim/src/sim/time/timer.rs b/msim/src/sim/time/timer.rs index 1c1f03b..f9d214f 100644 --- a/msim/src/sim/time/timer.rs +++ b/msim/src/sim/time/timer.rs @@ -113,7 +113,7 @@ impl Eq for Event {} // BinaryHeap is a max-heap. So we need to reverse the order. impl PartialOrd for Event { fn partial_cmp(&self, other: &Self) -> Option { - other.deadline.partial_cmp(&self.deadline) + Some(self.cmp(other)) } } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index a56a283..4cef0b7 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.80.1" +channel = "1.81"