id stringlengths 22 133 | text stringlengths 40 40.2k | arch stringclasses 1
value | syntax stringclasses 1
value | kind stringclasses 4
values | repo stringclasses 27
values | path stringlengths 5 116 | license stringclasses 6
values | commit stringlengths 40 40 | source_host stringclasses 1
value | category stringclasses 16
values | source_url stringlengths 85 196 | line_start int64 1 4.28k | line_end int64 4 4.31k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tokio-rs/tokio:tokio/src/runtime/builder.rs:10 | /// .unwrap();
/// ```
pub fn enable_time(&mut self) -> &mut Self {
self.enable_time = true;
self
}
}
}
cfg_rt_core! {
impl Builder {
fn build_basic_runtime(&mut self) -> io::Result<Runtime> {
use crate::runtime::{BasicScheduler, Kind};
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | dc356a41589a6129ec5db375e0ab9baee8612b83 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dc356a41589a6129ec5db375e0ab9baee8612b83/tokio/src/runtime/builder.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:11 | },
blocking_pool,
})
}
}
}
cfg_rt_threaded! {
impl Builder {
fn build_threaded_runtime(&mut self) -> io::Result<Runtime> {
use crate::runtime::{Kind, ThreadPool};
use crate::runtime::park::Parker;
let clock = time::create_clock();... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | dc356a41589a6129ec5db375e0ab9baee8612b83 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dc356a41589a6129ec5db375e0ab9baee8612b83/tokio/src/runtime/builder.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:12 | }
impl Default for Builder {
fn default() -> Self {
Self::new()
}
}
impl fmt::Debug for Builder {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Builder")
.field("kind", &self.kind)
.field("num_threads", &self.num_threads)
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | dc356a41589a6129ec5db375e0ab9baee8612b83 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dc356a41589a6129ec5db375e0ab9baee8612b83/tokio/src/runtime/builder.rs | 441 | 460 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:1 | use crate::runtime::handle::Handle;
use crate::runtime::shell::Shell;
use crate::runtime::{blocking, io, time, Callback, Runtime, Spawner};
use std::fmt;
#[cfg(not(loom))]
use std::sync::Arc;
/// Builds Tokio Runtime with custom configuration values.
///
/// Methods can be chained in order to set the configuration va... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/builder.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:2 | kind: Kind,
/// Whether or not to enable the I/O driver
enable_io: bool,
/// Whether or not to enable the time driver
enable_time: bool,
/// The number of worker threads.
///
/// Only used when not using the current-thread executor.
num_threads: usize,
/// Name used for threads s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/builder.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:3 | pub fn new() -> Builder {
Builder {
// No task execution by default
kind: Kind::Shell,
// I/O defaults to "off"
enable_io: false,
// Time defaults to "off"
enable_time: false,
// Default to use an equal number of threads to n... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/builder.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:4 | /// .unwrap();
/// ```
pub fn enable_all(&mut self) -> &mut Self {
#[cfg(feature = "io-driver")]
self.enable_io();
#[cfg(feature = "time")]
self.enable_time();
self
}
/// Set the maximum number of worker threads for the `Runtime`'s thread pool.
///
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/builder.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:5 | self
}
/// Use a multi-threaded scheduler for executing tasks.
#[cfg(feature = "rt-threaded")]
pub fn threaded_scheduler(&mut self) -> &mut Self {
self.kind = Kind::ThreadPool;
self
}
/// Set name of threads spawned by the `Runtime`'s thread pool.
///
/// The default na... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/builder.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:6 | /// ```
/// # use tokio::runtime;
///
/// # pub fn main() {
/// let rt = runtime::Builder::new()
/// .thread_stack_size(32 * 1024)
/// .build();
/// # }
/// ```
pub fn thread_stack_size(&mut self, val: usize) -> &mut Self {
self.thread_stack_size = Some(val);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/builder.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:7 | /// Execute function `f` before each thread stops.
///
/// This is intended for bookkeeping and monitoring use cases.
///
/// # Examples
///
/// ```
/// # use tokio::runtime;
///
/// # pub fn main() {
/// let runtime = runtime::Builder::new()
/// .on_thread_stop(|| {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/builder.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:8 | /// });
/// ```
pub fn build(&mut self) -> io::Result<Runtime> {
match self.kind {
Kind::Shell => self.build_shell_runtime(),
#[cfg(feature = "rt-core")]
Kind::Basic => self.build_basic_runtime(),
#[cfg(feature = "rt-threaded")]
Kind::ThreadPoo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/builder.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:9 | cfg_io_driver! {
impl Builder {
/// Enable the I/O driver.
///
/// Doing this enables using net, process, signal, and some I/O types on
/// the runtime.
///
/// # Examples
///
/// ```
/// use tokio::runtime;
///
/// let rt = run... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/builder.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:10 | /// ```
pub fn enable_time(&mut self) -> &mut Self {
self.enable_time = true;
self
}
}
}
cfg_rt_core! {
impl Builder {
fn build_basic_runtime(&mut self) -> io::Result<Runtime> {
use crate::runtime::{BasicScheduler, Kind};
let clock = time... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/builder.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:11 | blocking_pool,
})
}
}
}
cfg_rt_threaded! {
impl Builder {
fn build_threaded_runtime(&mut self) -> io::Result<Runtime> {
use crate::runtime::{Kind, ThreadPool};
use crate::runtime::park::Parker;
let clock = time::create_clock();
let (... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/builder.rs | 401 | 459 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:1 | use crate::loom::sync::Arc;
use crate::runtime::handle::{self, Handle};
use crate::runtime::shell::Shell;
use crate::runtime::{blocking, io, time, Runtime};
use std::fmt;
/// Builds Tokio Runtime with custom configuration values.
///
/// Methods can be chained in order to set the configuration values. The
/// Runtime... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/builder.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:2 | /// The number of worker threads.
///
/// Only used when not using the current-thread executor.
num_threads: usize,
/// Name used for threads spawned by the runtime.
pub(super) thread_name: String,
/// Stack size used for threads spawned by the runtime.
pub(super) thread_stack_size: Option... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/builder.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:3 | Builder {
// No task execution by default
kind: Kind::Shell,
// Default to use an equal number of threads to number of CPU cores
num_threads: crate::loom::sys::num_cpus(),
// Default thread name
thread_name: "tokio-runtime-worker".into(),
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/builder.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:4 | self
}
/// Use a simpler scheduler that runs all tasks on the current-thread.
///
/// The executor and all necessary drivers will all be run on the current
/// thread during `block_on` calls.
#[cfg(feature = "rt-core")]
pub fn basic_scheduler(&mut self) -> &mut Self {
self.kind = Ki... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/builder.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:6 | /// # }
/// ```
#[cfg(not(loom))]
pub fn after_start<F>(&mut self, f: F) -> &mut Self
where
F: Fn() + Send + Sync + 'static,
{
self.after_start = Some(Arc::new(f));
self
}
/// Execute function `f` before each thread stops.
///
/// This is intended for bookkee... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/builder.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:7 | ///
/// # Examples
///
/// ```
/// use tokio::runtime::Builder;
///
/// let mut rt = Builder::new().build().unwrap();
///
/// rt.block_on(async {
/// println!("Hello from the Tokio runtime");
/// });
/// ```
pub fn build(&mut self) -> io::Result<Runtime> {
mat... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/builder.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:8 | kind: handle::Kind::Shell,
io_handles,
time_handles,
clock,
blocking_spawner,
},
blocking_pool,
})
}
}
cfg_rt_core! {
impl Builder {
fn build_basic_runtime(&mut self) -> io::Result<Runtime> {
use... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/builder.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:9 | io_handles,
time_handles,
clock,
blocking_spawner,
},
blocking_pool,
})
}
}
}
cfg_rt_threaded! {
impl Builder {
fn build_threaded_runtime(&mut self) -> io::Result<Runtime> {
use c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/builder.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:10 | let io_handles = io_handles.clone();
let time_handles = time_handles.clone();
let after_start = self.after_start.clone();
let before_stop = self.before_stop.clone();
let around_worker = Arc::new(Box::new(move |index, next: &mut dyn FnMut()| {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/builder.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:11 | handle: Handle {
kind: handle::Kind::ThreadPool(spawner),
io_handles,
time_handles,
clock,
blocking_spawner,
},
blocking_pool,
})
}
}
}
impl Default for Builder {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/builder.rs | 401 | 431 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:2 | /// The number of worker threads.
///
/// Only used when not using the current-thread executor.
num_threads: usize,
/// Name used for threads spawned by the runtime.
pub(super) thread_name: String,
/// Stack size used for threads spawned by the runtime.
pub(super) thread_stack_size: Option... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 3f0eabe7798de624f5ee9c7562803bfb97e6088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3f0eabe7798de624f5ee9c7562803bfb97e6088f/tokio/src/runtime/builder.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:3 | Builder {
// No task execution by default
kind: Kind::Shell,
// Default to use an equal number of threads to number of CPU cores
num_threads: crate::loom::sys::num_cpus(),
// Default thread name
thread_name: "tokio-runtime-worker".into(),
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 3f0eabe7798de624f5ee9c7562803bfb97e6088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3f0eabe7798de624f5ee9c7562803bfb97e6088f/tokio/src/runtime/builder.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:4 | self
}
/// Use a simpler scheduler that runs all tasks on the current-thread.
///
/// The executor and all necessary drivers will all be run on the current
/// thread during `block_on` calls.
#[cfg(feature = "rt-core")]
pub fn basic_scheduler(&mut self) -> &mut Self {
self.kind = Ki... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 3f0eabe7798de624f5ee9c7562803bfb97e6088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3f0eabe7798de624f5ee9c7562803bfb97e6088f/tokio/src/runtime/builder.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:6 | /// # }
/// ```
#[cfg(not(loom))]
pub fn after_start<F>(&mut self, f: F) -> &mut Self
where
F: Fn() + Send + Sync + 'static,
{
self.after_start = Some(Arc::new(f));
self
}
/// Execute function `f` before each thread stops.
///
/// This is intended for bookkee... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 3f0eabe7798de624f5ee9c7562803bfb97e6088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3f0eabe7798de624f5ee9c7562803bfb97e6088f/tokio/src/runtime/builder.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:7 | ///
/// # Examples
///
/// ```
/// use tokio::runtime::Builder;
///
/// let mut rt = Builder::new().build().unwrap();
///
/// rt.block_on(async {
/// println!("Hello from the Tokio runtime");
/// });
/// ```
pub fn build(&mut self) -> io::Result<Runtime> {
mat... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 3f0eabe7798de624f5ee9c7562803bfb97e6088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3f0eabe7798de624f5ee9c7562803bfb97e6088f/tokio/src/runtime/builder.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:8 | kind: handle::Kind::Shell,
io_handles,
time_handles,
clock,
blocking_spawner,
},
blocking_pool,
})
}
#[cfg(feature = "rt-core")]
fn build_basic_runtime(&mut self) -> io::Result<Runtime> {
use crate::runt... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 3f0eabe7798de624f5ee9c7562803bfb97e6088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3f0eabe7798de624f5ee9c7562803bfb97e6088f/tokio/src/runtime/builder.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:9 | clock,
blocking_spawner,
},
blocking_pool,
})
}
#[cfg(feature = "rt-full")]
fn build_threaded_runtime(&mut self) -> io::Result<Runtime> {
use crate::runtime::{Kind, ThreadPool};
use std::sync::Mutex;
let clock = time::create_clock();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 3f0eabe7798de624f5ee9c7562803bfb97e6088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3f0eabe7798de624f5ee9c7562803bfb97e6088f/tokio/src/runtime/builder.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:10 | let around_worker = Arc::new(Box::new(move |index, next: &mut dyn FnMut()| {
// Configure the I/O driver
let _io = io::set_default(&io_handles[index]);
// Configure time
time::with_default(&time_handles[index], &clock, || {
// Call the... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 3f0eabe7798de624f5ee9c7562803bfb97e6088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3f0eabe7798de624f5ee9c7562803bfb97e6088f/tokio/src/runtime/builder.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:11 | blocking_spawner,
},
blocking_pool,
})
}
}
impl Default for Builder {
fn default() -> Self {
Self::new()
}
}
impl fmt::Debug for Builder {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Builder")
.field("kind",... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 3f0eabe7798de624f5ee9c7562803bfb97e6088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3f0eabe7798de624f5ee9c7562803bfb97e6088f/tokio/src/runtime/builder.rs | 401 | 425 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:2 | /// The number of worker threads.
///
/// Only used when not using the current-thread executor.
num_threads: usize,
/// Name used for threads spawned by the runtime.
pub(super) thread_name: String,
/// Stack size used for threads spawned by the runtime.
pub(super) thread_stack_size: Option... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/runtime/builder.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:3 | Builder {
// No task execution by default
kind: Kind::Shell,
// Default to use an equal number of threads to number of CPU cores
num_threads: crate::loom::sys::num_cpus(),
// Default thread name
thread_name: "tokio-runtime-worker".into(),
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/runtime/builder.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:4 | self
}
/// Use only the current thread for executing tasks.
///
/// The executor and all necessary drivers will all be run on the current
/// thread during `block_on` calls.
#[cfg(feature = "rt-core")]
pub fn current_thread(&mut self) -> &mut Self {
self.kind = Kind::CurrentThread;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/runtime/builder.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:6 | /// # }
/// ```
#[cfg(not(loom))]
pub fn after_start<F>(&mut self, f: F) -> &mut Self
where
F: Fn() + Send + Sync + 'static,
{
self.after_start = Some(Arc::new(f));
self
}
/// Execute function `f` before each thread stops.
///
/// This is intended for bookkee... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/runtime/builder.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:7 | ///
/// # Examples
///
/// ```
/// use tokio::runtime::Builder;
///
/// let mut rt = Builder::new().build().unwrap();
///
/// rt.block_on(async {
/// println!("Hello from the Tokio runtime");
/// });
/// ```
pub fn build(&mut self) -> io::Result<Runtime> {
mat... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/runtime/builder.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:8 | kind: handle::Kind::Shell,
io_handles,
time_handles,
clock,
blocking_spawner,
},
blocking_pool,
})
}
#[cfg(feature = "rt-core")]
fn build_current_thread(&mut self) -> io::Result<Runtime> {
use crate::run... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/runtime/builder.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:9 | clock,
blocking_spawner,
},
blocking_pool,
})
}
#[cfg(feature = "rt-full")]
fn build_threadpool(&mut self) -> io::Result<Runtime> {
use crate::runtime::{Kind, ThreadPool};
use std::sync::Mutex;
let clock = time::create_clock();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/runtime/builder.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:2 | /// The task execution model to use.
kind: Kind,
/// The number of worker threads.
///
/// Only used when not using the current-thread executor.
num_threads: usize,
/// Name used for threads spawned by the runtime.
thread_name: String,
/// Stack size used for threads spawned by the ru... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 7e35922a1d282b1e3dadf037cd237be336b331fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7e35922a1d282b1e3dadf037cd237be336b331fb/tokio/src/runtime/builder.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:3 | /// Returns a new runtime builder initialized with default configuration
/// values.
///
/// Configuration methods can be chained on the return value.
pub fn new() -> Builder {
Builder {
// No task execution by default
kind: Kind::Shell,
// Default to use an ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 7e35922a1d282b1e3dadf037cd237be336b331fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7e35922a1d282b1e3dadf037cd237be336b331fb/tokio/src/runtime/builder.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:4 | /// let rt = runtime::Builder::new()
/// .num_threads(4)
/// .build()
/// .unwrap();
/// # }
/// ```
pub fn num_threads(&mut self, val: usize) -> &mut Self {
self.num_threads = val;
self
}
/// Use only the current thread for executing tasks.
///
/// T... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 7e35922a1d282b1e3dadf037cd237be336b331fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7e35922a1d282b1e3dadf037cd237be336b331fb/tokio/src/runtime/builder.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:5 | /// .build();
/// # }
/// ```
pub fn thread_name(&mut self, val: impl Into<String>) -> &mut Self {
self.thread_name = val.into();
self
}
/// Set the stack size (in bytes) for worker threads.
///
/// The actual stack size may be greater than this value if the platform
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 7e35922a1d282b1e3dadf037cd237be336b331fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7e35922a1d282b1e3dadf037cd237be336b331fb/tokio/src/runtime/builder.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:6 | /// # use tokio::runtime;
///
/// # pub fn main() {
/// let runtime = runtime::Builder::new()
/// .after_start(|| {
/// println!("thread started");
/// })
/// .build();
/// # }
/// ```
#[cfg(not(loom))]
pub fn after_start<F>(&mut self, f: F) -> &mut Self
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 7e35922a1d282b1e3dadf037cd237be336b331fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7e35922a1d282b1e3dadf037cd237be336b331fb/tokio/src/runtime/builder.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:7 | {
self.before_stop = Some(Arc::new(f));
self
}
/// Set the `Clock` instance that will be used by the runtime.
pub fn clock(&mut self, clock: timer::Clock) -> &mut Self {
self.clock = clock;
self
}
/// Create the configured `Runtime`.
///
/// The returned `Th... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 7e35922a1d282b1e3dadf037cd237be336b331fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7e35922a1d282b1e3dadf037cd237be336b331fb/tokio/src/runtime/builder.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:8 | let (net, handle) = io::create()?;
let net_handles = vec![handle];
let (_timer, handle) = timer::create(net, self.clock.clone());
let timer_handles = vec![handle];
Ok(Runtime {
kind: Kind::Shell,
net_handles,
timer_handles,
#[cfg(feature ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 7e35922a1d282b1e3dadf037cd237be336b331fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7e35922a1d282b1e3dadf037cd237be336b331fb/tokio/src/runtime/builder.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:9 | })
}
#[cfg(feature = "rt-full")]
fn build_threadpool(&mut self) -> io::Result<Runtime> {
use crate::runtime::{Kind, ThreadPool};
use crate::time::clock;
use std::sync::Mutex;
let mut net_handles = Vec::new();
let mut timer_handles = Vec::new();
let mut timer... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 7e35922a1d282b1e3dadf037cd237be336b331fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7e35922a1d282b1e3dadf037cd237be336b331fb/tokio/src/runtime/builder.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:10 | // Configure the clock
clock::with_default(&clock, || {
// Configure the timer
let _timer = timer::set_default(&timer_handles[index]);
// Call the start callback
if let Some(after_start) = after_start.as_ref() {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 7e35922a1d282b1e3dadf037cd237be336b331fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7e35922a1d282b1e3dadf037cd237be336b331fb/tokio/src/runtime/builder.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:11 | // Create the blocking pool
blocking::Pool::new(self.thread_name.clone(), self.thread_stack_size)
}
}
impl Default for Builder {
fn default() -> Self {
Self::new()
}
}
impl fmt::Debug for Builder {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("B... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 7e35922a1d282b1e3dadf037cd237be336b331fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7e35922a1d282b1e3dadf037cd237be336b331fb/tokio/src/runtime/builder.rs | 401 | 424 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:8 | let (net, handle) = io::create()?;
let net_handles = vec![handle];
let (_timer, handle) = timer::create(net, self.clock.clone());
let timer_handles = vec![handle];
Ok(Runtime {
kind: Kind::Shell,
net_handles,
timer_handles,
#[cfg(feature ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 4dbe6af0a1a1c8e579b92ec8ffc1d419244e0944 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4dbe6af0a1a1c8e579b92ec8ffc1d419244e0944/tokio/src/runtime/builder.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:9 | })
}
#[cfg(feature = "rt-full")]
fn build_threadpool(&mut self) -> io::Result<Runtime> {
use crate::runtime::{Kind, ThreadPool};
use crate::timer::clock;
use std::sync::Mutex;
let mut net_handles = Vec::new();
let mut timer_handles = Vec::new();
let mut time... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 4dbe6af0a1a1c8e579b92ec8ffc1d419244e0944 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4dbe6af0a1a1c8e579b92ec8ffc1d419244e0944/tokio/src/runtime/builder.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:1 | #[cfg(feature = "blocking")]
use crate::runtime::blocking::{Pool, PoolWaiter};
#[cfg(feature = "rt-current-thread")]
use crate::runtime::current_thread::CurrentThread;
#[cfg(feature = "rt-full")]
use crate::runtime::thread_pool;
use crate::runtime::{io, timer, Runtime};
use std::fmt;
use std::sync::Arc;
/// Builds To... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | d5c1119c881c9a8b511aa9000fd26b9bda014256 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d5c1119c881c9a8b511aa9000fd26b9bda014256/tokio/src/runtime/builder.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:2 | /// // use runtime ...
/// }
/// ```
pub struct Builder {
/// The task execution model to use.
kind: Kind,
/// The number of worker threads.
///
/// Only used when not using the current-thread executor.
num_threads: usize,
/// Name used for threads spawned by the runtime.
thread_na... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | d5c1119c881c9a8b511aa9000fd26b9bda014256 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d5c1119c881c9a8b511aa9000fd26b9bda014256/tokio/src/runtime/builder.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:3 | ///
/// Configuration methods can be chained on the return value.
pub fn new() -> Builder {
Builder {
// No task execution by default
kind: Kind::Shell,
// Default to use an equal number of threads to number of CPU cores
num_threads: crate::loom::sys::num... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | d5c1119c881c9a8b511aa9000fd26b9bda014256 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d5c1119c881c9a8b511aa9000fd26b9bda014256/tokio/src/runtime/builder.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:4 | /// .build()
/// .unwrap();
/// # }
/// ```
pub fn num_threads(&mut self, val: usize) -> &mut Self {
self.num_threads = val;
self
}
/// Use only the current thread for executing tasks.
///
/// The network driver, timer, and executor will all be run on the current... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | d5c1119c881c9a8b511aa9000fd26b9bda014256 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d5c1119c881c9a8b511aa9000fd26b9bda014256/tokio/src/runtime/builder.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:5 | /// ```
pub fn thread_name(&mut self, val: impl Into<String>) -> &mut Self {
self.thread_name = val.into();
self
}
/// Set the stack size (in bytes) for worker threads.
///
/// The actual stack size may be greater than this value if the platform
/// specifies minimal stack size.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | d5c1119c881c9a8b511aa9000fd26b9bda014256 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d5c1119c881c9a8b511aa9000fd26b9bda014256/tokio/src/runtime/builder.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:6 | /// # pub fn main() {
/// let runtime = runtime::Builder::new()
/// .after_start(|| {
/// println!("thread started");
/// })
/// .build();
/// # }
/// ```
pub fn after_start<F>(&mut self, f: F) -> &mut Self
where
F: Fn() + Send + Sync + 'static,
{
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | d5c1119c881c9a8b511aa9000fd26b9bda014256 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d5c1119c881c9a8b511aa9000fd26b9bda014256/tokio/src/runtime/builder.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:7 | /// Set the `Clock` instance that will be used by the runtime.
pub fn clock(&mut self, clock: timer::Clock) -> &mut Self {
self.clock = clock;
self
}
/// Create the configured `Runtime`.
///
/// The returned `ThreadPool` instance is ready to spawn tasks.
///
/// # Examples
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | d5c1119c881c9a8b511aa9000fd26b9bda014256 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d5c1119c881c9a8b511aa9000fd26b9bda014256/tokio/src/runtime/builder.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:8 | let timer_handles = vec![handle];
Ok(Runtime {
kind: Kind::Shell,
net_handles,
timer_handles,
#[cfg(feature = "blocking")]
blocking_pool: PoolWaiter::from(Pool::default()),
})
}
#[cfg(feature = "rt-current-thread")]
fn build_curre... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | d5c1119c881c9a8b511aa9000fd26b9bda014256 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d5c1119c881c9a8b511aa9000fd26b9bda014256/tokio/src/runtime/builder.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:9 | fn build_threadpool(&mut self) -> io::Result<Runtime> {
use crate::runtime::Kind;
use crate::timer::clock;
use std::sync::Mutex;
let mut net_handles = Vec::new();
let mut timer_handles = Vec::new();
let mut timers = Vec::new();
for _ in 0..self.num_threads {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | d5c1119c881c9a8b511aa9000fd26b9bda014256 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d5c1119c881c9a8b511aa9000fd26b9bda014256/tokio/src/runtime/builder.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:10 | builder
.around_worker(move |index, next| {
// Configure the network driver
let _net = io::set_default(&net_handles[index]);
// Configure the clock
clock::with_default(&clock, || {
// Configure the t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | d5c1119c881c9a8b511aa9000fd26b9bda014256 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d5c1119c881c9a8b511aa9000fd26b9bda014256/tokio/src/runtime/builder.rs | 361 | 416 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:11 | }
}
impl fmt::Debug for Builder {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Builder")
.field("kind", &self.kind)
.field("num_threads", &self.num_threads)
.field("thread_name", &self.thread_name)
.field("thread_stack_size",... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | d5c1119c881c9a8b511aa9000fd26b9bda014256 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d5c1119c881c9a8b511aa9000fd26b9bda014256/tokio/src/runtime/builder.rs | 401 | 416 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:1 | use crate::executor::blocking::{Pool, PoolWaiter};
use crate::executor::current_thread::CurrentThread;
#[cfg(feature = "rt-full")]
use crate::executor::thread_pool;
use crate::net::driver::Reactor;
use crate::runtime::{Runtime, Kind};
use crate::timer::clock::Clock;
use crate::timer::timer::Timer;
use std::sync::Arc;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | a6253ed05a1e0d14bc64915f5937c29092df9497 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a6253ed05a1e0d14bc64915f5937c29092df9497/tokio/src/runtime/builder.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:2 | ///
/// // use runtime ...
/// }
/// ```
pub struct Builder {
/// When `true`, use the current-thread executor.
current_thread: bool,
/// The number of worker threads.
///
/// Only used when not using the current-thread executor.
num_threads: usize,
/// Name used for threads spawned by... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | a6253ed05a1e0d14bc64915f5937c29092df9497 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a6253ed05a1e0d14bc64915f5937c29092df9497/tokio/src/runtime/builder.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:3 | num_threads: crate::loom::sys::num_cpus(),
// Default thread name
thread_name: "tokio-runtime-worker".into(),
// Do not set a stack size by default
thread_stack_size: None,
// No worker thread callbacks
after_start: None,
before_stop... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | a6253ed05a1e0d14bc64915f5937c29092df9497 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a6253ed05a1e0d14bc64915f5937c29092df9497/tokio/src/runtime/builder.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:5 | /// ```
/// # use tokio::runtime;
///
/// # pub fn main() {
/// let rt = runtime::Builder::new()
/// .thread_stack_size(32 * 1024)
/// .build();
/// # }
/// ```
pub fn thread_stack_size(&mut self, val: usize) -> &mut Self {
self.thread_stack_size = Some(val);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | a6253ed05a1e0d14bc64915f5937c29092df9497 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a6253ed05a1e0d14bc64915f5937c29092df9497/tokio/src/runtime/builder.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:6 | /// Execute function `f` before each thread stops.
///
/// This is intended for bookkeeping and monitoring use cases.
///
/// # Examples
///
/// ```
/// # use tokio::runtime;
///
/// # pub fn main() {
/// let runtime = runtime::Builder::new()
/// .before_stop(|| {
///... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | a6253ed05a1e0d14bc64915f5937c29092df9497 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a6253ed05a1e0d14bc64915f5937c29092df9497/tokio/src/runtime/builder.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:7 | /// let mut rt = Builder::new().build().unwrap();
///
/// rt.block_on(async {
/// println!("Hello from the Tokio runtime");
/// });
/// ```
pub fn build(&mut self) -> io::Result<Runtime> {
if self.current_thread {
self.build_current_thread()
} else {
s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | a6253ed05a1e0d14bc64915f5937c29092df9497 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a6253ed05a1e0d14bc64915f5937c29092df9497/tokio/src/runtime/builder.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:8 | #[cfg(not(feature = "rt-full"))]
fn build_threadpool(&mut self) -> io::Result<Runtime> {
self.build_current_thread()
}
#[cfg(feature = "rt-full")]
fn build_threadpool(&mut self) -> io::Result<Runtime> {
use crate::net::driver;
use crate::timer::{clock, timer};
use std::s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | a6253ed05a1e0d14bc64915f5937c29092df9497 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a6253ed05a1e0d14bc64915f5937c29092df9497/tokio/src/runtime/builder.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:9 | builder.num_threads(self.num_threads);
builder.name(&self.thread_name);
if let Some(stack_size) = self.thread_stack_size {
builder.stack_size(stack_size);
}
builder
.around_worker(move |index, next| {
// Configure the ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | a6253ed05a1e0d14bc64915f5937c29092df9497 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a6253ed05a1e0d14bc64915f5937c29092df9497/tokio/src/runtime/builder.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:10 | }
}
impl Default for Builder {
fn default() -> Self {
Self::new()
}
}
impl fmt::Debug for Builder {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Builder")
.field("current_thread", &self.current_thread)
.field("num_threads", &self.nu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | a6253ed05a1e0d14bc64915f5937c29092df9497 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a6253ed05a1e0d14bc64915f5937c29092df9497/tokio/src/runtime/builder.rs | 361 | 382 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:2 | ///
/// // use runtime ...
/// }
/// ```
pub struct Builder {
/// When `true`, use the current-thread executor.
current_thread: bool,
/// The number of worker threads.
///
/// Only used when not using the current-thread executor.
num_threads: usize,
/// Name used for threads spawned by... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 94f9b04b066cfc3da5c3ee2c961c21a9496135dd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/94f9b04b066cfc3da5c3ee2c961c21a9496135dd/tokio/src/runtime/builder.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:3 | num_threads: crate::executor::loom::sys::num_cpus(),
// Default thread name
thread_name: "tokio-runtime-worker".into(),
// Do not set a stack size by default
thread_stack_size: None,
// No worker thread callbacks
after_start: None,
b... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | 94f9b04b066cfc3da5c3ee2c961c21a9496135dd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/94f9b04b066cfc3da5c3ee2c961c21a9496135dd/tokio/src/runtime/builder.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/builder.rs:9 | builder.num_threads(self.num_threads);
builder.name(&self.thread_name);
if let Some(stack_size) = self.thread_stack_size {
builder.stack_size(stack_size);
}
builder
.around_worker(move |index, next| {
// Configure the ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/builder.rs | MIT | d70c928d88dff9e3e8d673b8ee02bce131598550 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d70c928d88dff9e3e8d673b8ee02bce131598550/tokio/src/runtime/builder.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/config.rs:1 | #![cfg_attr(
any(not(all(tokio_unstable, feature = "full")), target_family = "wasm"),
allow(dead_code)
)]
use crate::runtime::{Callback, TaskCallback};
use crate::util::RngSeedGenerator;
pub(crate) struct Config {
/// How many ticks before pulling a task from the global/remote queue?
pub(crate) global_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/config.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/runtime/config.rs | 1 | 59 |
tokio-rs/tokio:tokio/src/runtime/config.rs:1 | #![cfg_attr(
any(not(all(tokio_unstable, feature = "full")), target_family = "wasm"),
allow(dead_code)
)]
use crate::runtime::{Callback, TaskCallback};
use crate::util::RngSeedGenerator;
pub(crate) struct Config {
/// How many ticks before pulling a task from the global/remote queue?
pub(crate) global_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/config.rs | MIT | 967f5715a71d5d2600b71da8c4ab652c4e644a41 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/967f5715a71d5d2600b71da8c4ab652c4e644a41/tokio/src/runtime/config.rs | 1 | 54 |
tokio-rs/tokio:tokio/src/runtime/config.rs:1 | #![cfg_attr(
any(not(all(tokio_unstable, feature = "full")), target_family = "wasm"),
allow(dead_code)
)]
use crate::runtime::{Callback, TaskCallback};
use crate::util::RngSeedGenerator;
pub(crate) struct Config {
/// How many ticks before pulling a task from the global/remote queue?
pub(crate) global_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/config.rs | MIT | fccc28f1d0041fc5bdd798dc2645dc3b5fc71ef1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fccc28f1d0041fc5bdd798dc2645dc3b5fc71ef1/tokio/src/runtime/config.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/config.rs:2 | /// As a stop-gap, this unstable option lets users disable the LIFO task.
/// Now that the LIFO slot is stealable, we may remove this option in a
/// future version.
pub(crate) disable_lifo_slot: bool,
/// Random number generator seed to configure runtimes to act in a
/// deterministic way.
pub... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/config.rs | MIT | fccc28f1d0041fc5bdd798dc2645dc3b5fc71ef1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fccc28f1d0041fc5bdd798dc2645dc3b5fc71ef1/tokio/src/runtime/config.rs | 41 | 61 |
tokio-rs/tokio:tokio/src/runtime/config.rs:1 | #![cfg_attr(
any(not(all(tokio_unstable, feature = "full")), target_family = "wasm"),
allow(dead_code)
)]
use crate::runtime::{Callback, TaskCallback};
use crate::util::RngSeedGenerator;
pub(crate) struct Config {
/// How many ticks before pulling a task from the global/remote queue?
pub(crate) global_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/config.rs | MIT | eeb55c733ba9a83c51d08b1629dca6a5ec0f4b2b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eeb55c733ba9a83c51d08b1629dca6a5ec0f4b2b/tokio/src/runtime/config.rs | 1 | 56 |
tokio-rs/tokio:tokio/src/runtime/config.rs:1 | #![cfg_attr(
any(not(all(tokio_unstable, feature = "full")), target_family = "wasm"),
allow(dead_code)
)]
use crate::runtime::{Callback, TaskCallback};
use crate::util::RngSeedGenerator;
pub(crate) struct Config {
/// How many ticks before pulling a task from the global/remote queue?
pub(crate) global_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/config.rs | MIT | b8ac94ed70df22f885bad7ea3c0ff51c536bad4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b8ac94ed70df22f885bad7ea3c0ff51c536bad4a/tokio/src/runtime/config.rs | 1 | 57 |
tokio-rs/tokio:tokio/src/runtime/config.rs:1 | #![cfg_attr(
any(not(all(tokio_unstable, feature = "full")), target_family = "wasm"),
allow(dead_code)
)]
use crate::runtime::{Callback, TaskCallback};
use crate::util::RngSeedGenerator;
pub(crate) struct Config {
/// How many ticks before pulling a task from the global/remote queue?
pub(crate) global_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/config.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/config.rs | 1 | 49 |
tokio-rs/tokio:tokio/src/runtime/config.rs:1 | #![cfg_attr(
any(not(all(tokio_unstable, feature = "full")), target_family = "wasm"),
allow(dead_code)
)]
use crate::runtime::Callback;
use crate::util::RngSeedGenerator;
pub(crate) struct Config {
/// How many ticks before pulling a task from the global/remote queue?
pub(crate) global_queue_interval: ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/config.rs | MIT | 8832e936b1b86946ce802c5494bd8d575f8ba3a3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8832e936b1b86946ce802c5494bd8d575f8ba3a3/tokio/src/runtime/config.rs | 1 | 43 |
tokio-rs/tokio:tokio/src/runtime/config.rs:1 | #![cfg_attr(any(not(feature = "full"), target_family = "wasm"), allow(dead_code))]
use crate::runtime::Callback;
use crate::util::RngSeedGenerator;
pub(crate) struct Config {
/// How many ticks before pulling a task from the global/remote queue?
pub(crate) global_queue_interval: Option<u32>,
/// How many ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/config.rs | MIT | c445e467ce4363b3a9b6825268814a9bc27c0127 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c445e467ce4363b3a9b6825268814a9bc27c0127/tokio/src/runtime/config.rs | 1 | 37 |
tokio-rs/tokio:tokio/src/runtime/config.rs:1 | #![cfg_attr(any(not(feature = "full"), tokio_wasm), allow(dead_code))]
use crate::runtime::Callback;
use crate::util::RngSeedGenerator;
pub(crate) struct Config {
/// How many ticks before pulling a task from the global/remote queue?
pub(crate) global_queue_interval: Option<u32>,
/// How many ticks before... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/config.rs | MIT | 79a7e78c0d4ea5f36d74a773b9023df7d6022b27 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/79a7e78c0d4ea5f36d74a773b9023df7d6022b27/tokio/src/runtime/config.rs | 1 | 37 |
tokio-rs/tokio:tokio/src/runtime/config.rs:1 | #![cfg_attr(any(not(feature = "full"), tokio_wasm), allow(dead_code))]
use crate::runtime::Callback;
use crate::util::RngSeedGenerator;
pub(crate) struct Config {
/// How many ticks before pulling a task from the global/remote queue?
pub(crate) global_queue_interval: u32,
/// How many ticks before yieldin... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/config.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/config.rs | 1 | 37 |
tokio-rs/tokio:tokio/src/runtime/config.rs:1 | #![cfg_attr(any(not(feature = "full"), tokio_wasm), allow(dead_code))]
use crate::runtime::Callback;
use crate::util::RngSeedGenerator;
pub(crate) struct Config {
/// How many ticks before pulling a task from the global/remote queue?
pub(crate) global_queue_interval: u32,
/// How many ticks before yieldin... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/config.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/config.rs | 1 | 34 |
tokio-rs/tokio:tokio/src/runtime/config.rs:1 | #![cfg_attr(any(not(feature = "full"), tokio_wasm), allow(dead_code))]
use crate::runtime::Callback;
pub(crate) struct Config {
/// How many ticks before pulling a task from the global/remote queue?
pub(crate) global_queue_interval: u32,
/// How many ticks before yielding to the driver for timer and I/O e... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/config.rs | MIT | b023522a37a48d16de02e654b6c88ffe1eccb280 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b023522a37a48d16de02e654b6c88ffe1eccb280/tokio/src/runtime/config.rs | 1 | 29 |
tokio-rs/tokio:tokio/src/runtime/config.rs:1 | use crate::runtime::Callback;
pub(crate) struct Config {
/// How many ticks before pulling a task from the global/remote queue?
pub(crate) global_queue_interval: u32,
/// How many ticks before yielding to the driver for timer and I/O events?
pub(crate) event_interval: u32,
/// Callback for a work... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/config.rs | MIT | df28ac092f0464d9c00eeb7f58e3b85dcb5bce52 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df28ac092f0464d9c00eeb7f58e3b85dcb5bce52/tokio/src/runtime/config.rs | 1 | 19 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | use crate::loom::thread::AccessError;
use crate::task::coop;
use std::cell::Cell;
#[cfg(any(feature = "rt", feature = "macros"))]
use crate::util::rand::FastRand;
cfg_rt! {
mod blocking;
pub(crate) use blocking::{disallow_block_in_place, try_enter_blocking_region, BlockingRegionGuard};
mod current;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | /// Handle to the runtime scheduler running on the current thread.
#[cfg(feature = "rt")]
current: current::HandleCell,
/// Handle to the scheduler's internal "context"
#[cfg(feature = "rt")]
scheduler: Scoped<scheduler::Context>,
#[cfg(feature = "rt")]
current_task_id: Cell<Option<Id>>,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | thread_id: Cell::new(None),
// Tracks the current runtime handle to use when spawning,
// accessing drivers, etc...
#[cfg(feature = "rt")]
current: current::HandleCell::new(),
// Tracks the current scheduler internal context
#[cfg(feature = "rt")... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/runtime/context.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/context.rs:4 | }
}
#[cfg(any(feature = "macros", all(feature = "sync", feature = "rt")))]
pub(crate) fn thread_rng_n(n: u32) -> u32 {
CONTEXT.with(|ctx| {
let mut rng = ctx.rng.get().unwrap_or_else(FastRand::new);
let ret = rng.fastrand_n(n);
ctx.rng.set(Some(rng));
ret
})
}
pub(crate) fn bud... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/runtime/context.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/context.rs:5 | #[cfg(tokio_unstable)]
pub(crate) fn worker_index() -> Option<usize> {
with_scheduler(|ctx| ctx.and_then(|c| c.worker_index()))
}
#[track_caller]
pub(crate) fn defer(waker: &Waker) {
with_scheduler(|maybe_scheduler| {
if let Some(scheduler) = maybe_scheduler {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/runtime/context.rs | 161 | 205 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | thread_id: Cell::new(None),
// Tracks the current runtime handle to use when spawning,
// accessing drivers, etc...
#[cfg(feature = "rt")]
current: current::HandleCell::new(),
// Tracks the current scheduler internal context
#[cfg(feature = "rt")... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 1604bc335157be9a131e24cfde55cab3c90ebc92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1604bc335157be9a131e24cfde55cab3c90ebc92/tokio/src/runtime/context.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/context.rs:4 | }
}
#[cfg(any(feature = "macros", feature = "rt"))]
pub(crate) fn thread_rng_n(n: u32) -> u32 {
CONTEXT.with(|ctx| {
let mut rng = ctx.rng.get().unwrap_or_else(FastRand::new);
let ret = rng.fastrand_n(n);
ctx.rng.set(Some(rng));
ret
})
}
pub(crate) fn budget<R>(f: impl FnOnce(&... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 1604bc335157be9a131e24cfde55cab3c90ebc92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1604bc335157be9a131e24cfde55cab3c90ebc92/tokio/src/runtime/context.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/context.rs:4 | }
}
#[cfg(any(feature = "macros", all(feature = "sync", feature = "rt")))]
pub(crate) fn thread_rng_n(n: u32) -> u32 {
CONTEXT.with(|ctx| {
let mut rng = ctx.rng.get().unwrap_or_else(FastRand::new);
let ret = rng.fastrand_n(n);
ctx.rng.set(Some(rng));
ret
})
}
pub(crate) fn bud... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d1f1499f630c34c1d319acdc2cc86d7a1008c4b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1f1499f630c34c1d319acdc2cc86d7a1008c4b4/tokio/src/runtime/context.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/context.rs:5 | #[track_caller]
pub(crate) fn defer(waker: &Waker) {
with_scheduler(|maybe_scheduler| {
if let Some(scheduler) = maybe_scheduler {
scheduler.defer(waker);
} else {
// Called from outside of the runtime, immediately wake the
// task.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d1f1499f630c34c1d319acdc2cc86d7a1008c4b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1f1499f630c34c1d319acdc2cc86d7a1008c4b4/tokio/src/runtime/context.rs | 161 | 200 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | /// Handle to the runtime scheduler running on the current thread.
#[cfg(feature = "rt")]
current: current::HandleCell,
/// Handle to the scheduler's internal "context"
#[cfg(feature = "rt")]
scheduler: Scoped<scheduler::Context>,
#[cfg(feature = "rt")]
current_task_id: Cell<Option<Id>>,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | thread_id: Cell::new(None),
// Tracks the current runtime handle to use when spawning,
// accessing drivers, etc...
#[cfg(feature = "rt")]
current: current::HandleCell::new(),
// Tracks the current scheduler internal context
#[cfg(feature = "rt")... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/context.rs | 81 | 140 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.