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

0 commit comments

Comments
 (0)