Skip to content

Commit 1667669

Browse files
committed
tweak
1 parent 68f559e commit 1667669

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

tokio/src/process/unix/orphan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ pub(crate) mod test {
295295
#[cfg_attr(miri, ignore)] // Miri does not support epoll.
296296
#[test]
297297
fn does_not_register_signal_if_queue_empty() {
298-
let (io_driver, io_handle) = IoDriver::new(1024).unwrap();
298+
let (io_driver, io_handle) = IoDriver::new(1024, 1).unwrap();
299299
let signal_driver = SignalDriver::new(io_driver, &io_handle).unwrap();
300300
let handle = signal_driver.handle();
301301

tokio/src/runtime/builder.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,13 @@ impl Builder {
940940
enable_time: self.enable_time,
941941
start_paused: self.start_paused,
942942
nevents: self.nevents,
943+
num_workers: match self.kind {
944+
Kind::CurrentThread => 1,
945+
#[cfg(feature = "rt-multi-thread")]
946+
Kind::MultiThread => self
947+
.worker_threads
948+
.unwrap_or_else(crate::loom::sys::num_cpus),
949+
},
943950
}
944951
}
945952

@@ -1457,7 +1464,7 @@ impl Builder {
14571464
use crate::runtime::scheduler;
14581465
use crate::runtime::Config;
14591466

1460-
let (driver, driver_handle) = driver::Driver::new(self.get_cfg(), 1)?;
1467+
let (driver, driver_handle) = driver::Driver::new(self.get_cfg())?;
14611468

14621469
// Blocking pool
14631470
let blocking_pool = blocking::create_blocking_pool(self, self.max_blocking_threads);
@@ -1612,7 +1619,7 @@ cfg_rt_multi_thread! {
16121619

16131620
let worker_threads = self.worker_threads.unwrap_or_else(num_cpus);
16141621

1615-
let (driver, driver_handle) = driver::Driver::new(self.get_cfg(), worker_threads)?;
1622+
let (driver, driver_handle) = driver::Driver::new(self.get_cfg())?;
16161623

16171624
// Create the blocking pool
16181625
let blocking_pool =

tokio/src/runtime/driver.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ pub(crate) struct Cfg {
4040
pub(crate) enable_pause_time: bool,
4141
pub(crate) start_paused: bool,
4242
pub(crate) nevents: usize,
43+
pub(crate) num_workers: usize,
4344
}
4445

4546
impl Driver {
46-
pub(crate) fn new(cfg: Cfg, num_workers: usize) -> io::Result<(Self, Handle)> {
47+
pub(crate) fn new(cfg: Cfg) -> io::Result<(Self, Handle)> {
4748
let (io_stack, io_handle, signal_handle) =
48-
create_io_stack(cfg.enable_io, cfg.nevents, num_workers)?;
49+
create_io_stack(cfg.enable_io, cfg.nevents, cfg.num_workers)?;
4950

5051
let clock = create_clock(cfg.enable_pause_time, cfg.start_paused);
5152

@@ -142,7 +143,7 @@ cfg_io_driver! {
142143
assert!(!enabled);
143144

144145
let ret = if enabled {
145-
let (io_driver, io_handle) = crate::runtime::io::Driver::new(nevents,num_workers)?;
146+
let (io_driver, io_handle) = crate::runtime::io::Driver::new(nevents, num_workers)?;
146147

147148
let (signal_driver, signal_handle) = create_signal_driver(io_driver, &io_handle)?;
148149
let process_driver = create_process_driver(signal_driver);
@@ -203,7 +204,7 @@ cfg_not_io_driver! {
203204
#[derive(Debug)]
204205
pub(crate) struct IoStack(ParkThread);
205206

206-
fn create_io_stack(_enabled: bool, _nevents: usize, _num_worker: usize) -> io::Result<(IoStack, IoHandle, SignalHandle)> {
207+
fn create_io_stack(_enabled: bool, _nevents: usize, _num_worker: usize) -> io::Result<(IoStack, IoHandle, SignalHandle)> {
207208
let park_thread = ParkThread::new();
208209
let unpark_thread = park_thread.unpark();
209210
Ok((IoStack(park_thread), unpark_thread, Default::default()))

tokio/src/runtime/driver/op.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub(crate) enum State {
3737

3838
pub(crate) struct Op<T: Cancellable> {
3939
// Uring shard id this operation belongs to
40-
pub(crate) shard_id: usize,
40+
shard_id: usize,
4141
// Handle to the runtime
4242
handle: Handle,
4343
// State of this Op
@@ -55,8 +55,9 @@ impl<T: Cancellable> Op<T> {
5555
pub(crate) unsafe fn new(entry: Entry, data: T) -> Self {
5656
let handle = Handle::current();
5757
let shard_size = handle.inner.driver().io().uring_context.len();
58+
let shard_id = OpId::next().as_u64() as usize % shard_size;
5859
Self {
59-
shard_id: OpId::next().as_u64() as usize % shard_size,
60+
shard_id,
6061
handle,
6162
data: Some(data),
6263
state: State::Initialize(Some(entry)),

0 commit comments

Comments
 (0)