Skip to content

Commit b065b3c

Browse files
authored
Merge pull request rust-lang#335 from tmiasko/condattr
Add support for pthread_condattr_t on Unix platforms.
2 parents 32dc2ea + c4947bb commit b065b3c

File tree

20 files changed

+54
-1
lines changed

20 files changed

+54
-1
lines changed

libc-test/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ fn main() {
2222
let bsdlike = freebsd || apple || netbsd || openbsd || dragonfly;
2323
let mut cfg = ctest::TestGenerator::new();
2424

25-
// Pull in extra goodies on linux/mingw
25+
// Pull in extra goodies
2626
if linux || android {
2727
cfg.define("_GNU_SOURCE", None);
28+
} else if netbsd {
29+
cfg.define("_NETBSD_SOURCE", Some("1"));
2830
} else if windows {
2931
cfg.define("_WIN32_WINNT", Some("0x8000"));
3032
}

src/unix/bsd/apple/b32.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ s! {
1212

1313
pub const __PTHREAD_MUTEX_SIZE__: usize = 40;
1414
pub const __PTHREAD_COND_SIZE__: usize = 24;
15+
pub const __PTHREAD_CONDATTR_SIZE__: usize = 4;
1516
pub const __PTHREAD_RWLOCK_SIZE__: usize = 124;
1617

1718
pub const TIOCTIMESTAMP: ::c_ulong = 0x40087459;

src/unix/bsd/apple/b64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ s! {
1212

1313
pub const __PTHREAD_MUTEX_SIZE__: usize = 56;
1414
pub const __PTHREAD_COND_SIZE__: usize = 40;
15+
pub const __PTHREAD_CONDATTR_SIZE__: usize = 8;
1516
pub const __PTHREAD_RWLOCK_SIZE__: usize = 192;
1617

1718
pub const TIOCTIMESTAMP: ::c_ulong = 0x40107459;

src/unix/bsd/apple/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ s! {
114114
__opaque: [u8; __PTHREAD_COND_SIZE__],
115115
}
116116

117+
pub struct pthread_condattr_t {
118+
__sig: ::c_long,
119+
__opaque: [u8; __PTHREAD_CONDATTR_SIZE__],
120+
}
121+
117122
pub struct pthread_rwlock_t {
118123
__sig: ::c_long,
119124
__opaque: [u8; __PTHREAD_RWLOCK_SIZE__],

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub type rlim_t = i64;
55
pub type pthread_mutex_t = *mut ::c_void;
66
pub type pthread_mutexattr_t = *mut ::c_void;
77
pub type pthread_cond_t = *mut ::c_void;
8+
pub type pthread_condattr_t = *mut ::c_void;
89
pub type pthread_rwlock_t = *mut ::c_void;
910
pub type pthread_key_t = ::c_int;
1011
pub type tcflag_t = ::c_uint;
@@ -806,6 +807,10 @@ extern {
806807
flags: ::c_int) -> ::c_int;
807808
pub fn mkfifoat(dirfd: ::c_int, pathname: *const ::c_char,
808809
mode: ::mode_t) -> ::c_int;
810+
pub fn pthread_condattr_getclock(attr: *const pthread_condattr_t,
811+
clock_id: *mut clockid_t) -> ::c_int;
812+
pub fn pthread_condattr_setclock(attr: *mut pthread_condattr_t,
813+
clock_id: clockid_t) -> ::c_int;
809814
}
810815

811816
cfg_if! {

src/unix/bsd/openbsdlike/bitrig.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub type pthread_attr_t = *mut ::c_void;
99
pub type pthread_mutex_t = *mut ::c_void;
1010
pub type pthread_mutexattr_t = *mut ::c_void;
1111
pub type pthread_cond_t = *mut ::c_void;
12+
pub type pthread_condattr_t = *mut ::c_void;
1213
pub type pthread_rwlock_t = *mut ::c_void;
1314

1415
s! {

src/unix/bsd/openbsdlike/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,8 @@ extern {
525525
flags: ::c_int) -> ::c_int;
526526
pub fn mkfifoat(dirfd: ::c_int, pathname: *const ::c_char,
527527
mode: ::mode_t) -> ::c_int;
528+
pub fn pthread_condattr_setclock(attr: *mut pthread_condattr_t,
529+
clock_id: clockid_t) -> ::c_int;
528530
}
529531

530532
cfg_if! {

src/unix/bsd/openbsdlike/netbsd.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ s! {
152152
ptc_private: *mut ::c_void,
153153
}
154154

155+
pub struct pthread_condattr_t {
156+
ptca_magic: ::c_uint,
157+
ptca_private: *mut ::c_void,
158+
}
159+
155160
pub struct pthread_rwlock_t {
156161
ptr_magic: ::c_uint,
157162
ptr_interlock: ::c_uchar,

src/unix/bsd/openbsdlike/openbsd.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub type pthread_attr_t = *mut ::c_void;
99
pub type pthread_mutex_t = *mut ::c_void;
1010
pub type pthread_mutexattr_t = *mut ::c_void;
1111
pub type pthread_cond_t = *mut ::c_void;
12+
pub type pthread_condattr_t = *mut ::c_void;
1213
pub type pthread_rwlock_t = *mut ::c_void;
1314

1415
s! {

src/unix/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,10 @@ extern {
538538
pub fn pthread_mutexattr_settype(attr: *mut pthread_mutexattr_t,
539539
_type: ::c_int) -> ::c_int;
540540

541+
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
542+
link_name = "pthread_cond_init$UNIX2003")]
543+
pub fn pthread_cond_init(cond: *mut pthread_cond_t,
544+
attr: *const pthread_condattr_t) -> ::c_int;
541545
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
542546
link_name = "pthread_cond_wait$UNIX2003")]
543547
pub fn pthread_cond_wait(cond: *mut pthread_cond_t,
@@ -550,6 +554,8 @@ extern {
550554
pub fn pthread_cond_signal(cond: *mut pthread_cond_t) -> ::c_int;
551555
pub fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> ::c_int;
552556
pub fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> ::c_int;
557+
pub fn pthread_condattr_init(attr: *mut pthread_condattr_t) -> ::c_int;
558+
pub fn pthread_condattr_destroy(attr: *mut pthread_condattr_t) -> ::c_int;
553559
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
554560
link_name = "pthread_rwlock_destroy$UNIX2003")]
555561
pub fn pthread_rwlock_destroy(lock: *mut pthread_rwlock_t) -> ::c_int;

src/unix/notbsd/android/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub type useconds_t = u32;
1313
pub type socklen_t = i32;
1414
pub type pthread_t = ::c_long;
1515
pub type pthread_mutexattr_t = ::c_long;
16+
pub type pthread_condattr_t = ::c_long;
1617
pub type sigset_t = ::c_ulong;
1718
pub type time64_t = i64; // N/A on android
1819
pub type fsfilcnt_t = ::c_ulong;

src/unix/notbsd/linux/mips.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ pub const SO_RCVTIMEO: ::c_int = 4102;
378378
pub const SO_SNDTIMEO: ::c_int = 4101;
379379
pub const SO_ACCEPTCONN: ::c_int = 4105;
380380

381+
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
381382
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24;
382383
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32;
383384
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;

src/unix/notbsd/linux/mod.rs

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

107+
pub struct pthread_condattr_t {
108+
__align: [::c_int; 0],
109+
size: [u8; __SIZEOF_PTHREAD_CONDATTR_T],
110+
}
111+
107112
pub struct passwd {
108113
pub pw_name: *mut ::c_char,
109114
pub pw_passwd: *mut ::c_char,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ pub const SIGUNUSED: ::c_int = ::SIGSYS;
107107
pub const FALLOC_FL_KEEP_SIZE: ::c_int = 0x01;
108108
pub const FALLOC_FL_PUNCH_HOLE: ::c_int = 0x02;
109109

110+
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
110111
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
111112

112113
pub const CPU_SETSIZE: ::c_int = 128;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ s! {
8585
}
8686
}
8787

88+
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
8889
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24;
8990
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32;
9091
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ s! {
5555
}
5656
}
5757

58+
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 8;
5859
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 48;
5960
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 8;
6061

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ s! {
5353
}
5454
}
5555

56+
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
5657
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
5758
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
5859

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ s! {
9393
}
9494
}
9595

96+
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
9697
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
9798
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
9899

src/unix/notbsd/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,10 @@ extern {
860860
linkpath: *const ::c_char) -> ::c_int;
861861
pub fn unlinkat(dirfd: ::c_int, pathname: *const ::c_char,
862862
flags: ::c_int) -> ::c_int;
863+
pub fn pthread_condattr_getclock(attr: *const pthread_condattr_t,
864+
clock_id: *mut clockid_t) -> ::c_int;
865+
pub fn pthread_condattr_setclock(attr: *mut pthread_condattr_t,
866+
clock_id: clockid_t) -> ::c_int;
863867
}
864868

865869
cfg_if! {

src/unix/solaris/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ s! {
143143
__pthread_cond_data: u64
144144
}
145145

146+
pub struct pthread_condattr_t {
147+
__pthread_condattrp: *mut ::c_void,
148+
}
149+
146150
pub struct pthread_rwlock_t {
147151
__pthread_rwlock_readers: i32,
148152
__pthread_rwlock_type: u16,
@@ -1013,5 +1017,9 @@ extern {
10131017
pub fn sethostname(name: *const ::c_char, len: ::size_t) -> ::c_int;
10141018
pub fn if_nameindex() -> *mut if_nameindex;
10151019
pub fn if_freenameindex(ptr: *mut if_nameindex);
1020+
pub fn pthread_condattr_getclock(attr: *const pthread_condattr_t,
1021+
clock_id: *mut clockid_t) -> ::c_int;
1022+
pub fn pthread_condattr_setclock(attr: *mut pthread_condattr_t,
1023+
clock_id: clockid_t) -> ::c_int;
10161024
}
10171025

0 commit comments

Comments
 (0)