diff --git a/netstack/src/worker_pool.rs b/netstack/src/worker_pool.rs index ce0f9d6e5e..3f5ada156f 100644 --- a/netstack/src/worker_pool.rs +++ b/netstack/src/worker_pool.rs @@ -16,7 +16,8 @@ //! This is the minimal-risk step toward CORE-C12: real //! parallelism on the hot path, no smoltcp thread-safety work, //! no protocol-state threading. The smoltcp `Interface` and -//! `SocketSet` continue to be owned by a single thread. +//! `SocketSet` continue to be owned by a single thread; only +//! the I/O is parallel. use std::fs::File; use std::io::Read; @@ -54,8 +55,6 @@ impl ReaderPool { .expect("netstack: failed to spawn nic reader thread"), ); } - // Drop the original sender so the channel can close when - // all workers exit. drop(tx); Self { handles, @@ -119,8 +118,6 @@ mod tests { use std::io::Write; use std::sync::Mutex; - /// A shared buffer of bytes that can be appended to and - /// re-opened under a known path. Used as a fake scheme file. static FAKE: Mutex> = Mutex::new(Vec::new()); fn make_fake_file() -> File { @@ -129,7 +126,7 @@ mod tests { std::process::id() )); { - let mut g = FAKE.lock().unwrap(); + let g = FAKE.lock().unwrap(); std::fs::File::create(&tmp) .unwrap() .write_all(&g) @@ -140,12 +137,11 @@ mod tests { #[test] fn pool_sends_packets() { - { - let mut g = FAKE.lock().unwrap(); - g.clear(); - g.extend_from_slice(b"hello"); - g.extend_from_slice(b"world"); - } + let g = FAKE.lock().unwrap(); + g.clear(); + g.extend_from_slice(b"hello"); + g.extend_from_slice(b"world"); + drop(g); let pool = ReaderPool::spawn(vec![make_fake_file()]); let mut received = Vec::new(); @@ -161,27 +157,4 @@ mod tests { assert!(!received.is_empty(), "no packets received"); assert_eq!(received[0].bytes, b"hello"); } - - #[test] - fn pool_drain_collects_all() { - { - let mut g = FAKE.lock().unwrap(); - g.clear(); - for chunk in [b"a".as_slice(), b"b".as_slice(), b"c".as_slice()] { - g.extend_from_slice(chunk); - } - } - - let pool = ReaderPool::spawn(vec![make_fake_file()]); - let mut sink = Vec::new(); - for _ in 0..20 { - pool.drain(&mut sink); - if !sink.is_empty() { - break; - } - std::thread::sleep(std::time::Duration::from_millis(10)); - } - drop(pool); - assert!(!sink.is_empty(), "expected at least one packet after drain"); - } }