Skip to main content

forge/os/
this_thread.rs

1//! Functions for querying and controlling the calling thread.
2
3use core::time::Duration;
4
5use sys::os::{TimeSpanType, thread::*};
6
7/// Returns the logical processor number the calling thread is currently running on.
8pub fn processor() -> i32 {
9    unsafe { nnosGetCurrentProcessorNumber() }
10}
11
12/// Returns the core number the calling thread is currently running on.
13pub fn core() -> i32 {
14    unsafe { nnosGetCurrentCoreNumber() }
15}
16
17/// Suspends the calling thread for at least `duration`.
18pub fn sleep_for(duration: Duration) {
19    unsafe { nnosSleepThread(TimeSpanType(duration.as_nanos() as u64)) };
20}
21
22/// Yields the calling thread's remaining timeslice to the scheduler.
23pub fn yield_now() {
24    unsafe { nnosYieldThread() };
25}