Skip to content

Commit

Permalink
Auto merge of #3065 - Forestryks:master, r=JohnTitor
Browse files Browse the repository at this point in the history
linux: add pthread barriers

This PR adds pthread barrier bindings for all supported linux platforms
  • Loading branch information
bors committed Jan 18, 2023
2 parents 216a428 + 4625f47 commit 36d0272
Show file tree
Hide file tree
Showing 23 changed files with 137 additions and 0 deletions.
11 changes: 11 additions & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2858,6 +2858,8 @@ __SIZEOF_PTHREAD_MUTEXATTR_T
__SIZEOF_PTHREAD_MUTEX_T
__SIZEOF_PTHREAD_RWLOCKATTR_T
__SIZEOF_PTHREAD_RWLOCK_T
__SIZEOF_PTHREAD_BARRIERATTR_T
__SIZEOF_PTHREAD_BARRIER_T
__WALL
__WCLONE
__WNOTHREAD
Expand Down Expand Up @@ -3176,6 +3178,15 @@ pthread_spin_lock
pthread_spin_trylock
pthread_spin_unlock
pthread_spinlock_t
pthread_barrierattr_init
pthread_barrierattr_setpshared
pthread_barrierattr_getpshared
pthread_barrierattr_destroy
pthread_barrier_init
pthread_barrier_wait
pthread_barrier_destroy
pthread_barrierattr_t
pthread_barrier_t
ptrace
ptsname_r
pwrite64
Expand Down
30 changes: 30 additions & 0 deletions src/unix/linux_like/linux/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ macro_rules! expand_align {
size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T],
}

#[repr(align(4))]
pub struct pthread_barrierattr_t {
#[doc(hidden)]
size: [u8; ::__SIZEOF_PTHREAD_BARRIERATTR_T],
}

#[repr(align(8))]
pub struct fanotify_event_metadata {
pub event_len: __u32,
Expand Down Expand Up @@ -123,6 +129,30 @@ macro_rules! expand_align {
size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T],
}

#[cfg_attr(all(target_pointer_width = "32",
any(target_arch = "mips",
target_arch = "arm",
target_arch = "hexagon",
target_arch = "m68k",
target_arch = "powerpc",
target_arch = "sparc",
target_arch = "x86_64",
target_arch = "x86")),
repr(align(4)))]
#[cfg_attr(any(target_pointer_width = "64",
not(any(target_arch = "mips",
target_arch = "arm",
target_arch = "hexagon",
target_arch = "m68k",
target_arch = "powerpc",
target_arch = "sparc",
target_arch = "x86_64",
target_arch = "x86"))),
repr(align(8)))]
pub struct pthread_barrier_t {
size: [u8; ::__SIZEOF_PTHREAD_BARRIER_T],
}

// linux/can.h
#[repr(align(8))]
#[allow(missing_debug_implementations)]
Expand Down
2 changes: 2 additions & 0 deletions src/unix/linux_like/linux/gnu/b32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ pub const F_OFD_SETLKW: ::c_int = 38;
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 20;
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;

cfg_if! {
if #[cfg(target_arch = "sparc")] {
Expand Down
2 changes: 2 additions & 0 deletions src/unix/linux_like/linux/gnu/b32/riscv32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ pub const TCSAFLUSH: ::c_int = 2;

pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;
pub const O_DIRECT: ::c_int = 16384;
pub const O_DIRECTORY: ::c_int = 65536;
pub const O_NOFOLLOW: ::c_int = 131072;
Expand Down Expand Up @@ -452,6 +453,7 @@ pub const FLUSHO: ::tcflag_t = 4096;
pub const EXTPROC: ::tcflag_t = 65536;
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;
pub const NGREG: usize = 32;
pub const REG_PC: usize = 0;
pub const REG_RA: usize = 1;
Expand Down
2 changes: 2 additions & 0 deletions src/unix/linux_like/linux/gnu/b64/aarch64/ilp32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 32;
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 48;
pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 20;

align_const! {
#[cfg(target_endian = "little")]
Expand Down
2 changes: 2 additions & 0 deletions src/unix/linux_like/linux/gnu/b64/aarch64/lp64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 8;
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 48;
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 8;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 8;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;

align_const! {
#[cfg(target_endian = "little")]
Expand Down
2 changes: 2 additions & 0 deletions src/unix/linux_like/linux/gnu/b64/loongarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ s! {

pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;

align_const! {
#[cfg(target_endian = "little")]
Expand Down
2 changes: 2 additions & 0 deletions src/unix/linux_like/linux/gnu/b64/mips64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ s! {

pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;

align_const! {
#[cfg(target_endian = "little")]
Expand Down
2 changes: 2 additions & 0 deletions src/unix/linux_like/linux/gnu/b64/powerpc64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ pub const RTLD_GLOBAL: ::c_int = 0x100;
pub const RTLD_NOLOAD: ::c_int = 0x4;
pub const VEOF: usize = 4;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;

pub const O_APPEND: ::c_int = 1024;
pub const O_CREAT: ::c_int = 64;
Expand Down Expand Up @@ -402,6 +403,7 @@ pub const EFD_CLOEXEC: ::c_int = 0x80000;
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;

align_const! {
#[cfg(target_endian = "little")]
Expand Down
2 changes: 2 additions & 0 deletions src/unix/linux_like/linux/gnu/b64/riscv64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ pub const EPOLL_CLOEXEC: ::c_int = 524288;
pub const EFD_CLOEXEC: ::c_int = 524288;
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;
pub const O_DIRECT: ::c_int = 16384;
pub const O_DIRECTORY: ::c_int = 65536;
pub const O_NOFOLLOW: ::c_int = 131072;
Expand Down Expand Up @@ -491,6 +492,7 @@ pub const FLUSHO: ::tcflag_t = 4096;
pub const EXTPROC: ::tcflag_t = 65536;
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;
pub const NGREG: usize = 32;
pub const REG_PC: usize = 0;
pub const REG_RA: usize = 1;
Expand Down
2 changes: 2 additions & 0 deletions src/unix/linux_like/linux/gnu/b64/s390x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,10 @@ pub const EFD_CLOEXEC: ::c_int = 0x80000;

pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;

align_const! {
pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t =
Expand Down
2 changes: 2 additions & 0 deletions src/unix/linux_like/linux/gnu/b64/sparc64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ pub const RTLD_DEEPBIND: ::c_int = 0x8;
pub const RTLD_GLOBAL: ::c_int = 0x100;
pub const RTLD_NOLOAD: ::c_int = 0x4;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;

pub const O_APPEND: ::c_int = 0x8;
pub const O_CREAT: ::c_int = 0x200;
Expand Down Expand Up @@ -401,6 +402,7 @@ pub const EFD_CLOEXEC: ::c_int = 0x400000;
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;

align_const! {
pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t =
Expand Down
1 change: 1 addition & 0 deletions src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ pub const EFD_CLOEXEC: ::c_int = 0x80000;

pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;

pub const O_DIRECT: ::c_int = 0x4000;
pub const O_DIRECTORY: ::c_int = 0x10000;
Expand Down
1 change: 1 addition & 0 deletions src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ s! {

pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;

align_const! {
#[cfg(target_endian = "little")]
Expand Down
1 change: 1 addition & 0 deletions src/unix/linux_like/linux/gnu/b64/x86_64/x32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ s! {

pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 32;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 44;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 20;

align_const! {
pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t =
Expand Down
39 changes: 39 additions & 0 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,28 @@ cfg_if! {
}
}

impl PartialEq for pthread_barrier_t {
fn eq(&self, other: &pthread_barrier_t) -> bool {
self.size.iter().zip(other.size.iter()).all(|(a,b)| a == b)
}
}

impl Eq for pthread_barrier_t {}

impl ::fmt::Debug for pthread_barrier_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("pthread_barrier_t")
.field("size", &self.size)
.finish()
}
}

impl ::hash::Hash for pthread_barrier_t {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.size.hash(state);
}
}

impl PartialEq for sockaddr_alg {
fn eq(&self, other: &sockaddr_alg) -> bool {
self.salg_family == other.salg_family
Expand Down Expand Up @@ -4169,6 +4191,23 @@ extern "C" {
lock: *mut pthread_mutex_t,
abstime: *const ::timespec,
) -> ::c_int;
pub fn pthread_barrierattr_init(attr: *mut ::pthread_barrierattr_t) -> ::c_int;
pub fn pthread_barrierattr_destroy(attr: *mut ::pthread_barrierattr_t) -> ::c_int;
pub fn pthread_barrierattr_getpshared(
attr: *const ::pthread_barrierattr_t,
shared: *mut ::c_int,
) -> ::c_int;
pub fn pthread_barrierattr_setpshared(
attr: *mut ::pthread_barrierattr_t,
shared: ::c_int,
) -> ::c_int;
pub fn pthread_barrier_init(
barrier: *mut pthread_barrier_t,
attr: *const ::pthread_barrierattr_t,
count: ::c_uint,
) -> ::c_int;
pub fn pthread_barrier_destroy(barrier: *mut pthread_barrier_t) -> ::c_int;
pub fn pthread_barrier_wait(barrier: *mut pthread_barrier_t) -> ::c_int;
pub fn pthread_spin_init(lock: *mut ::pthread_spinlock_t, pshared: ::c_int) -> ::c_int;
pub fn pthread_spin_destroy(lock: *mut ::pthread_spinlock_t) -> ::c_int;
pub fn pthread_spin_lock(lock: *mut ::pthread_spinlock_t) -> ::c_int;
Expand Down
1 change: 1 addition & 0 deletions src/unix/linux_like/linux/musl/b32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ s! {

pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32;
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 20;

cfg_if! {
if #[cfg(any(target_arch = "x86"))] {
Expand Down
2 changes: 2 additions & 0 deletions src/unix/linux_like/linux/musl/b32/riscv32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ pub const TIOCM_DSR: ::c_int = 256;

pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;
pub const O_DIRECT: ::c_int = 16384;
pub const O_DIRECTORY: ::c_int = 65536;
pub const O_NOFOLLOW: ::c_int = 131072;
Expand Down Expand Up @@ -504,6 +505,7 @@ pub const TIOCSWINSZ: ::c_int = 21524;
pub const FIONREAD: ::c_int = 21531;
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;

pub const SYS_read: ::c_long = 63;
pub const SYS_write: ::c_long = 64;
Expand Down
1 change: 1 addition & 0 deletions src/unix/linux_like/linux/musl/b64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ s! {

pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;

pub const SOCK_NONBLOCK: ::c_int = 2048;

Expand Down
1 change: 1 addition & 0 deletions src/unix/linux_like/linux/musl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ pub const SIGUNUSED: ::c_int = ::SIGSYS;
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;

pub const CPU_SETSIZE: ::c_int = 128;

Expand Down
25 changes: 25 additions & 0 deletions src/unix/linux_like/linux/no_align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ macro_rules! expand_align {
size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T],
}

pub struct pthread_barrierattr_t {
__align: [::c_int; 0],
size: [u8; ::__SIZEOF_PTHREAD_BARRIERATTR_T],
}

pub struct fanotify_event_metadata {
__align: [::c_long; 0],
pub event_len: __u32,
Expand Down Expand Up @@ -100,6 +105,26 @@ macro_rules! expand_align {
__align: [::c_longlong; 0],
size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T],
}

pub struct pthread_barrier_t {
#[cfg(any(target_arch = "mips",
target_arch = "arm",
target_arch = "m68k",
target_arch = "powerpc",
target_arch = "sparc",
all(target_arch = "x86_64",
target_pointer_width = "32")))]
__align: [::c_long; 0],
#[cfg(not(any(target_arch = "mips",
target_arch = "arm",
target_arch = "m68k",
target_arch = "powerpc",
target_arch = "sparc",
all(target_arch = "x86_64",
target_pointer_width = "32"))))]
__align: [::c_longlong; 0],
size: [u8; ::__SIZEOF_PTHREAD_BARRIER_T],
}
}
};
}
2 changes: 2 additions & 0 deletions src/unix/linux_like/linux/uclibc/mips/mips64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ s! {

pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;

pub const SYS_gettid: ::c_long = 5178; // Valid for n64

Expand Down
2 changes: 2 additions & 0 deletions src/unix/linux_like/linux/uclibc/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ pub const __SIZEOF_PTHREAD_COND_T: usize = 48;
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;
pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;
pub const PIDFD_NONBLOCK: ::c_int = 04000;

cfg_if! {
Expand Down

0 comments on commit 36d0272

Please sign in to comment.