Skip to content

Commit

Permalink
Use Send-safe wrapper in install_trigger function
Browse files Browse the repository at this point in the history
When targeting musl, libc::pthread_t aliases to *mut c_void, which is
not Send, and therefore causes compilation failures. pthread_t is meant
to be an opaque handle, so we can safely just wrap it in a newtype that
explicitly implements Send.
  • Loading branch information
mrakh authored and Glauber Costa committed Feb 28, 2023
1 parent 847db3a commit 517326b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions glommio/src/executor/stall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,15 @@ impl StallDetector {
timer: Arc<sys::timerfd::TimerFd>,
signal: i32,
) -> JoinHandle<()> {
let tid = unsafe { nix::libc::pthread_self() };
struct SendWrapper(libc::pthread_t);
unsafe impl Send for SendWrapper {}
let tid = SendWrapper(unsafe { nix::libc::pthread_self() });
std::thread::spawn(enclose::enclose! { (terminated, timer) move || {
while timer.wait().is_ok() {
if terminated.load(Ordering::Relaxed) {
return
}
unsafe { nix::libc::pthread_kill(tid, signal) };
unsafe { nix::libc::pthread_kill(tid.0, signal) };
}
}})
}
Expand Down

0 comments on commit 517326b

Please sign in to comment.