Skip to content

Commit

Permalink
Auto merge of #633 - main--:rwlockattr, r=alexcrichton
Browse files Browse the repository at this point in the history
Add pthread_rwlockattr APIs

I'm basically trying to mirror the existing code for pthread_mutexattr.

Hopefully the non-linux parts are correct - finding the right definitions is rather confusing and occasionally even contradicts existing definitions (e.g. [this](https://github.com/practicalswift/osx/blob/a26375e7b3e01c83e26a23977f909438ed9b31b4/src/libpthread/src/internal.h#L295) `pthread_condattr_t` doesn't match #335).
  • Loading branch information
bors committed Jun 29, 2017
2 parents 4dd6727 + b2de1fd commit 83f5543
Show file tree
Hide file tree
Showing 20 changed files with 77 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/unix/bsd/apple/b32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub const __PTHREAD_MUTEX_SIZE__: usize = 40;
pub const __PTHREAD_COND_SIZE__: usize = 24;
pub const __PTHREAD_CONDATTR_SIZE__: usize = 4;
pub const __PTHREAD_RWLOCK_SIZE__: usize = 124;
pub const __PTHREAD_RWLOCKATTR_SIZE__: usize = 12;

pub const TIOCTIMESTAMP: ::c_ulong = 0x40087459;
pub const TIOCDCDTIMESTAMP: ::c_ulong = 0x40087458;
1 change: 1 addition & 0 deletions src/unix/bsd/apple/b64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub const __PTHREAD_MUTEX_SIZE__: usize = 56;
pub const __PTHREAD_COND_SIZE__: usize = 40;
pub const __PTHREAD_CONDATTR_SIZE__: usize = 8;
pub const __PTHREAD_RWLOCK_SIZE__: usize = 192;
pub const __PTHREAD_RWLOCKATTR_SIZE__: usize = 16;

pub const TIOCTIMESTAMP: ::c_ulong = 0x40107459;
pub const TIOCDCDTIMESTAMP: ::c_ulong = 0x40107458;
Expand Down
11 changes: 11 additions & 0 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ s! {
__opaque: [u8; __PTHREAD_RWLOCK_SIZE__],
}

pub struct pthread_rwlockattr_t {
__sig: ::c_long,
__opaque: [u8; __PTHREAD_RWLOCKATTR_SIZE__],
}

pub struct siginfo_t {
pub si_signo: ::c_int,
pub si_errno: ::c_int,
Expand Down Expand Up @@ -804,6 +809,8 @@ pub const _SC_XOPEN_UNIX: ::c_int = 115;
pub const _SC_XOPEN_VERSION: ::c_int = 116;
pub const _SC_XOPEN_XCU_VERSION: ::c_int = 121;

pub const PTHREAD_PROCESS_PRIVATE: usize = 2;
pub const PTHREAD_PROCESS_SHARED: usize = 1;
pub const PTHREAD_CREATE_JOINABLE: ::c_int = 1;
pub const PTHREAD_CREATE_DETACHED: ::c_int = 2;
pub const PTHREAD_STACK_MIN: ::size_t = 8192;
Expand Down Expand Up @@ -1603,6 +1610,10 @@ extern {
pshared: ::c_int) -> ::c_int;
pub fn pthread_mutexattr_getpshared(attr: *const pthread_mutexattr_t,
pshared: *mut ::c_int) -> ::c_int;
pub fn pthread_rwlockattr_getpshared(attr: *const pthread_rwlockattr_t,
val: *mut ::c_int) -> ::c_int;
pub fn pthread_rwlockattr_setpshared(attr: *mut pthread_rwlockattr_t,
val: ::c_int) -> ::c_int;
pub fn __error() -> *mut ::c_int;
pub fn backtrace(buf: *mut *mut ::c_void,
sz: ::c_int) -> ::c_int;
Expand Down
7 changes: 7 additions & 0 deletions src/unix/bsd/freebsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub type pthread_mutexattr_t = *mut ::c_void;
pub type pthread_cond_t = *mut ::c_void;
pub type pthread_condattr_t = *mut ::c_void;
pub type pthread_rwlock_t = *mut ::c_void;
pub type pthread_rwlockattr_t = *mut ::c_void;
pub type pthread_key_t = ::c_int;
pub type tcflag_t = ::c_uint;
pub type speed_t = ::c_uint;
Expand Down Expand Up @@ -466,6 +467,8 @@ pub const POSIX_MADV_SEQUENTIAL: ::c_int = 2;
pub const POSIX_MADV_WILLNEED: ::c_int = 3;
pub const POSIX_MADV_DONTNEED: ::c_int = 4;

pub const PTHREAD_PROCESS_PRIVATE: ::c_int = 0;
pub const PTHREAD_PROCESS_SHARED: ::c_int = 1;
pub const PTHREAD_CREATE_JOINABLE: ::c_int = 0;
pub const PTHREAD_CREATE_DETACHED: ::c_int = 1;

Expand Down Expand Up @@ -1059,6 +1062,10 @@ extern {
pshared: ::c_int) -> ::c_int;
pub fn pthread_mutexattr_getpshared(attr: *const pthread_mutexattr_t,
pshared: *mut ::c_int) -> ::c_int;
pub fn pthread_rwlockattr_getpshared(attr: *const pthread_rwlockattr_t,
val: *mut ::c_int) -> ::c_int;
pub fn pthread_rwlockattr_setpshared(attr: *mut pthread_rwlockattr_t,
val: ::c_int) -> ::c_int;
pub fn getpriority(which: ::c_int, who: ::c_int) -> ::c_int;
pub fn setpriority(which: ::c_int, who: ::c_int, prio: ::c_int) -> ::c_int;

Expand Down
5 changes: 5 additions & 0 deletions src/unix/bsd/netbsdlike/netbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ s! {
ptma_private: *mut ::c_void,
}

pub struct pthread_rwlockattr_t {
ptra_magic: ::c_uint,
ptra_private: *mut ::c_void,
}

pub struct pthread_cond_t {
ptc_magic: ::c_uint,
ptc_lock: ::c_uchar,
Expand Down
1 change: 1 addition & 0 deletions src/unix/bsd/netbsdlike/openbsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub type pthread_mutexattr_t = *mut ::c_void;
pub type pthread_cond_t = *mut ::c_void;
pub type pthread_condattr_t = *mut ::c_void;
pub type pthread_rwlock_t = *mut ::c_void;
pub type pthread_rwlockattr_t = *mut ::c_void;

s! {
pub struct dirent {
Expand Down
1 change: 1 addition & 0 deletions src/unix/haiku/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub type useconds_t = u32;
pub type socklen_t = u32;
pub type pthread_t = ::uintptr_t;
pub type pthread_mutexattr_t = ::uintptr_t;
pub type pthread_rwlockattr_t = ::uintptr_t;
pub type sigset_t = u64;
pub type fsblkcnt_t = i64;
pub type fsfilcnt_t = i64;
Expand Down
7 changes: 7 additions & 0 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,10 @@ extern {
pub fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> ::c_int;
pub fn pthread_condattr_init(attr: *mut pthread_condattr_t) -> ::c_int;
pub fn pthread_condattr_destroy(attr: *mut pthread_condattr_t) -> ::c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "pthread_rwlock_init$UNIX2003")]
pub fn pthread_rwlock_init(lock: *mut pthread_rwlock_t,
attr: *const pthread_rwlockattr_t) -> ::c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "pthread_rwlock_destroy$UNIX2003")]
pub fn pthread_rwlock_destroy(lock: *mut pthread_rwlock_t) -> ::c_int;
Expand All @@ -665,6 +669,9 @@ extern {
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "pthread_rwlock_unlock$UNIX2003")]
pub fn pthread_rwlock_unlock(lock: *mut pthread_rwlock_t) -> ::c_int;
pub fn pthread_rwlockattr_init(attr: *mut pthread_rwlockattr_t) -> ::c_int;
pub fn pthread_rwlockattr_destroy(attr: *mut pthread_rwlockattr_t)
-> ::c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "pthread_sigmask$UNIX2003")]
pub fn pthread_sigmask(how: ::c_int, set: *const sigset_t,
Expand Down
1 change: 1 addition & 0 deletions src/unix/notbsd/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub type nlink_t = u32;
pub type useconds_t = u32;
pub type pthread_t = ::c_long;
pub type pthread_mutexattr_t = ::c_long;
pub type pthread_rwlockattr_t = ::c_long;
pub type pthread_condattr_t = ::c_long;
pub type fsfilcnt_t = ::c_ulong;
pub type fsblkcnt_t = ::c_ulong;
Expand Down
1 change: 1 addition & 0 deletions src/unix/notbsd/linux/mips/mips32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ 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_MUTEXATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;

pub const RLIM_INFINITY: ::rlim_t = 0x7fffffff;

Expand Down
1 change: 1 addition & 0 deletions src/unix/notbsd/linux/mips/mips64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;

pub const RLIM_INFINITY: ::rlim_t = 0xffff_ffff_ffff_ffff;

Expand Down
10 changes: 10 additions & 0 deletions src/unix/notbsd/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ s! {
size: [u8; __SIZEOF_PTHREAD_MUTEXATTR_T],
}

pub struct pthread_rwlockattr_t {
#[cfg(any(target_env = "musl"))]
__align: [::c_int; 0],
#[cfg(not(any(target_env = "musl")))]
__align: [::c_long; 0],
size: [u8; __SIZEOF_PTHREAD_RWLOCKATTR_T],
}

pub struct pthread_cond_t {
#[cfg(any(target_env = "musl"))]
__align: [*const ::c_void; 0],
Expand Down Expand Up @@ -647,6 +655,8 @@ pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0;
pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1;
pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 2;
pub const PTHREAD_MUTEX_DEFAULT: ::c_int = PTHREAD_MUTEX_NORMAL;
pub const PTHREAD_PROCESS_PRIVATE: usize = 0;
pub const PTHREAD_PROCESS_SHARED: usize = 1;
pub const __SIZEOF_PTHREAD_COND_T: usize = 48;

pub const SCHED_OTHER: ::c_int = 0;
Expand Down
1 change: 1 addition & 0 deletions src/unix/notbsd/linux/musl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ pub const FALLOC_FL_PUNCH_HOLE: ::c_int = 0x02;

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 CPU_SETSIZE: ::c_int = 128;

Expand Down
1 change: 1 addition & 0 deletions src/unix/notbsd/linux/other/b32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ 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_MUTEXATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;

pub const PTRACE_GETFPREGS: ::c_uint = 14;
pub const PTRACE_SETFPREGS: ::c_uint = 15;
Expand Down
1 change: 1 addition & 0 deletions src/unix/notbsd/linux/other/b64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ s! {
}

pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;

cfg_if! {
if #[cfg(target_arch = "aarch64")] {
Expand Down
4 changes: 4 additions & 0 deletions src/unix/notbsd/linux/other/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,10 @@ extern {
pub fn pthread_setaffinity_np(thread: ::pthread_t,
cpusetsize: ::size_t,
cpuset: *const ::cpu_set_t) -> ::c_int;
pub fn pthread_rwlockattr_getkind_np(attr: *const ::pthread_rwlockattr_t,
val: *mut ::c_int) -> ::c_int;
pub fn pthread_rwlockattr_setkind_np(attr: *mut ::pthread_rwlockattr_t,
val: ::c_int) -> ::c_int;
pub fn sched_getcpu() -> ::c_int;
}

Expand Down
1 change: 1 addition & 0 deletions src/unix/notbsd/linux/s390x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;

pub const EADDRINUSE: ::c_int = 98;
pub const EADDRNOTAVAIL: ::c_int = 99;
Expand Down
4 changes: 4 additions & 0 deletions src/unix/notbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,10 @@ extern {
pshared: ::c_int) -> ::c_int;
pub fn pthread_mutexattr_getpshared(attr: *const pthread_mutexattr_t,
pshared: *mut ::c_int) -> ::c_int;
pub fn pthread_rwlockattr_getpshared(attr: *const pthread_rwlockattr_t,
val: *mut ::c_int) -> ::c_int;
pub fn pthread_rwlockattr_setpshared(attr: *mut pthread_rwlockattr_t,
val: ::c_int) -> ::c_int;
pub fn ptsname_r(fd: ::c_int,
buf: *mut ::c_char,
buflen: ::size_t) -> ::c_int;
Expand Down
6 changes: 5 additions & 1 deletion src/unix/solaris/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ s! {
__pthread_rwlock_writercv: ::pthread_cond_t
}

pub struct pthread_rwlockattr_t {
__pthread_rwlockattrp: *mut ::c_void,
}

pub struct dirent {
pub d_ino: ::ino_t,
pub d_off: ::off_t,
Expand Down Expand Up @@ -769,7 +773,7 @@ pub const POSIX_MADV_DONTNEED: ::c_int = 4;
pub const PTHREAD_CREATE_JOINABLE: ::c_int = 0;
pub const PTHREAD_CREATE_DETACHED: ::c_int = 0x40;
pub const PTHREAD_PROCESS_SHARED: ::c_int = 1;
pub const PTHREAD_PROCESS_PRIVATE: u16 = 0;
pub const PTHREAD_PROCESS_PRIVATE: ::c_int = 0;
pub const PTHREAD_STACK_MIN: ::size_t = 4096;

pub const SIGSTKSZ: ::size_t = 8192;
Expand Down
13 changes: 13 additions & 0 deletions src/unix/uclibc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ s! {
size: [u8; __SIZEOF_PTHREAD_MUTEXATTR_T],
}

pub struct pthread_rwlockattr_t {
__lockkind: ::c_int,
__pshared: ::c_int,
}

pub struct pthread_cond_t {
__align: [::c_longlong; 0],
size: [u8; __SIZEOF_PTHREAD_COND_T],
Expand Down Expand Up @@ -1577,6 +1582,14 @@ extern {
pshared: ::c_int) -> ::c_int;
pub fn pthread_mutexattr_getpshared(attr: *const pthread_mutexattr_t,
pshared: *mut ::c_int) -> ::c_int;
pub fn pthread_rwlockattr_getkind_np(attr: *const pthread_rwlockattr_t,
val: *mut ::c_int) -> ::c_int;
pub fn pthread_rwlockattr_setkind_np(attr: *mut pthread_rwlockattr_t,
val: ::c_int) -> ::c_int;
pub fn pthread_rwlockattr_getpshared(attr: *const pthread_rwlockattr_t,
val: *mut ::c_int) -> ::c_int;
pub fn pthread_rwlockattr_setpshared(attr: *mut pthread_rwlockattr_t,
val: ::c_int) -> ::c_int;
pub fn ptsname_r(fd: ::c_int,
buf: *mut ::c_char,
buflen: ::size_t) -> ::c_int;
Expand Down

0 comments on commit 83f5543

Please sign in to comment.