Verified Commit 276d5aa1 authored by Stefan Lankes's avatar Stefan Lankes
Browse files

add system calls to block and unblock a task

parent e83d61cf
use alloc::collections::BTreeMap;
use core::isize;
#[cfg(feature = "newlib")]
use core::sync::atomic::AtomicUsize;
......@@ -18,7 +19,8 @@ use crate::errno::*;
#[cfg(feature = "newlib")]
use crate::mm::{task_heap_end, task_heap_start};
use crate::scheduler;
use crate::scheduler::task::{Priority, TaskId};
use crate::scheduler::task::{Priority, TaskHandle, TaskId};
use crate::synch::spinlock::SpinlockIrqSave;
use crate::syscalls;
use crate::syscalls::timer::timespec;
......@@ -283,3 +285,33 @@ fn __sys_join(id: Tid) -> i32 {
pub extern "C" fn sys_join(id: Tid) -> i32 {
kernel_function!(__sys_join(id))
}
/// Mapping between TaskID and TaskHandle
static TASKS: SpinlockIrqSave<BTreeMap<TaskId, TaskHandle>> = SpinlockIrqSave::new(BTreeMap::new());
fn __sys_block_current_task() {
let core_scheduler = core_scheduler();
let handle = core_scheduler.get_current_task_handle();
let tid = core_scheduler.get_current_task_id();
TASKS.lock().insert(tid, handle);
core_scheduler.block_current_task(None);
}
#[no_mangle]
pub extern "C" fn sys_block_current_task() {
kernel_function!(__sys_block_current_task())
}
fn __sys_wakeup_task(id: Tid) {
let task_id = TaskId::from(id);
if let Some(handle) = TASKS.lock().remove(&task_id) {
core_scheduler().custom_wakeup(handle);
}
}
#[no_mangle]
pub extern "C" fn sys_wakeup_task(id: Tid) {
kernel_function!(__sys_wakeup_task(id))
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment