Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

18 fix tests #23

Merged
merged 4 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ edition = "2021"
[features]
default = []
c-library = []

[dev-dependencies]
sequential-test = "0.2.4"
52 changes: 34 additions & 18 deletions src/task_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,28 +227,44 @@ impl TaskManager {
}
}

/// Starts task manager work.
/// One step of task manager's work.
// TODO: Support priorities.
// TODO: Delete tasks from task vector if they are pending
pub fn start_task_manager() -> ! {
loop {
if unsafe { !TASK_MANAGER.tasks.is_empty() } {
let waker = task_waker();

let task = unsafe { &mut TASK_MANAGER.tasks[TASK_MANAGER.task_to_execute_index] };
let mut task_future_pin = Pin::new(task);
let _ = task_future_pin
.as_mut()
.poll(&mut Context::from_waker(&waker));

unsafe {
if TASK_MANAGER.task_to_execute_index + 1 < TASK_MANAGER.tasks.len() {
TASK_MANAGER.task_to_execute_index += 1;
} else {
TASK_MANAGER.task_to_execute_index = 0;
}
fn task_manager_step() {
if unsafe { !TASK_MANAGER.tasks.is_empty() } {
let waker = task_waker();

let task = unsafe { &mut TASK_MANAGER.tasks[TASK_MANAGER.task_to_execute_index] };
let mut task_future_pin = Pin::new(task);
let _ = task_future_pin
.as_mut()
.poll(&mut Context::from_waker(&waker));

unsafe {
if TASK_MANAGER.task_to_execute_index + 1 < TASK_MANAGER.tasks.len() {
TASK_MANAGER.task_to_execute_index += 1;
} else {
TASK_MANAGER.task_to_execute_index = 0;
}
}
}
}

/// Starts task manager work.
pub fn start_task_manager() -> ! {
loop {
TaskManager::task_manager_step();
}
}

/// Starts task manager work. Returns after 1000 steps only for testing task_manager_step.
pub fn test_start_task_manager() {
for _n in 1..=1000 {
TaskManager::task_manager_step();
}
// This is bad idea
unsafe {
TASK_MANAGER.tasks_number = 0;
}
}
}
Loading
Loading