MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / run_periodically

Method run_periodically

crates/fuzzing/src/oracles.rs:1033–1052  ·  view source on GitHub ↗
(&mut self, dur: Duration, mut closure: impl FnMut() + Send + 'static)

Source from the content-addressed store, hash-verified

1031
1032impl HelperThread {
1033 fn run_periodically(&mut self, dur: Duration, mut closure: impl FnMut() + Send + 'static) {
1034 let state = self.state.clone();
1035 self.thread = Some(std::thread::spawn(move || {
1036 // Using our mutex/condvar we wait here for the first of `dur` to
1037 // pass or the `HelperThread` instance to get dropped.
1038 let mut should_exit = state.should_exit.lock().unwrap();
1039 while !*should_exit {
1040 let (lock, result) = state
1041 .should_exit_cvar
1042 .wait_timeout(should_exit, dur)
1043 .unwrap();
1044 should_exit = lock;
1045 // If we timed out for sure then there's no need to continue
1046 // since we'll just abort on the next `checked_sub` anyway.
1047 if result.timed_out() {
1048 closure();
1049 }
1050 }
1051 }));
1052 }
1053}
1054
1055impl Drop for HelperThread {

Callers 2

instantiateFunction · 0.80
call_asyncFunction · 0.80

Calls 4

spawnFunction · 0.85
cloneMethod · 0.45
unwrapMethod · 0.45
lockMethod · 0.45

Tested by

no test coverage detected