diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/raw.rs | 8 | ||||
-rw-r--r-- | src/task.rs | 1 | ||||
-rw-r--r-- | src/utils.rs | 18 |
3 files changed, 22 insertions, 5 deletions
@@ -10,7 +10,7 @@ use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; use crate::header::Header; use crate::state::*; -use crate::utils::{abort_on_panic, extend}; +use crate::utils::{abort, abort_on_panic, extend}; use crate::Task; /// The vtable for a task. @@ -111,7 +111,7 @@ where unsafe { // Allocate enough space for the entire task. let raw_task = match NonNull::new(alloc::alloc::alloc(task_layout.layout) as *mut ()) { - None => libc::abort(), + None => abort(), Some(p) => p, }; @@ -311,7 +311,7 @@ where if state & RUNNING == 0 { // If the reference count overflowed, abort. if state > isize::max_value() as usize { - libc::abort(); + abort(); } // Schedule the task. There is no need to call `Self::schedule(ptr)` @@ -343,7 +343,7 @@ where // If the reference count overflowed, abort. if state > isize::max_value() as usize { - libc::abort(); + abort(); } RawWaker::new(ptr, raw_waker_vtable) diff --git a/src/task.rs b/src/task.rs index b26c082..8ef209c 100644 --- a/src/task.rs +++ b/src/task.rs @@ -101,6 +101,7 @@ where /// // Create a task with the future and the schedule function. /// let (task, handle) = async_task::spawn_local(future, schedule, ()); /// ``` +#[cfg(any(unix, windows))] pub fn spawn_local<F, R, S, T>(future: F, schedule: S, tag: T) -> (Task<T>, JoinHandle<R, T>) where F: Future<Output = R> + 'static, diff --git a/src/utils.rs b/src/utils.rs index 7c71deb..cb9b65e 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,6 +1,22 @@ use core::alloc::Layout; use core::mem; +/// Aborts the process. +/// +/// To abort, this function simply panics while panicking. +pub(crate) fn abort() -> ! { + struct Panic; + + impl Drop for Panic { + fn drop(&mut self) { + panic!("aborting the process"); + } + } + + let _panic = Panic; + panic!("aborting the process"); +} + /// Calls a function and aborts if it panics. /// /// This is useful in unsafe code where we can't recover from panics. @@ -10,7 +26,7 @@ pub(crate) fn abort_on_panic<T>(f: impl FnOnce() -> T) -> T { impl Drop for Bomb { fn drop(&mut self) { - unsafe { libc::abort() } + abort(); } } |