Skip to content

Commit c24c8e4

Browse files
committed
add rudimentary implementation of Thread::sleep and Thread::yield_now on armv7a-vex-v5
1 parent 9e9d61c commit c24c8e4

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

library/std/src/sys/pal/vexos/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub mod pipe;
1313
#[path = "../unsupported/process.rs"]
1414
pub mod process;
1515
pub mod stdio;
16-
#[path = "../unsupported/thread.rs"]
1716
pub mod thread;
1817
pub mod time;
1918

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use super::unsupported;
2+
use crate::ffi::CStr;
3+
use crate::io;
4+
use crate::num::NonZero;
5+
use crate::time::Duration;
6+
7+
pub struct Thread(!);
8+
9+
pub const DEFAULT_MIN_STACK_SIZE: usize = 64 * 1024;
10+
11+
impl Thread {
12+
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
13+
pub unsafe fn new(_stack: usize, _p: Box<dyn FnOnce()>) -> io::Result<Thread> {
14+
unsupported()
15+
}
16+
17+
pub fn yield_now() {
18+
unsafe {
19+
vex_sdk::vexTasksRun();
20+
}
21+
}
22+
23+
pub fn set_name(_name: &CStr) {
24+
// nope
25+
}
26+
27+
pub fn sleep(dur: Duration) {
28+
let start = Instant::now();
29+
30+
while start.elapsed() < dur {
31+
unsafe {
32+
vex_sdk::vexTasksRun();
33+
}
34+
}
35+
}
36+
37+
pub fn join(self) {
38+
self.0
39+
}
40+
}
41+
42+
pub fn available_parallelism() -> io::Result<NonZero<usize>> {
43+
unsupported()
44+
}

0 commit comments

Comments
 (0)