Skip to content

Commit e043361

Browse files
authored
Merge pull request #2717 from benbrandt/simplify-epoch-increment-thread
simplify break condition for epoch ticker thread
2 parents 17e8477 + 56253c5 commit e043361

File tree

4 files changed

+8
-18
lines changed

4 files changed

+8
-18
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ edition = { workspace = true }
77
[dependencies]
88
anyhow = "1.0"
99
async-trait = "0.1"
10-
crossbeam-channel = "0.5"
1110
tracing = { workspace = true }
1211
wasmtime = { workspace = true }
1312
wasmtime-wasi = { workspace = true }

crates/core/src/lib.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use std::sync::OnceLock;
1919
use std::{path::PathBuf, time::Duration};
2020

2121
use anyhow::Result;
22-
use crossbeam_channel::Sender;
2322
use http::Request;
2423
use tracing::{field::Empty, instrument};
2524
use wasmtime::{InstanceAllocationStrategy, PoolingAllocationConfig};
@@ -406,27 +405,24 @@ impl<T: Send + Sync> EngineBuilder<T> {
406405
self.epoch_ticker_thread = enable;
407406
}
408407

409-
fn maybe_spawn_epoch_ticker(&self) -> Option<Sender<()>> {
408+
fn maybe_spawn_epoch_ticker(&self) {
410409
if !self.epoch_ticker_thread {
411-
return None;
410+
return;
412411
}
413-
let engine = self.engine.clone();
412+
let engine_weak = self.engine.weak();
414413
let interval = self.epoch_tick_interval;
415-
let (send, recv) = crossbeam_channel::bounded(0);
416414
std::thread::spawn(move || loop {
417-
match recv.recv_timeout(interval) {
418-
Err(crossbeam_channel::RecvTimeoutError::Timeout) => (),
419-
Err(crossbeam_channel::RecvTimeoutError::Disconnected) => break,
420-
res => panic!("unexpected epoch_ticker_signal: {res:?}"),
421-
}
415+
std::thread::sleep(interval);
416+
let Some(engine) = engine_weak.upgrade() else {
417+
break;
418+
};
422419
engine.increment_epoch();
423420
});
424-
Some(send)
425421
}
426422

427423
/// Builds an [`Engine`] from this builder.
428424
pub fn build(self) -> Engine<T> {
429-
let epoch_ticker_signal = self.maybe_spawn_epoch_ticker();
425+
self.maybe_spawn_epoch_ticker();
430426

431427
let host_components = self.host_components_builder.build();
432428

@@ -436,7 +432,6 @@ impl<T: Send + Sync> EngineBuilder<T> {
436432
module_linker: self.module_linker,
437433
host_components,
438434
epoch_tick_interval: self.epoch_tick_interval,
439-
_epoch_ticker_signal: epoch_ticker_signal,
440435
}
441436
}
442437
}
@@ -449,8 +444,6 @@ pub struct Engine<T> {
449444
module_linker: ModuleLinker<T>,
450445
host_components: HostComponents,
451446
epoch_tick_interval: Duration,
452-
// Matching receiver closes on drop
453-
_epoch_ticker_signal: Option<Sender<()>>,
454447
}
455448

456449
impl<T: OutboundWasiHttpHandler + Send + Sync> Engine<T> {

examples/spin-timer/Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)