From 30223430ff134c7d0df014ce1573bfe35d27025a Mon Sep 17 00:00:00 2001 From: kolapapa <346512016@qq.com> Date: Mon, 4 Nov 2019 16:44:04 +0800 Subject: [PATCH 1/5] change DYNAMIC_THREAD_COUNT to be an AtomicUsize --- src/task/spawn_blocking.rs | 6 +++--- src/task/task_id.rs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/task/spawn_blocking.rs b/src/task/spawn_blocking.rs index 3f4f18a17..d633e225f 100644 --- a/src/task/spawn_blocking.rs +++ b/src/task/spawn_blocking.rs @@ -1,4 +1,4 @@ -use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::atomic::{AtomicUsize, Ordering}; use std::thread; use std::time::Duration; @@ -49,9 +49,9 @@ where JoinHandle::new(handle) } -const MAX_THREADS: u64 = 10_000; +const MAX_THREADS: usize = 10_000; -static DYNAMIC_THREAD_COUNT: AtomicU64 = AtomicU64::new(0); +static DYNAMIC_THREAD_COUNT: AtomicUsize = AtomicUsize::new(0); struct Pool { sender: Sender, diff --git a/src/task/task_id.rs b/src/task/task_id.rs index 67eee154b..497227ce8 100644 --- a/src/task/task_id.rs +++ b/src/task/task_id.rs @@ -1,5 +1,5 @@ use std::fmt; -use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::atomic::{AtomicUsize, Ordering}; /// A unique identifier for a task. /// @@ -13,15 +13,15 @@ use std::sync::atomic::{AtomicU64, Ordering}; /// }) /// ``` #[derive(Eq, PartialEq, Clone, Copy, Hash, Debug)] -pub struct TaskId(pub(crate) u64); +pub struct TaskId(pub(crate) usize); impl TaskId { /// Generates a new `TaskId`. pub(crate) fn generate() -> TaskId { - static COUNTER: AtomicU64 = AtomicU64::new(1); + static COUNTER: AtomicUsize = AtomicUsize::new(1); let id = COUNTER.fetch_add(1, Ordering::Relaxed); - if id > u64::max_value() / 2 { + if id > usize::max_value() / 2 { std::process::abort(); } TaskId(id) From 9a86c1754f78544f3b65ee02a3eb115f66c2bb4c Mon Sep 17 00:00:00 2001 From: kolapapa <346512016@qq.com> Date: Thu, 7 Nov 2019 14:59:14 +0800 Subject: [PATCH 2/5] change TaskId to u64,COUNTER to AtomicCell --- Cargo.toml | 2 +- src/task/task_id.rs | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4e9dc09cf..b0882bd61 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ async-task = "1.0.0" broadcaster = { version = "0.2.6", optional = true, default-features = false, features = ["default-channels"] } crossbeam-channel = "0.3.9" crossbeam-deque = "0.7.1" -crossbeam-utils = "0.6.6" +crossbeam-utils = "0.7.3" futures-core-preview = "=0.3.0-alpha.19" futures-io-preview = "=0.3.0-alpha.19" futures-timer = "1.0.2" diff --git a/src/task/task_id.rs b/src/task/task_id.rs index 497227ce8..4eea746a0 100644 --- a/src/task/task_id.rs +++ b/src/task/task_id.rs @@ -1,5 +1,6 @@ use std::fmt; -use std::sync::atomic::{AtomicUsize, Ordering}; + +use crossbeam_utils::atomic::AtomicCell; /// A unique identifier for a task. /// @@ -13,15 +14,15 @@ use std::sync::atomic::{AtomicUsize, Ordering}; /// }) /// ``` #[derive(Eq, PartialEq, Clone, Copy, Hash, Debug)] -pub struct TaskId(pub(crate) usize); +pub struct TaskId(pub(crate) u64); impl TaskId { /// Generates a new `TaskId`. pub(crate) fn generate() -> TaskId { - static COUNTER: AtomicUsize = AtomicUsize::new(1); + static COUNTER: AtomicCell = AtomicCell::new(1u64); - let id = COUNTER.fetch_add(1, Ordering::Relaxed); - if id > usize::max_value() / 2 { + let id = COUNTER.fetch_add(1); + if id > u64::max_value() / 2 { std::process::abort(); } TaskId(id) From 8bddb17d85a6d0362a68eee293279a1c44d34064 Mon Sep 17 00:00:00 2001 From: kolapapa <346512016@qq.com> Date: Thu, 7 Nov 2019 15:18:51 +0800 Subject: [PATCH 3/5] update crossbeam-utils version to 0.7.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9583cdee7..b4a2108a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ async-task = "1.0.0" broadcaster = { version = "0.2.6", optional = true, default-features = false, features = ["default-channels"] } crossbeam-channel = "0.3.9" crossbeam-deque = "0.7.1" -crossbeam-utils = "0.6.6" +crossbeam-utils = "0.7.0" futures-core = "0.3.0" futures-io = "0.3.0" futures-timer = "1.0.2" From dfc3c881d925e21c0b83383d1fbed22ac5ca8f8e Mon Sep 17 00:00:00 2001 From: kolapapa <346512016@qq.com> Date: Sun, 10 Nov 2019 11:47:32 +0800 Subject: [PATCH 4/5] update crossbeam-utils version to 0.7.0 --- Cargo.toml | 23 ++--------------------- src/task/spawn_blocking.rs | 8 +------- 2 files changed, 3 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 62f1d0468..aa0cfc7ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,27 +54,9 @@ async-attributes = { version = "1.1.0", optional = true } async-macros = { version = "1.0.0", optional = true } async-task = { version = "1.0.0", optional = true } broadcaster = { version = "0.2.6", optional = true, default-features = false, features = ["default-channels"] } -<<<<<<< HEAD -crossbeam-channel = "0.3.9" -crossbeam-deque = "0.7.1" -crossbeam-utils = "0.7.0" -futures-core = "0.3.0" -futures-io = "0.3.0" -futures-timer = "1.0.2" -kv-log-macro = "1.0.4" -log = { version = "0.4.8", features = ["kv_unstable"] } -memchr = "2.2.1" -mio = "0.6.19" -mio-uds = "0.6.7" -num_cpus = "1.10.1" -once_cell = "1.2.0" -pin-project-lite = "0.1" -pin-utils = "0.1.0-alpha.4" -slab = "0.4.2" -======= crossbeam-channel = { version = "0.3.9", optional = true } crossbeam-deque = { version = "0.7.1", optional = true } -crossbeam-utils = { version = "0.6.6", optional = true } +crossbeam-utils = { version = "0.7.0", optional = true } futures-core = { version = "0.3.0", optional = true } futures-io = { version = "0.3.0", optional = true } futures-timer = { version = "1.0.2", optional = true } @@ -88,7 +70,6 @@ once_cell = { version = "1.2.0", optional = true } pin-project-lite = { version = "0.1", optional = true } pin-utils = { version = "0.1.0-alpha.4", optional = true } slab = { version = "0.4.2", optional = true } ->>>>>>> 122e87364bef463c5afbf7681ec3ce35a3a7f577 [dev-dependencies] femme = "1.2.0" @@ -103,4 +84,4 @@ required-features = ["unstable"] [[example]] name = "tcp-ipv4-and-6-echo" -required-features = ["unstable"] +required-features = ["unstable"] \ No newline at end of file diff --git a/src/task/spawn_blocking.rs b/src/task/spawn_blocking.rs index f90f4addd..91f9ad256 100644 --- a/src/task/spawn_blocking.rs +++ b/src/task/spawn_blocking.rs @@ -48,16 +48,10 @@ where JoinHandle::new(handle) } -<<<<<<< HEAD -const MAX_THREADS: usize = 10_000; - -static DYNAMIC_THREAD_COUNT: AtomicUsize = AtomicUsize::new(0); -======= type Runnable = async_task::Task; /// The number of sleeping worker threads. static SLEEPING: AtomicUsize = AtomicUsize::new(0); ->>>>>>> 122e87364bef463c5afbf7681ec3ce35a3a7f577 struct Pool { sender: Sender, @@ -113,4 +107,4 @@ fn start_thread() { } }) .expect("cannot start a blocking thread"); -} +} \ No newline at end of file From b61707e794abf46c2523146b08b8dee1705e1701 Mon Sep 17 00:00:00 2001 From: kolapapa <346512016@qq.com> Date: Sun, 10 Nov 2019 12:02:38 +0800 Subject: [PATCH 5/5] lint fix --- Cargo.toml | 2 +- src/task/spawn_blocking.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index aa0cfc7ae..783980246 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,4 +84,4 @@ required-features = ["unstable"] [[example]] name = "tcp-ipv4-and-6-echo" -required-features = ["unstable"] \ No newline at end of file +required-features = ["unstable"] diff --git a/src/task/spawn_blocking.rs b/src/task/spawn_blocking.rs index 91f9ad256..6076d1bcd 100644 --- a/src/task/spawn_blocking.rs +++ b/src/task/spawn_blocking.rs @@ -107,4 +107,4 @@ fn start_thread() { } }) .expect("cannot start a blocking thread"); -} \ No newline at end of file +}