]>
Commit | Line | Data |
---|---|---|
ba9703b0 XL |
1 | // Copyright 2016 Amanieu d'Antras |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or | |
4 | // http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or | |
5 | // http://opensource.org/licenses/MIT>, at your option. This file may not be | |
6 | // copied, modified, or distributed except according to those terms. | |
7 | ||
8 | //! The wasm platform can't park when atomic support is not available. | |
9 | //! So this ThreadParker just panics on any attempt to park. | |
10 | ||
f035d41b XL |
11 | use instant::Instant; |
12 | use std::thread; | |
ba9703b0 XL |
13 | |
14 | pub struct ThreadParker(()); | |
15 | ||
16 | impl super::ThreadParkerT for ThreadParker { | |
17 | type UnparkHandle = UnparkHandle; | |
18 | ||
19 | const IS_CHEAP_TO_CONSTRUCT: bool = true; | |
20 | ||
21 | fn new() -> ThreadParker { | |
22 | ThreadParker(()) | |
23 | } | |
24 | ||
25 | unsafe fn prepare_park(&self) { | |
26 | panic!("Parking not supported on this platform"); | |
27 | } | |
28 | ||
29 | unsafe fn timed_out(&self) -> bool { | |
30 | panic!("Parking not supported on this platform"); | |
31 | } | |
32 | ||
33 | unsafe fn park(&self) { | |
34 | panic!("Parking not supported on this platform"); | |
35 | } | |
36 | ||
37 | unsafe fn park_until(&self, _timeout: Instant) -> bool { | |
38 | panic!("Parking not supported on this platform"); | |
39 | } | |
40 | ||
41 | unsafe fn unpark_lock(&self) -> UnparkHandle { | |
42 | panic!("Parking not supported on this platform"); | |
43 | } | |
44 | } | |
45 | ||
46 | pub struct UnparkHandle(()); | |
47 | ||
48 | impl super::UnparkHandleT for UnparkHandle { | |
49 | unsafe fn unpark(self) {} | |
50 | } | |
51 | ||
52 | pub fn thread_yield() { | |
53 | thread::yield_now(); | |
54 | } |