Skip to content

Commit

Permalink
ThreadNameFn always use std::sync::Arc
Browse files Browse the repository at this point in the history
  • Loading branch information
biluohc authored and ysl committed Mar 3, 2020
1 parent 2213fce commit 5416579
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tokio/src/runtime/builder.rs
Expand Up @@ -2,10 +2,7 @@ use crate::runtime::handle::Handle;
use crate::runtime::shell::Shell;
use crate::runtime::{blocking, io, time, Callback, Runtime, Spawner};

#[cfg(loom)]
use crate::loom::sync::Arc;
use std::fmt;
#[cfg(not(loom))]
use std::sync::Arc;

/// Builds Tokio Runtime with custom configuration values.
Expand Down Expand Up @@ -70,7 +67,7 @@ pub struct Builder {
pub(super) before_stop: Option<Callback>,
}

pub(crate) type ThreadNameFn = Arc<Box<dyn Fn() -> String + Send + Sync + 'static>>;
pub(crate) type ThreadNameFn = Arc<dyn Fn() -> String + Send + Sync + 'static>;

#[derive(Debug, Clone, Copy)]
enum Kind {
Expand Down Expand Up @@ -103,7 +100,7 @@ impl Builder {
max_threads: 512,

// Default thread name
thread_name: Arc::new(Box::new(|| "tokio-runtime-worker".into())),
thread_name: Arc::new(|| "tokio-runtime-worker".into()),

// Do not set a stack size by default
thread_stack_size: None,
Expand Down Expand Up @@ -215,7 +212,7 @@ impl Builder {
/// ```
pub fn thread_name(&mut self, val: impl Into<String>) -> &mut Self {
let val = val.into();
self.thread_name = Arc::new(Box::new(move || val.clone()));
self.thread_name = Arc::new(move || val.clone());
self
}

Expand Down Expand Up @@ -243,7 +240,7 @@ impl Builder {
where
F: Fn() -> String + Send + Sync + 'static,
{
self.thread_name = Arc::new(Box::new(f));
self.thread_name = Arc::new(f);
self
}

Expand Down Expand Up @@ -543,7 +540,10 @@ impl fmt::Debug for Builder {
.field("kind", &self.kind)
.field("core_threads", &self.core_threads)
.field("max_threads", &self.max_threads)
.field("thread_name", &"<dyn Fn() -> String + Send + Sync + 'static>")
.field(
"thread_name",
&"<dyn Fn() -> String + Send + Sync + 'static>",
)
.field("thread_stack_size", &self.thread_stack_size)
.field("after_start", &self.after_start.as_ref().map(|_| "..."))
.field("before_stop", &self.after_start.as_ref().map(|_| "..."))
Expand Down

0 comments on commit 5416579

Please sign in to comment.