Skip to content

Commit

Permalink
define some types
Browse files Browse the repository at this point in the history
  • Loading branch information
DaughterOfMars committed Nov 18, 2024
1 parent 2b27c37 commit 2532741
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
5 changes: 3 additions & 2 deletions msim/src/sim/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -372,7 +372,7 @@ pub struct NodeBuilder<'a> {
handle: &'a Handle,
name: Option<String>,
ip: Option<IpAddr>,
init: Option<Arc<dyn Fn(&task::TaskNodeHandle) + Send + Sync>>,
init: Option<InitFn>,
}

impl<'a> NodeBuilder<'a> {
Expand Down Expand Up @@ -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(())
Expand Down
16 changes: 8 additions & 8 deletions msim/src/sim/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ struct PanicWrapper {
restart_after: Option<Duration>,
}

struct PanicHookGuard(Option<Box<dyn Fn(&std::panic::PanicInfo<'_>) + Sync + Send + 'static>>);
type PanicFn = Box<dyn Fn(&std::panic::PanicInfo<'_>) + Sync + Send + 'static>;

struct PanicHookGuard(Option<PanicFn>);

impl PanicHookGuard {
fn new() -> Self {
Expand Down Expand Up @@ -337,11 +339,13 @@ pub(crate) struct TaskHandle {
}
assert_send_sync!(TaskHandle);

pub(crate) type InitFn = Arc<dyn Fn(&TaskNodeHandle) + Send + Sync>;

struct Node {
info: Arc<TaskInfo>,
paused: Vec<Runnable>,
/// A function to spawn the initial task.
init: Option<Arc<dyn Fn(&TaskNodeHandle) + Send + Sync>>,
init: Option<InitFn>,
}

impl TaskHandle {
Expand Down Expand Up @@ -392,11 +396,7 @@ impl TaskHandle {
}

/// Create a new node.
pub fn create_node(
&self,
name: Option<String>,
init: Option<Arc<dyn Fn(&TaskNodeHandle) + Send + Sync>>,
) -> TaskNodeHandle {
pub fn create_node(&self, name: Option<String>, init: Option<InitFn>) -> 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));
Expand Down Expand Up @@ -690,7 +690,7 @@ impl AbortHandle {
ret
}

fn inner(&self) -> Box<Arc<InnerHandle<()>>> {
fn inner(&self) -> Arc<InnerHandle<()>> {
unsafe { ErasablePtr::unerase(self.inner) }
}
}
Expand Down
1 change: 1 addition & 0 deletions msim/src/sim/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

Expand Down
2 changes: 1 addition & 1 deletion msim/src/sim/time/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ordering> {
other.deadline.partial_cmp(&self.deadline)
Some(self.cmp(other))
}
}

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.80.1"
channel = "1.81"

0 comments on commit 2532741

Please sign in to comment.