-
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It doesn't currently pass, but should in the near future. Signed-off-by: Klim Tsoutsman <[email protected]>
- Loading branch information
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "test_task_cancel" | ||
version = "0.1.0" | ||
authors = ["Klim Tsoutsman <[email protected]>"] | ||
description = "Task cancellation test" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
log = "0.4" | ||
spawn = { path = "../../kernel/spawn" } | ||
spin = "0.9" | ||
task = { path = "../../kernel/task" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// TODO: Properly implement Task::kill so the test passes. | ||
|
||
#![no_std] | ||
|
||
extern crate alloc; | ||
|
||
use alloc::{string::String, sync::Arc, vec::Vec}; | ||
use core::sync::atomic::{AtomicUsize, Ordering}; | ||
use spin::Mutex; | ||
|
||
pub fn main(_: Vec<String>) -> isize { | ||
let lock = Arc::new(Mutex::new(())); | ||
let task = spawn::new_task_builder(other, lock.clone()) | ||
.spawn() | ||
.expect("failed to spawn task"); | ||
|
||
while !lock.is_locked() {} | ||
|
||
task.kill(task::KillReason::Requested) | ||
.expect("failed to abort task"); | ||
|
||
log::debug!("waiting for lock to be unlocked"); | ||
|
||
// For us to acquire the lock, the drop handler of the other thread's guard must | ||
// have been invoked. | ||
let _ = lock.lock(); | ||
|
||
0 | ||
} | ||
|
||
#[inline(never)] | ||
fn other(lock: Arc<Mutex<()>>) { | ||
let _guard = lock.lock(); | ||
loop { | ||
// In order to properly unwind the task we need to reach an instruction that is | ||
// covered by the unwind tables. Rust generates an unwind row for all call | ||
// sites so by placing a call site in the loop we ensure that the task will | ||
// reach an instruction from which it can unwind when it is told to cancel. | ||
unwind_row_generator(); | ||
} | ||
} | ||
|
||
#[inline(never)] | ||
fn unwind_row_generator() { | ||
static __COUNTER: AtomicUsize = AtomicUsize::new(0); | ||
|
||
// Prevents unwind_row_generator from being optimised away. | ||
__COUNTER.fetch_add(1, Ordering::Relaxed); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters