diff options
author | Carl Lerche <me@carllerche.com> | 2019-11-16 07:19:45 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-16 07:19:45 -0800 |
commit | 3f0eabe7798de624f5ee9c7562803bfb97e6088f (patch) | |
tree | 6458345730f7eae674ec1e7ea82f120a5f1b70bc /tokio/src/runtime/global.rs | |
parent | 1474794055e291c544c3c95d6381d549cefbd7d5 (diff) |
runtime: rename current_thread -> basic_scheduler (#1769)
It no longer supports executing !Send futures. The use case for
It is wanting a “light” runtime. There will be “local” task execution
using a different strategy coming later.
This patch also renames `thread_pool` -> `threaded_scheduler`, but
only in public APIs for now.
Diffstat (limited to 'tokio/src/runtime/global.rs')
-rw-r--r-- | tokio/src/runtime/global.rs | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/tokio/src/runtime/global.rs b/tokio/src/runtime/global.rs index f1cb8d1b..8a2641b9 100644 --- a/tokio/src/runtime/global.rs +++ b/tokio/src/runtime/global.rs @@ -1,4 +1,4 @@ -use crate::runtime::current_thread; +use crate::runtime::basic_scheduler; #[cfg(feature = "rt-full")] use crate::runtime::thread_pool; @@ -11,8 +11,8 @@ enum State { // default executor not defined Empty, - // Current-thread executor - CurrentThread(*const current_thread::Scheduler), + // Basic scheduler (runs on the current-thread) + Basic(*const basic_scheduler::SchedulerPriv), // default executor is a thread pool instance. #[cfg(feature = "rt-full")] @@ -73,17 +73,17 @@ where { EXECUTOR.with(|current_executor| match current_executor.get() { #[cfg(feature = "rt-full")] - State::ThreadPool(threadpool_ptr) => { - let thread_pool = unsafe { &*threadpool_ptr }; + State::ThreadPool(thread_pool_ptr) => { + let thread_pool = unsafe { &*thread_pool_ptr }; thread_pool.spawn_background(future); } - State::CurrentThread(current_thread_ptr) => { - let current_thread = unsafe { &*current_thread_ptr }; + State::Basic(basic_scheduler_ptr) => { + let basic_scheduler = unsafe { &*basic_scheduler_ptr }; - // Safety: The `CurrentThread` value set the thread-local (same + // Safety: The `BasicScheduler` value set the thread-local (same // thread). unsafe { - current_thread.spawn_background(future); + basic_scheduler.spawn_background(future); } } State::Empty => { @@ -95,19 +95,22 @@ where }) } -pub(super) fn with_current_thread<F, R>(current_thread: ¤t_thread::Scheduler, f: F) -> R +pub(super) fn with_basic_scheduler<F, R>( + basic_scheduler: &basic_scheduler::SchedulerPriv, + f: F, +) -> R where F: FnOnce() -> R, { with_state( - State::CurrentThread(current_thread as *const current_thread::Scheduler), + State::Basic(basic_scheduler as *const basic_scheduler::SchedulerPriv), f, ) } -pub(super) fn current_thread_is_current(current_thread: ¤t_thread::Scheduler) -> bool { +pub(super) fn basic_scheduler_is_current(basic_scheduler: &basic_scheduler::SchedulerPriv) -> bool { EXECUTOR.with(|current_executor| match current_executor.get() { - State::CurrentThread(ptr) => ptr == current_thread as *const _, + State::Basic(ptr) => ptr == basic_scheduler as *const _, _ => false, }) } |