]> git.lizzy.rs Git - rust.git/blob - library/std/src/sys/itron/task.rs
Rollup merge of #101445 - TaKO8Ki:suggest-introducing-explicit-lifetime, r=oli-obk
[rust.git] / library / std / src / sys / itron / task.rs
1 use super::{
2     abi,
3     error::{fail, fail_aborting, ItronError},
4 };
5
6 use crate::mem::MaybeUninit;
7
8 /// Get the ID of the task in Running state. Panics on failure.
9 #[inline]
10 pub fn current_task_id() -> abi::ID {
11     try_current_task_id().unwrap_or_else(|e| fail(e, &"get_tid"))
12 }
13
14 /// Get the ID of the task in Running state. Aborts on failure.
15 #[inline]
16 pub fn current_task_id_aborting() -> abi::ID {
17     try_current_task_id().unwrap_or_else(|e| fail_aborting(e, &"get_tid"))
18 }
19
20 /// Get the ID of the task in Running state.
21 #[inline]
22 pub fn try_current_task_id() -> Result<abi::ID, ItronError> {
23     unsafe {
24         let mut out = MaybeUninit::uninit();
25         ItronError::err_if_negative(abi::get_tid(out.as_mut_ptr()))?;
26         Ok(out.assume_init())
27     }
28 }
29
30 /// Get the specified task's priority. Panics on failure.
31 #[inline]
32 pub fn task_priority(task: abi::ID) -> abi::PRI {
33     try_task_priority(task).unwrap_or_else(|e| fail(e, &"get_pri"))
34 }
35
36 /// Get the specified task's priority.
37 #[inline]
38 pub fn try_task_priority(task: abi::ID) -> Result<abi::PRI, ItronError> {
39     unsafe {
40         let mut out = MaybeUninit::uninit();
41         ItronError::err_if_negative(abi::get_pri(task, out.as_mut_ptr()))?;
42         Ok(out.assume_init())
43     }
44 }