From 522a78ba339f094032b83fc5f303bf3ad7444960 Mon Sep 17 00:00:00 2001 From: Victor Koenders Date: Mon, 10 Jan 2022 11:29:14 +0100 Subject: [PATCH 1/4] Added a way to obtain an indication of the current task state --- src/task.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/task.rs b/src/task.rs index fff918c..ba7a38a 100644 --- a/src/task.rs +++ b/src/task.rs @@ -395,6 +395,23 @@ impl Task { let header = ptr as *const Header; unsafe { &*header } } + + /// Get the current state of the task. + /// + /// Note that in a multithreaded environment, this state can change immediately after calling this function. + pub fn state(&self) -> TaskState { + let ptr = self.ptr.as_ptr(); + let header = ptr as *const Header; + + unsafe { + let state = (*header).state.load(Ordering::Acquire); + if state & (CLOSED | COMPLETED) != 0 { + TaskState::Completed + } else { + TaskState::Running + } + } + } } impl Drop for Task { @@ -515,3 +532,14 @@ impl fmt::Debug for FallibleTask { .finish() } } + +/// The state of a task. +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[non_exhaustive] +pub enum TaskState { + /// The task is still running. + Running, + + /// The task has completed. + Completed, +} From a382c33f9df6bd1cc7285e62175fa12588c0690f Mon Sep 17 00:00:00 2001 From: Victor Koenders Date: Sat, 22 Jan 2022 08:23:25 +0100 Subject: [PATCH 2/4] Bumped MSRV to 1.40 for the #[non_exhaustive] attribute --- .clippy.toml | 2 +- .github/workflows/ci.yml | 2 +- Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.clippy.toml b/.clippy.toml index 53095b1..0f404fa 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -1 +1 @@ -msrv = "1.39" +msrv = "1.40" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5305ffe..8ae6754 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,7 +45,7 @@ jobs: matrix: # When updating this, the reminder to update the minimum supported # Rust version in Cargo.toml and .clippy.toml. - rust: ['1.39'] + rust: ['1.40'] steps: - uses: actions/checkout@v2 - name: Install Rust diff --git a/Cargo.toml b/Cargo.toml index b1ae509..8140776 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ name = "async-task" version = "4.1.0" authors = ["Stjepan Glavina "] edition = "2018" -rust-version = "1.39" +rust-version = "1.40" license = "Apache-2.0 OR MIT" repository = "https://github.com/smol-rs/async-task" description = "Task abstraction for building executors" From f2391a16015ba614ad14bfbdb5a993f53edba754 Mon Sep 17 00:00:00 2001 From: Victor Koenders Date: Fri, 4 Mar 2022 14:50:19 +0100 Subject: [PATCH 3/4] Replaced `TaskState` with a simple `is_finished()` function --- src/task.rs | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/src/task.rs b/src/task.rs index ba7a38a..7d1c433 100644 --- a/src/task.rs +++ b/src/task.rs @@ -396,20 +396,16 @@ impl Task { unsafe { &*header } } - /// Get the current state of the task. + /// Returns `true` if the current task is finished. /// - /// Note that in a multithreaded environment, this state can change immediately after calling this function. - pub fn state(&self) -> TaskState { + /// Note that in a multithreaded environment, this task can change finish immediately after calling this function. + pub fn is_finished(&self) -> bool { let ptr = self.ptr.as_ptr(); let header = ptr as *const Header; unsafe { let state = (*header).state.load(Ordering::Acquire); - if state & (CLOSED | COMPLETED) != 0 { - TaskState::Completed - } else { - TaskState::Running - } + state & (CLOSED | COMPLETED) != 0 } } } @@ -532,14 +528,3 @@ impl fmt::Debug for FallibleTask { .finish() } } - -/// The state of a task. -#[derive(Copy, Clone, Debug, PartialEq, Eq)] -#[non_exhaustive] -pub enum TaskState { - /// The task is still running. - Running, - - /// The task has completed. - Completed, -} From 5dfe3d4806198c7a70bd4b4efa7541843305b3c9 Mon Sep 17 00:00:00 2001 From: Victor Koenders Date: Fri, 4 Mar 2022 15:02:16 +0100 Subject: [PATCH 4/4] Reverted MSRV bump --- .clippy.toml | 2 +- .github/workflows/ci.yml | 2 +- Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.clippy.toml b/.clippy.toml index 0f404fa..53095b1 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -1 +1 @@ -msrv = "1.40" +msrv = "1.39" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ae6754..5305ffe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,7 +45,7 @@ jobs: matrix: # When updating this, the reminder to update the minimum supported # Rust version in Cargo.toml and .clippy.toml. - rust: ['1.40'] + rust: ['1.39'] steps: - uses: actions/checkout@v2 - name: Install Rust diff --git a/Cargo.toml b/Cargo.toml index 8140776..b1ae509 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ name = "async-task" version = "4.1.0" authors = ["Stjepan Glavina "] edition = "2018" -rust-version = "1.40" +rust-version = "1.39" license = "Apache-2.0 OR MIT" repository = "https://github.com/smol-rs/async-task" description = "Task abstraction for building executors"