Skip to content

Commit

Permalink
fix(mpsc): compilation error on macOS (#53)
Browse files Browse the repository at this point in the history
This fixes a compilation error that occurs on macOS due to
`std::thread::Thread` not being `UnwindSafe` on that platform. It's kind
of sad that we have to do this, but I think it's probably fine.

Fixes #54

Signed-off-by: Eliza Weisman <[email protected]>
  • Loading branch information
hawkw authored Mar 16, 2022
1 parent 27ea0ec commit d0d0cd9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ jobs:

tests:
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- nightly
- 1.57.0
# test all Rust versions on Ubuntu
rust: [stable, 1.57.0]
os: [ubuntu-latest, m]
# test stable Rust on Windows and MacOS as well
include:
- rust: stable
os: windows-latest
- rust: stable
os: macos-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Install toolchain
Expand Down
3 changes: 1 addition & 2 deletions src/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
//! [`core::task::Waker`]s, for the async MPSC, or [`std::thread::Thread`]s, for
//! the blocking MPSC. In either case, the role played by these types is fairly
//! analogous.
use crate::util::panic::UnwindSafe;
use core::{fmt, task::Waker};

mod cell;
Expand Down Expand Up @@ -54,7 +53,7 @@ pub(crate) enum WaitResult {
Notified,
}

pub(crate) trait Notify: UnwindSafe + fmt::Debug + Clone {
pub(crate) trait Notify: fmt::Debug + Clone {
fn notify(self);

fn same(&self, other: &Self) -> bool;
Expand Down
11 changes: 8 additions & 3 deletions src/wait/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ impl<T: Notify> WaitCell<T> {
let result = match test_dbg!(self.compare_exchange(State::PARKING, State::WAITING, AcqRel))
{
Ok(_) => {
let _ = panic::catch_unwind(move || drop(prev_waiter));
// XXX(eliza): it's kind of sad we have to use
// `AssertUnwindSafe` here, because `std::thread::Thread`
// contains a `Condvar` on macOS :(
let _ = panic::catch_unwind(panic::AssertUnwindSafe(move || drop(prev_waiter)));

WaitResult::Wait
}
Expand All @@ -117,9 +120,11 @@ impl<T: Notify> WaitCell<T> {
);

if let Some(prev_waiter) = prev_waiter {
let _ = panic::catch_unwind(move || {
// XXX(eliza): similarly, it's necessary to assert unwind
// safety due to `std::thread::Thread` on macOS here...
let _ = panic::catch_unwind(panic::AssertUnwindSafe(move || {
prev_waiter.notify();
});
}));
}

if let Some(waiter) = waiter {
Expand Down

0 comments on commit d0d0cd9

Please sign in to comment.