Browse Source

fix(mpsc): compilation error on macOS (#53)

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 <eliza@buoyant.io>
Eliza Weisman 3 years ago
parent
commit
d0d0cd904e
3 changed files with 19 additions and 10 deletions
  1. 10 5
      .github/workflows/tests.yml
  2. 1 2
      src/wait.rs
  3. 8 3
      src/wait/cell.rs

+ 10 - 5
.github/workflows/tests.yml

@@ -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

+ 1 - 2
src/wait.rs

@@ -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;
@@ -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;

+ 8 - 3
src/wait/cell.rs

@@ -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
             }
@@ -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 {