Skip to content
Snippets Groups Projects

chore(cbus): add `Send` bound to callback for `tarantool::cbus::Message` (close #165)

Merged Konstantin D requested to merge chore/cbus-msg-send-bound into master
Files
4
+ 22
1
@@ -56,7 +56,9 @@ use crate::ffi;
use crate::ffi::tarantool::{
cbus_endpoint_delete, cbus_endpoint_new, cbus_loop, lcpipe_delete, lcpipe_new, lcpipe_push_now,
};
use crate::fiber::Cond;
use std::ffi::CString;
use std::ops::Deref;
use std::os::raw::c_void;
use std::ptr;
@@ -96,7 +98,7 @@ pub struct Message<T> {
impl<F> Message<F>
where
F: FnOnce() + 'static,
F: FnOnce() + Send + 'static,
{
unsafe fn trampoline(msg: *mut c_void) {
let msg = msg.cast::<Self>();
@@ -203,6 +205,25 @@ impl Drop for LCPipe {
}
}
/// This is a wrapper over a [`Cond`] for sending it between threads.
///
/// # Safety.
/// `UnsafeCond` must be dereference and dropped only at TX thread, drop this structure
/// in non-TX thread will lead to application crash.
struct UnsafeCond(Cond);
impl Deref for UnsafeCond {
type Target = Cond;
fn deref(&self) -> &Self::Target {
&self.0
}
}
unsafe impl Send for UnsafeCond {}
unsafe impl Sync for UnsafeCond {}
#[cfg(feature = "internal_test")]
mod tests {
use crate::cbus;
Loading