Skip to content

Commit 83f5543

Browse files
committed
Auto merge of #633 - main--:rwlockattr, r=alexcrichton
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).
2 parents 4dd6727 + b2de1fd commit 83f5543

File tree

20 files changed

+77
-1
lines changed

20 files changed

+77
-1
lines changed

src/unix/bsd/apple/b32.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub const __PTHREAD_MUTEX_SIZE__: usize = 40;
1414
pub const __PTHREAD_COND_SIZE__: usize = 24;
1515
pub const __PTHREAD_CONDATTR_SIZE__: usize = 4;
1616
pub const __PTHREAD_RWLOCK_SIZE__: usize = 124;
17+
pub const __PTHREAD_RWLOCKATTR_SIZE__: usize = 12;
1718

1819
pub const TIOCTIMESTAMP: ::c_ulong = 0x40087459;
1920
pub const TIOCDCDTIMESTAMP: ::c_ulong = 0x40087458;

src/unix/bsd/apple/b64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub const __PTHREAD_MUTEX_SIZE__: usize = 56;
1414
pub const __PTHREAD_COND_SIZE__: usize = 40;
1515
pub const __PTHREAD_CONDATTR_SIZE__: usize = 8;
1616
pub const __PTHREAD_RWLOCK_SIZE__: usize = 192;
17+
pub const __PTHREAD_RWLOCKATTR_SIZE__: usize = 16;
1718

1819
pub const TIOCTIMESTAMP: ::c_ulong = 0x40107459;
1920
pub const TIOCDCDTIMESTAMP: ::c_ulong = 0x40107458;

src/unix/bsd/apple/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ s! {
146146
__opaque: [u8; __PTHREAD_RWLOCK_SIZE__],
147147
}
148148

149+
pub struct pthread_rwlockattr_t {
150+
__sig: ::c_long,
151+
__opaque: [u8; __PTHREAD_RWLOCKATTR_SIZE__],
152+
}
153+
149154
pub struct siginfo_t {
150155
pub si_signo: ::c_int,
151156
pub si_errno: ::c_int,
@@ -804,6 +809,8 @@ pub const _SC_XOPEN_UNIX: ::c_int = 115;
804809
pub const _SC_XOPEN_VERSION: ::c_int = 116;
805810
pub const _SC_XOPEN_XCU_VERSION: ::c_int = 121;
806811

812+
pub const PTHREAD_PROCESS_PRIVATE: usize = 2;
813+
pub const PTHREAD_PROCESS_SHARED: usize = 1;
807814
pub const PTHREAD_CREATE_JOINABLE: ::c_int = 1;
808815
pub const PTHREAD_CREATE_DETACHED: ::c_int = 2;
809816
pub const PTHREAD_STACK_MIN: ::size_t = 8192;
@@ -1603,6 +1610,10 @@ extern {
16031610
pshared: ::c_int) -> ::c_int;
16041611
pub fn pthread_mutexattr_getpshared(attr: *const pthread_mutexattr_t,
16051612
pshared: *mut ::c_int) -> ::c_int;
1613+
pub fn pthread_rwlockattr_getpshared(attr: *const pthread_rwlockattr_t,
1614+
val: *mut ::c_int) -> ::c_int;
1615+
pub fn pthread_rwlockattr_setpshared(attr: *mut pthread_rwlockattr_t,
1616+
val: ::c_int) -> ::c_int;
16061617
pub fn __error() -> *mut ::c_int;
16071618
pub fn backtrace(buf: *mut *mut ::c_void,
16081619
sz: ::c_int) -> ::c_int;

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub type pthread_mutexattr_t = *mut ::c_void;
77
pub type pthread_cond_t = *mut ::c_void;
88
pub type pthread_condattr_t = *mut ::c_void;
99
pub type pthread_rwlock_t = *mut ::c_void;
10+
pub type pthread_rwlockattr_t = *mut ::c_void;
1011
pub type pthread_key_t = ::c_int;
1112
pub type tcflag_t = ::c_uint;
1213
pub type speed_t = ::c_uint;
@@ -466,6 +467,8 @@ pub const POSIX_MADV_SEQUENTIAL: ::c_int = 2;
466467
pub const POSIX_MADV_WILLNEED: ::c_int = 3;
467468
pub const POSIX_MADV_DONTNEED: ::c_int = 4;
468469

470+
pub const PTHREAD_PROCESS_PRIVATE: ::c_int = 0;
471+
pub const PTHREAD_PROCESS_SHARED: ::c_int = 1;
469472
pub const PTHREAD_CREATE_JOINABLE: ::c_int = 0;
470473
pub const PTHREAD_CREATE_DETACHED: ::c_int = 1;
471474

@@ -1059,6 +1062,10 @@ extern {
10591062
pshared: ::c_int) -> ::c_int;
10601063
pub fn pthread_mutexattr_getpshared(attr: *const pthread_mutexattr_t,
10611064
pshared: *mut ::c_int) -> ::c_int;
1065+
pub fn pthread_rwlockattr_getpshared(attr: *const pthread_rwlockattr_t,
1066+
val: *mut ::c_int) -> ::c_int;
1067+
pub fn pthread_rwlockattr_setpshared(attr: *mut pthread_rwlockattr_t,
1068+
val: ::c_int) -> ::c_int;
10621069
pub fn getpriority(which: ::c_int, who: ::c_int) -> ::c_int;
10631070
pub fn setpriority(which: ::c_int, who: ::c_int, prio: ::c_int) -> ::c_int;
10641071

src/unix/bsd/netbsdlike/netbsd/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ s! {
165165
ptma_private: *mut ::c_void,
166166
}
167167

168+
pub struct pthread_rwlockattr_t {
169+
ptra_magic: ::c_uint,
170+
ptra_private: *mut ::c_void,
171+
}
172+
168173
pub struct pthread_cond_t {
169174
ptc_magic: ::c_uint,
170175
ptc_lock: ::c_uchar,

src/unix/bsd/netbsdlike/openbsdlike/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub type pthread_mutexattr_t = *mut ::c_void;
1313
pub type pthread_cond_t = *mut ::c_void;
1414
pub type pthread_condattr_t = *mut ::c_void;
1515
pub type pthread_rwlock_t = *mut ::c_void;
16+
pub type pthread_rwlockattr_t = *mut ::c_void;
1617

1718
s! {
1819
pub struct dirent {

src/unix/haiku/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub type useconds_t = u32;
2323
pub type socklen_t = u32;
2424
pub type pthread_t = ::uintptr_t;
2525
pub type pthread_mutexattr_t = ::uintptr_t;
26+
pub type pthread_rwlockattr_t = ::uintptr_t;
2627
pub type sigset_t = u64;
2728
pub type fsblkcnt_t = i64;
2829
pub type fsfilcnt_t = i64;

src/unix/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,10 @@ extern {
647647
pub fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> ::c_int;
648648
pub fn pthread_condattr_init(attr: *mut pthread_condattr_t) -> ::c_int;
649649
pub fn pthread_condattr_destroy(attr: *mut pthread_condattr_t) -> ::c_int;
650+
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
651+
link_name = "pthread_rwlock_init$UNIX2003")]
652+
pub fn pthread_rwlock_init(lock: *mut pthread_rwlock_t,
653+
attr: *const pthread_rwlockattr_t) -> ::c_int;
650654
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
651655
link_name = "pthread_rwlock_destroy$UNIX2003")]
652656
pub fn pthread_rwlock_destroy(lock: *mut pthread_rwlock_t) -> ::c_int;
@@ -665,6 +669,9 @@ extern {
665669
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
666670
link_name = "pthread_rwlock_unlock$UNIX2003")]
667671
pub fn pthread_rwlock_unlock(lock: *mut pthread_rwlock_t) -> ::c_int;
672+
pub fn pthread_rwlockattr_init(attr: *mut pthread_rwlockattr_t) -> ::c_int;
673+
pub fn pthread_rwlockattr_destroy(attr: *mut pthread_rwlockattr_t)
674+
-> ::c_int;
668675
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
669676
link_name = "pthread_sigmask$UNIX2003")]
670677
pub fn pthread_sigmask(how: ::c_int, set: *const sigset_t,

src/unix/notbsd/android/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub type nlink_t = u32;
1212
pub type useconds_t = u32;
1313
pub type pthread_t = ::c_long;
1414
pub type pthread_mutexattr_t = ::c_long;
15+
pub type pthread_rwlockattr_t = ::c_long;
1516
pub type pthread_condattr_t = ::c_long;
1617
pub type fsfilcnt_t = ::c_ulong;
1718
pub type fsblkcnt_t = ::c_ulong;

src/unix/notbsd/linux/mips/mips32.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
229229
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24;
230230
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32;
231231
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
232+
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
232233

233234
pub const RLIM_INFINITY: ::rlim_t = 0x7fffffff;
234235

src/unix/notbsd/linux/mips/mips64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
215215
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
216216
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
217217
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
218+
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
218219

219220
pub const RLIM_INFINITY: ::rlim_t = 0xffff_ffff_ffff_ffff;
220221

src/unix/notbsd/linux/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ s! {
104104
size: [u8; __SIZEOF_PTHREAD_MUTEXATTR_T],
105105
}
106106

107+
pub struct pthread_rwlockattr_t {
108+
#[cfg(any(target_env = "musl"))]
109+
__align: [::c_int; 0],
110+
#[cfg(not(any(target_env = "musl")))]
111+
__align: [::c_long; 0],
112+
size: [u8; __SIZEOF_PTHREAD_RWLOCKATTR_T],
113+
}
114+
107115
pub struct pthread_cond_t {
108116
#[cfg(any(target_env = "musl"))]
109117
__align: [*const ::c_void; 0],
@@ -647,6 +655,8 @@ pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0;
647655
pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1;
648656
pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 2;
649657
pub const PTHREAD_MUTEX_DEFAULT: ::c_int = PTHREAD_MUTEX_NORMAL;
658+
pub const PTHREAD_PROCESS_PRIVATE: usize = 0;
659+
pub const PTHREAD_PROCESS_SHARED: usize = 1;
650660
pub const __SIZEOF_PTHREAD_COND_T: usize = 48;
651661

652662
pub const SCHED_OTHER: ::c_int = 0;

src/unix/notbsd/linux/musl/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ pub const FALLOC_FL_PUNCH_HOLE: ::c_int = 0x02;
160160

161161
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
162162
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
163+
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
163164

164165
pub const CPU_SETSIZE: ::c_int = 128;
165166

src/unix/notbsd/linux/other/b32/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
263263
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24;
264264
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32;
265265
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
266+
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
266267

267268
pub const PTRACE_GETFPREGS: ::c_uint = 14;
268269
pub const PTRACE_SETFPREGS: ::c_uint = 15;

src/unix/notbsd/linux/other/b64/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ s! {
4747
}
4848

4949
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
50+
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
5051

5152
cfg_if! {
5253
if #[cfg(target_arch = "aarch64")] {

src/unix/notbsd/linux/other/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,10 @@ extern {
576576
pub fn pthread_setaffinity_np(thread: ::pthread_t,
577577
cpusetsize: ::size_t,
578578
cpuset: *const ::cpu_set_t) -> ::c_int;
579+
pub fn pthread_rwlockattr_getkind_np(attr: *const ::pthread_rwlockattr_t,
580+
val: *mut ::c_int) -> ::c_int;
581+
pub fn pthread_rwlockattr_setkind_np(attr: *mut ::pthread_rwlockattr_t,
582+
val: ::c_int) -> ::c_int;
579583
pub fn sched_getcpu() -> ::c_int;
580584
}
581585

src/unix/notbsd/linux/s390x.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
314314
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
315315
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
316316
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
317+
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
317318

318319
pub const EADDRINUSE: ::c_int = 98;
319320
pub const EADDRNOTAVAIL: ::c_int = 99;

src/unix/notbsd/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,10 @@ extern {
992992
pshared: ::c_int) -> ::c_int;
993993
pub fn pthread_mutexattr_getpshared(attr: *const pthread_mutexattr_t,
994994
pshared: *mut ::c_int) -> ::c_int;
995+
pub fn pthread_rwlockattr_getpshared(attr: *const pthread_rwlockattr_t,
996+
val: *mut ::c_int) -> ::c_int;
997+
pub fn pthread_rwlockattr_setpshared(attr: *mut pthread_rwlockattr_t,
998+
val: ::c_int) -> ::c_int;
995999
pub fn ptsname_r(fd: ::c_int,
9961000
buf: *mut ::c_char,
9971001
buflen: ::size_t) -> ::c_int;

src/unix/solaris/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ s! {
169169
__pthread_rwlock_writercv: ::pthread_cond_t
170170
}
171171

172+
pub struct pthread_rwlockattr_t {
173+
__pthread_rwlockattrp: *mut ::c_void,
174+
}
175+
172176
pub struct dirent {
173177
pub d_ino: ::ino_t,
174178
pub d_off: ::off_t,
@@ -769,7 +773,7 @@ pub const POSIX_MADV_DONTNEED: ::c_int = 4;
769773
pub const PTHREAD_CREATE_JOINABLE: ::c_int = 0;
770774
pub const PTHREAD_CREATE_DETACHED: ::c_int = 0x40;
771775
pub const PTHREAD_PROCESS_SHARED: ::c_int = 1;
772-
pub const PTHREAD_PROCESS_PRIVATE: u16 = 0;
776+
pub const PTHREAD_PROCESS_PRIVATE: ::c_int = 0;
773777
pub const PTHREAD_STACK_MIN: ::size_t = 4096;
774778

775779
pub const SIGSTKSZ: ::size_t = 8192;

src/unix/uclibc/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ s! {
257257
size: [u8; __SIZEOF_PTHREAD_MUTEXATTR_T],
258258
}
259259

260+
pub struct pthread_rwlockattr_t {
261+
__lockkind: ::c_int,
262+
__pshared: ::c_int,
263+
}
264+
260265
pub struct pthread_cond_t {
261266
__align: [::c_longlong; 0],
262267
size: [u8; __SIZEOF_PTHREAD_COND_T],
@@ -1577,6 +1582,14 @@ extern {
15771582
pshared: ::c_int) -> ::c_int;
15781583
pub fn pthread_mutexattr_getpshared(attr: *const pthread_mutexattr_t,
15791584
pshared: *mut ::c_int) -> ::c_int;
1585+
pub fn pthread_rwlockattr_getkind_np(attr: *const pthread_rwlockattr_t,
1586+
val: *mut ::c_int) -> ::c_int;
1587+
pub fn pthread_rwlockattr_setkind_np(attr: *mut pthread_rwlockattr_t,
1588+
val: ::c_int) -> ::c_int;
1589+
pub fn pthread_rwlockattr_getpshared(attr: *const pthread_rwlockattr_t,
1590+
val: *mut ::c_int) -> ::c_int;
1591+
pub fn pthread_rwlockattr_setpshared(attr: *mut pthread_rwlockattr_t,
1592+
val: ::c_int) -> ::c_int;
15801593
pub fn ptsname_r(fd: ::c_int,
15811594
buf: *mut ::c_char,
15821595
buflen: ::size_t) -> ::c_int;

0 commit comments

Comments
 (0)