Skip to content

Commit 29b5331

Browse files
committed
fuchsia: fix pthread.h definitions
Remove opaque types. Replace with proper fields. Remove conditional defintion for 32-bit targets. Fuchsia has no 32-bit targets. Static initializers needed modification. They are specified as `{ 0 }` in POSIX for C. The new definition replicates that. It zeroes/nullifies the new fields. Constants were used to initialize the previous opaque array. These have been deprecated. These are declared in [1]. [1]: https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/third_party/ulib/musl/include/pthread.h
1 parent 74384c2 commit 29b5331

1 file changed

Lines changed: 62 additions & 55 deletions

File tree

src/fuchsia/mod.rs

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,15 @@ s! {
778778
}
779779

780780
pub struct pthread_attr_t {
781-
__size: [u64; 7],
781+
__name: *const c_char,
782+
__c11: c_int,
783+
_a_stacksize: crate::size_t,
784+
_a_guardsize: crate::size_t,
785+
_a_stackaddr: *mut c_void,
786+
_a_detach: c_int,
787+
_a_sched: c_int,
788+
_a_policy: c_int,
789+
_a_prio: c_int,
782790
}
783791

784792
pub struct sigset_t {
@@ -879,27 +887,16 @@ s! {
879887
pub ipi6_ifindex: c_uint,
880888
}
881889

882-
#[cfg_attr(
883-
any(target_pointer_width = "32", target_arch = "x86_64"),
884-
repr(align(4))
885-
)]
886-
#[cfg_attr(
887-
not(any(target_pointer_width = "32", target_arch = "x86_64")),
888-
repr(align(8))
889-
)]
890890
pub struct pthread_mutexattr_t {
891-
size: [u8; crate::__SIZEOF_PTHREAD_MUTEXATTR_T],
891+
pub __attr: c_uint,
892892
}
893893

894-
#[cfg_attr(target_pointer_width = "32", repr(align(4)))]
895-
#[cfg_attr(target_pointer_width = "64", repr(align(8)))]
896894
pub struct pthread_rwlockattr_t {
897-
size: [u8; crate::__SIZEOF_PTHREAD_RWLOCKATTR_T],
895+
pub __attr: [c_uint; 2],
898896
}
899897

900-
#[repr(align(4))]
901898
pub struct pthread_condattr_t {
902-
size: [u8; crate::__SIZEOF_PTHREAD_CONDATTR_T],
899+
pub __attr: c_uint,
903900
}
904901

905902
#[deprecated(since = "0.2.187", note = "This type doesn't exist upstream.")]
@@ -1007,53 +1004,28 @@ s! {
10071004
pub sigev_value: crate::sigval,
10081005
pub sigev_signo: c_int,
10091006
pub sigev_notify: c_int,
1010-
pub sigev_notify_function: fn(crate::sigval),
1007+
pub sigev_notify_function: Option<extern "C" fn(crate::sigval)>,
10111008
pub sigev_notify_attributes: *mut pthread_attr_t,
1012-
pub __pad: [c_char; 56 - 3 * 8],
1009+
__pad: Padding<[c_char; 56 - 3 * size_of::<c_long>()]>,
10131010
}
10141011

1015-
#[cfg_attr(
1016-
all(
1017-
target_pointer_width = "32",
1018-
any(target_arch = "arm", target_arch = "x86_64")
1019-
),
1020-
repr(align(4))
1021-
)]
1022-
#[cfg_attr(
1023-
any(
1024-
target_pointer_width = "64",
1025-
not(any(target_arch = "arm", target_arch = "x86_64"))
1026-
),
1027-
repr(align(8))
1028-
)]
10291012
pub struct pthread_mutex_t {
1030-
size: [u8; crate::__SIZEOF_PTHREAD_MUTEX_T],
1013+
pub _m_attr: c_uint,
1014+
pub _m_lock: c_int,
1015+
pub _m_waiters: c_int,
1016+
pub _m_count: c_int,
10311017
}
10321018

1033-
#[cfg_attr(
1034-
all(
1035-
target_pointer_width = "32",
1036-
any(target_arch = "arm", target_arch = "x86_64")
1037-
),
1038-
repr(align(4))
1039-
)]
1040-
#[cfg_attr(
1041-
any(
1042-
target_pointer_width = "64",
1043-
not(any(target_arch = "arm", target_arch = "x86_64"))
1044-
),
1045-
repr(align(8))
1046-
)]
10471019
pub struct pthread_rwlock_t {
1048-
size: [u8; crate::__SIZEOF_PTHREAD_RWLOCK_T],
1020+
pub _rw_lock: c_int,
1021+
pub _rw_waiters: c_int,
10491022
}
10501023

1051-
#[cfg_attr(target_pointer_width = "32", repr(align(4)))]
1052-
#[cfg_attr(target_pointer_width = "64", repr(align(8)))]
1053-
#[cfg_attr(target_arch = "x86", repr(align(4)))]
1054-
#[cfg_attr(not(target_arch = "x86"), repr(align(8)))]
10551024
pub struct pthread_cond_t {
1056-
size: [u8; crate::__SIZEOF_PTHREAD_COND_T],
1025+
pub _c_head: *mut c_void,
1026+
pub _c_clock: c_int,
1027+
pub _c_tail: *mut c_void,
1028+
pub _c_lock: c_int,
10571029
}
10581030
}
10591031

@@ -2151,20 +2123,32 @@ pub const RTLD_NOW: c_int = 0x2;
21512123
pub const TCP_MD5SIG: c_int = 14;
21522124

21532125
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
2154-
size: [0; __SIZEOF_PTHREAD_MUTEX_T],
2126+
_m_attr: 0,
2127+
_m_lock: 0,
2128+
_m_waiters: 0,
2129+
_m_count: 0,
21552130
};
21562131
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
2157-
size: [0; __SIZEOF_PTHREAD_COND_T],
2132+
_c_head: ptr::null_mut(),
2133+
_c_clock: 0,
2134+
_c_tail: ptr::null_mut(),
2135+
_c_lock: 0,
21582136
};
21592137
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
2160-
size: [0; __SIZEOF_PTHREAD_RWLOCK_T],
2138+
_rw_lock: 0,
2139+
_rw_waiters: 0,
21612140
};
21622141
pub const PTHREAD_MUTEX_NORMAL: c_int = 0;
21632142
pub const PTHREAD_MUTEX_RECURSIVE: c_int = 1;
21642143
pub const PTHREAD_MUTEX_ERRORCHECK: c_int = 2;
21652144
pub const PTHREAD_MUTEX_DEFAULT: c_int = PTHREAD_MUTEX_NORMAL;
21662145
pub const PTHREAD_PROCESS_PRIVATE: c_int = 0;
21672146
pub const PTHREAD_PROCESS_SHARED: c_int = 1;
2147+
2148+
#[deprecated(
2149+
since = "0.2.187",
2150+
note = "This type doesn't exist. It's not part of the Fuchsia SDK."
2151+
)]
21682152
pub const __SIZEOF_PTHREAD_COND_T: usize = 48;
21692153

21702154
pub const RENAME_NOREPLACE: c_int = 1;
@@ -2686,8 +2670,22 @@ pub const TCP_TIMESTAMP: c_int = 24;
26862670

26872671
pub const SIGUNUSED: c_int = crate::SIGSYS;
26882672

2673+
#[deprecated(
2674+
since = "0.2.187",
2675+
note = "This type doesn't exist. It's not part of the Fuchsia SDK."
2676+
)]
26892677
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
2678+
2679+
#[deprecated(
2680+
since = "0.2.187",
2681+
note = "This type doesn't exist. It's not part of the Fuchsia SDK."
2682+
)]
26902683
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
2684+
2685+
#[deprecated(
2686+
since = "0.2.187",
2687+
note = "This type doesn't exist. It's not part of the Fuchsia SDK."
2688+
)]
26912689
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
26922690

26932691
pub const CPU_SETSIZE: c_int = 128;
@@ -2826,7 +2824,16 @@ pub const B3000000: crate::speed_t = 0o010015;
28262824
pub const B3500000: crate::speed_t = 0o010016;
28272825
pub const B4000000: crate::speed_t = 0o010017;
28282826

2827+
#[deprecated(
2828+
since = "0.2.187",
2829+
note = "This type doesn't exist. It's not part of the Fuchsia SDK."
2830+
)]
28292831
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
2832+
2833+
#[deprecated(
2834+
since = "0.2.187",
2835+
note = "This type doesn't exist. It's not part of the Fuchsia SDK."
2836+
)]
28302837
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
28312838

28322839
pub const O_ASYNC: c_int = 0x00000400;

0 commit comments

Comments
 (0)