-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Expand file tree
/
Copy paththread.rs
More file actions
59 lines (48 loc) · 1.61 KB
/
thread.rs
File metadata and controls
59 lines (48 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Horizon-specific extensions for working with the [`std::thread`] module.
//!
//! [`std::thread`]: crate::thread
#![unstable(feature = "thread_scheduling", issue = "none")]
use crate::fmt;
/// The relative priority of the thread. See the `libctru` docs for the `prio`
/// parameter of [`threadCreate`] for details on valid values.
///
/// [`threadCreate`]: https://libctru.devkitpro.org/thread_8h.html#a38c873d8cb02de7f5eca848fe68183ee
pub struct Priority(pub(crate) libc::c_int);
impl TryFrom<i32> for Priority {
type Error = ();
fn try_from(value: i32) -> Result<Self, Self::Error> {
match value {
0x18..=0x3F => Ok(Self(value)),
_ => Err(()),
}
}
}
impl crate::fmt::Debug for Priority {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Priority").finish_non_exhaustive()
}
}
/// The CPU(s) on which to spawn the thread. See the `libctru` docs for the
/// `core_id` parameter of [`threadCreate`] for details on valid values.
///
/// [`threadCreate`]: https://libctru.devkitpro.org/thread_8h.html#a38c873d8cb02de7f5eca848fe68183ee
pub struct Affinity(pub(crate) libc::c_int);
impl Default for Affinity {
fn default() -> Self {
Self(-2)
}
}
impl TryFrom<i32> for Affinity {
type Error = ();
fn try_from(value: i32) -> Result<Self, Self::Error> {
match value {
-2..=4 => Ok(Self(value)),
_ => Err(()),
}
}
}
impl crate::fmt::Debug for Affinity {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Affinity").finish_non_exhaustive()
}
}