Skip to content

Commit ecc5f88

Browse files
committed
move Sleep impl from foreign_items to time
1 parent 4d06aa8 commit ecc5f88

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

src/shims/time.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,30 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
233233

234234
Ok(0)
235235
}
236+
237+
#[allow(non_snake_case)]
238+
fn Sleep(&mut self, timeout: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx> {
239+
let this = self.eval_context_mut();
240+
241+
this.check_no_isolation("`Sleep`")?;
242+
243+
let timeout_ms = this.read_scalar(timeout)?.to_u32()?;
244+
245+
let duration = Duration::from_millis(timeout_ms.into());
246+
let timeout_time = Time::Monotonic(Instant::now().checked_add(duration).unwrap());
247+
248+
let active_thread = this.get_active_thread();
249+
this.block_thread(active_thread);
250+
251+
this.register_timeout_callback(
252+
active_thread,
253+
timeout_time,
254+
Box::new(move |ecx| {
255+
ecx.unblock_thread(active_thread);
256+
Ok(())
257+
}),
258+
);
259+
260+
Ok(())
261+
}
236262
}

src/shims/windows/foreign_items.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -228,24 +228,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
228228
let [timeout] =
229229
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
230230

231-
this.check_no_isolation("`Sleep`")?;
232-
233-
let timeout_ms = this.read_scalar(timeout)?.to_u32()?;
234-
235-
let duration = Duration::from_millis(timeout_ms as u64);
236-
let timeout_time = Time::Monotonic(Instant::now().checked_add(duration).unwrap());
237-
238-
let active_thread = this.get_active_thread();
239-
this.block_thread(active_thread);
240-
241-
this.register_timeout_callback(
242-
active_thread,
243-
timeout_time,
244-
Box::new(move |ecx| {
245-
ecx.unblock_thread(active_thread);
246-
Ok(())
247-
}),
248-
);
231+
this.Sleep(timeout)?;
249232
}
250233

251234
// Synchronization primitives

0 commit comments

Comments
 (0)