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
ysl committed Mar 3, 2020
1 parent 2213fce commit cbc1a76
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions tokio/bar.txt
@@ -0,0 +1 @@
Hello File!
1 change: 1 addition & 0 deletions tokio/foo.txt
@@ -0,0 +1 @@
Hello File!
11 changes: 4 additions & 7 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

0 comments on commit cbc1a76

Please sign in to comment.