Skip to content

Commit

Permalink
Update use of libc::timespec to prepare for future libc version
Browse files Browse the repository at this point in the history
In a future release of the `libc` crate, `libc::timespec` will contain
private padding fields on `*-linux-musl` targets and so the struct will
no longer be able to be created using the literal initialization syntax.

Update the use of `libc::timespec` to create a value by calling
`std::mem::zeroed()` first and then setting the `tv_sec` and `tv_nsec`
fields manually which works with both current versions of `libc` as well
as the future version which contains that change.
  • Loading branch information
wesleywiser committed Nov 22, 2022
1 parent fa859df commit 7fec6a7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions core/src/thread_parker/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ impl super::ThreadParkerT for ThreadParker {
self.park();
return true;
}
let ts = libc::timespec {
tv_sec: diff.as_secs() as libc::time_t,
tv_nsec: diff.subsec_nanos() as tv_nsec_t,
};
// SAFETY: libc::timespec is zero initializable.
let mut ts: libc::timespec = std::mem::zeroed();
ts.tv_sec = diff.as_secs() as libc::time_t;
ts.tv_nsec = diff.subsec_nanos() as tv_nsec_t;
self.futex_wait(Some(ts));
}
true
Expand Down

0 comments on commit 7fec6a7

Please sign in to comment.