Skip to content
This repository has been archived by the owner on May 3, 2021. It is now read-only.

Commit

Permalink
Move static_assertion closer to where it is needed
Browse files Browse the repository at this point in the history
  • Loading branch information
furuholm committed Dec 27, 2019
1 parent affcd85 commit eddb1cd
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions libsignal-protocol/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,6 @@ impl Default for Context {
}
}

// Assert that Context does not implement [`Send`] and [`Sync`] to guarantee
// that each [`Context`] instance is only used within a single thread. This allows
// locking to be omitted (see lock_function below).
//
// See https://github.com/Michael-F-Bryan/libsignal-protocol-rs/issues/49
// for details.
static_assertions::assert_not_impl_all!(Context: Send, Sync);

/// Our Rust wrapper around the [`sys::signal_context`].
///
/// # Safety
Expand Down Expand Up @@ -431,6 +423,13 @@ fn translate_log_level(raw: c_int) -> Level {
}
}

// Assert that Context does not implement [`Send`] and [`Sync`] to guarantee
// that each [`Context`] instance is only used within a single thread.
//
// See https://github.com/Michael-F-Bryan/libsignal-protocol-rs/issues/49
// for details.
static_assertions::assert_not_impl_all!(Context: Send, Sync);

unsafe extern "C" fn lock_function(_user_data: *mut c_void) {
// Locking is not required as [`Context`] cannot be shared between
// threads as long as it does not implement [`Sync`] and [`Send`].
Expand Down

0 comments on commit eddb1cd

Please sign in to comment.