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 11 use std::thread; 12 use std::time::Instant; 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 new() -> ThreadParker21 fn new() -> ThreadParker { 22 ThreadParker(()) 23 } 24 prepare_park(&self)25 unsafe fn prepare_park(&self) { 26 panic!("Parking not supported on this platform"); 27 } 28 timed_out(&self) -> bool29 unsafe fn timed_out(&self) -> bool { 30 panic!("Parking not supported on this platform"); 31 } 32 park(&self)33 unsafe fn park(&self) { 34 panic!("Parking not supported on this platform"); 35 } 36 park_until(&self, _timeout: Instant) -> bool37 unsafe fn park_until(&self, _timeout: Instant) -> bool { 38 panic!("Parking not supported on this platform"); 39 } 40 unpark_lock(&self) -> UnparkHandle41 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 { unpark(self)49 unsafe fn unpark(self) {} 50 } 51 thread_yield()52pub fn thread_yield() { 53 thread::yield_now(); 54 } 55