I have the following section of code:
let curr_ptr = self.mytype_.load(Ordering::SeqCst);
let curr_type = unsafe { Box::from_raw(curr_ptr) };
if curr_type.as_ref().eq(old_memtable) {
let newt_type = MyType::new();
let new_ptr = Box::into_raw(Box::new(new_type));
let res = self.mytype_.compare_exchange(
curr_ptr,
new_ptr,
Ordering::Acquire,
Ordering::Relaxed,
);
match res {
Ok(old) => {
// This line does not compile.
XXXX::instance().add(*curr_type).await;
retval = true;
}
Err(_) => {
std::mem::forget(curr_type);
}
}
} else {
std::mem::forget(curr_type);
}
The section does not compile because the *mut MyType does not implement Send and it is used later. How am I using it later? How do I fix this w/o trying to make the add() non-async.