diff --git a/Cargo.lock b/Cargo.lock index 133681e91..d16b4ba72 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -242,7 +242,7 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.16" +version = "0.1.17" dependencies = [ "compiler_builtins", "libc", diff --git a/hermit-abi/Cargo.toml b/hermit-abi/Cargo.toml index 15189622d..48e879566 100644 --- a/hermit-abi/Cargo.toml +++ b/hermit-abi/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hermit-abi" -version = "0.1.16" +version = "0.1.17" authors = ["Stefan Lankes"] license = "MIT/Apache-2.0" readme = "README.md" diff --git a/hermit-abi/src/lib.rs b/hermit-abi/src/lib.rs index a00948b6a..30bdca011 100644 --- a/hermit-abi/src/lib.rs +++ b/hermit-abi/src/lib.rs @@ -65,11 +65,17 @@ extern "C" { fn sys_open(name: *const i8, flags: i32, mode: i32) -> i32; fn sys_unlink(name: *const i8) -> i32; fn sys_network_init() -> i32; + fn sys_block_current_task(); + fn sys_wakeup_task(tid: Tid); + fn sys_get_priority() -> u8; } /// A thread handle type pub type Tid = u32; +/// Maximum number of priorities +pub const NO_PRIORITIES: usize = 31; + /// Priority of a thread #[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Copy)] pub struct Priority(u8); @@ -461,3 +467,22 @@ pub unsafe fn secure_rand32() -> Option { pub unsafe fn secure_rand64() -> Option { sys_secure_rand64() } + +/// Add current task to the queue of blocked tasl. After calling `block_current_task`, +/// call `yield_now` to switch to another task. +#[inline(always)] +pub unsafe fn block_current_task() { + sys_block_current_task(); +} + +/// Wakeup task with the thread id `tid` +#[inline(always)] +pub unsafe fn wakeup_task(tid: Tid) { + sys_wakeup_task(tid); +} + +/// Determine the priority of the current thread +#[inline(always)] +pub unsafe fn get_priority() -> Priority { + Priority::from(sys_get_priority()) +} diff --git a/libhermit-rs b/libhermit-rs index 265e2e43f..b59ca4152 160000 --- a/libhermit-rs +++ b/libhermit-rs @@ -1 +1 @@ -Subproject commit 265e2e43fbfb26d4c091cd2cf6b92c18db24b573 +Subproject commit b59ca4152c25d03cce19f80b5316e0ec7b688ca5