mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-24 12:34:31 +00:00
cros_async: block_on: simplify errno handling
Change-Id: I9971911239a0c2e1cc0bbebeabc687025d3c2212 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4328233 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
parent
6631cdbd7d
commit
c842b3ee2d
2 changed files with 16 additions and 26 deletions
|
@ -26,12 +26,6 @@ thread_local!(static PER_THREAD_WAKER: Arc<Waker> = Arc::new(Waker(AtomicI32::ne
|
|||
#[repr(transparent)]
|
||||
struct Waker(AtomicI32);
|
||||
|
||||
extern "C" {
|
||||
#[cfg_attr(target_os = "android", link_name = "__errno")]
|
||||
#[cfg_attr(target_os = "linux", link_name = "__errno_location")]
|
||||
fn errno_location() -> *mut libc::c_int;
|
||||
}
|
||||
|
||||
impl ArcWake for Waker {
|
||||
fn wake_by_ref(arc_self: &Arc<Self>) {
|
||||
let state = arc_self.0.swap(WOKEN, Ordering::Release);
|
||||
|
@ -50,9 +44,10 @@ impl ArcWake for Waker {
|
|||
)
|
||||
};
|
||||
if res < 0 {
|
||||
panic!("unexpected error from FUTEX_WAKE_PRIVATE: {}", unsafe {
|
||||
*errno_location()
|
||||
});
|
||||
panic!(
|
||||
"unexpected error from FUTEX_WAKE_PRIVATE: {}",
|
||||
std::io::Error::last_os_error()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,10 +86,10 @@ pub fn block_on<F: Future>(f: F) -> F::Output {
|
|||
};
|
||||
|
||||
if res < 0 {
|
||||
// Safe because libc guarantees that this is a valid pointer.
|
||||
match unsafe { *errno_location() } {
|
||||
libc::EAGAIN | libc::EINTR => {}
|
||||
e => panic!("unexpected error from FUTEX_WAIT_PRIVATE: {}", e),
|
||||
let e = std::io::Error::last_os_error();
|
||||
match e.raw_os_error() {
|
||||
Some(libc::EAGAIN) | Some(libc::EINTR) => {}
|
||||
_ => panic!("unexpected error from FUTEX_WAIT_PRIVATE: {}", e),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,12 +26,6 @@ thread_local!(static PER_THREAD_WAKER: Arc<Waker> = Arc::new(Waker(AtomicI32::ne
|
|||
#[repr(transparent)]
|
||||
struct Waker(AtomicI32);
|
||||
|
||||
extern "C" {
|
||||
#[cfg_attr(target_os = "android", link_name = "__errno")]
|
||||
#[cfg_attr(target_os = "linux", link_name = "__errno_location")]
|
||||
fn errno_location() -> *mut libc::c_int;
|
||||
}
|
||||
|
||||
impl ArcWake for Waker {
|
||||
fn wake_by_ref(arc_self: &Arc<Self>) {
|
||||
let state = arc_self.0.swap(WOKEN, Ordering::Release);
|
||||
|
@ -50,9 +44,10 @@ impl ArcWake for Waker {
|
|||
)
|
||||
};
|
||||
if res < 0 {
|
||||
panic!("unexpected error from FUTEX_WAKE_PRIVATE: {}", unsafe {
|
||||
*errno_location()
|
||||
});
|
||||
panic!(
|
||||
"unexpected error from FUTEX_WAKE_PRIVATE: {}",
|
||||
std::io::Error::last_os_error()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,10 +86,10 @@ pub fn block_on<F: Future>(f: F) -> F::Output {
|
|||
};
|
||||
|
||||
if res < 0 {
|
||||
// Safe because libc guarantees that this is a valid pointer.
|
||||
match unsafe { *errno_location() } {
|
||||
libc::EAGAIN | libc::EINTR => {}
|
||||
e => panic!("unexpected error from FUTEX_WAIT_PRIVATE: {}", e),
|
||||
let e = std::io::Error::last_os_error();
|
||||
match e.raw_os_error() {
|
||||
Some(libc::EAGAIN) | Some(libc::EINTR) => {}
|
||||
_ => panic!("unexpected error from FUTEX_WAIT_PRIVATE: {}", e),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue