Skip to content

add new system calls to block and unblock tasks #72

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

Merged
merged 4 commits into from
Oct 6, 2020
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion hermit-abi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
25 changes: 25 additions & 0 deletions hermit-abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -461,3 +467,22 @@ pub unsafe fn secure_rand32() -> Option<u32> {
pub unsafe fn secure_rand64() -> Option<u64> {
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())
}
2 changes: 1 addition & 1 deletion libhermit-rs