Skip to content

Commit 55ab890

Browse files
committed
l4re: Update available pthread API
This is imperfect but should get things closer to what is available on l4re's uclibc fork. Based on work by Marius Melzer [#4479]. [#4479]: #4479 (backport <#4836>) (cherry picked from commit 34d8ce7)
1 parent b8bdde0 commit 55ab890

File tree

6 files changed

+68
-42
lines changed

6 files changed

+68
-42
lines changed

src/new/common/linux_like/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
//! API that primarily comes from Linux but is also used other platforms (e.g. Android).
22
3-
#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))]
3+
#[cfg(any(
4+
target_os = "android",
5+
target_os = "emscripten",
6+
target_os = "l4re",
7+
target_os = "linux"
8+
))]
49
pub(crate) mod pthread;

src/new/common/posix/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
//! These can be found at: <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/contents.html>.
44
55
// FIXME(pthread): eventually all platforms should use this module
6-
#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))]
6+
#[cfg(any(
7+
target_os = "android",
8+
target_os = "emscripten",
9+
target_os = "l4re",
10+
target_os = "linux"
11+
))]
712
pub(crate) mod pthread;
813
pub(crate) mod unistd;

src/new/common/posix/pthread.rs

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ extern "C" {
1212
child: Option<unsafe extern "C" fn()>,
1313
) -> c_int;
1414

15-
#[cfg(any(target_os = "android", target_os = "linux"))]
15+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
1616
pub fn pthread_attr_getguardsize(
1717
attr: *const crate::pthread_attr_t,
1818
guardsize: *mut size_t,
1919
) -> c_int;
2020

21-
#[cfg(any(target_os = "android", target_os = "linux"))]
21+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
2222
pub fn pthread_attr_getinheritsched(
2323
attr: *const crate::pthread_attr_t,
2424
inheritsched: *mut c_int,
2525
) -> c_int;
2626

27-
#[cfg(target_os = "linux")]
27+
#[cfg(any(target_os = "l4re", target_os = "linux"))]
2828
pub fn pthread_attr_getschedparam(
2929
attr: *const crate::pthread_attr_t,
3030
param: *mut crate::sched_param,
3131
) -> c_int;
3232

33-
#[cfg(target_os = "linux")]
33+
#[cfg(any(target_os = "l4re", target_os = "linux"))]
3434
pub fn pthread_attr_getschedpolicy(
3535
attr: *const crate::pthread_attr_t,
3636
policy: *mut c_int,
@@ -48,22 +48,22 @@ extern "C" {
4848
stacksize: *mut size_t,
4949
) -> c_int;
5050

51-
#[cfg(any(target_os = "android", target_os = "linux"))]
51+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
5252
pub fn pthread_attr_setguardsize(attr: *mut crate::pthread_attr_t, guardsize: size_t) -> c_int;
5353

54-
#[cfg(any(target_os = "android", target_os = "linux"))]
54+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
5555
pub fn pthread_attr_setinheritsched(
5656
attr: *mut crate::pthread_attr_t,
5757
inheritsched: c_int,
5858
) -> c_int;
5959

60-
#[cfg(target_os = "linux")]
60+
#[cfg(any(target_os = "l4re", target_os = "linux"))]
6161
pub fn pthread_attr_setschedparam(
6262
attr: *mut crate::pthread_attr_t,
6363
param: *const crate::sched_param,
6464
) -> c_int;
6565

66-
#[cfg(target_os = "linux")]
66+
#[cfg(any(target_os = "l4re", target_os = "linux"))]
6767
pub fn pthread_attr_setschedpolicy(attr: *mut crate::pthread_attr_t, policy: c_int) -> c_int;
6868

6969
#[cfg(any(
@@ -78,20 +78,20 @@ extern "C" {
7878
stacksize: size_t,
7979
) -> c_int;
8080

81-
#[cfg(any(target_os = "android", target_os = "linux"))]
81+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
8282
pub fn pthread_barrier_destroy(barrier: *mut crate::pthread_barrier_t) -> c_int;
8383

84-
#[cfg(any(target_os = "android", target_os = "linux"))]
84+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
8585
pub fn pthread_barrier_init(
8686
barrier: *mut crate::pthread_barrier_t,
8787
attr: *const crate::pthread_barrierattr_t,
8888
count: c_uint,
8989
) -> c_int;
9090

91-
#[cfg(any(target_os = "android", target_os = "linux"))]
91+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
9292
pub fn pthread_barrier_wait(barrier: *mut crate::pthread_barrier_t) -> c_int;
9393

94-
#[cfg(any(target_os = "android", target_os = "linux"))]
94+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
9595
pub fn pthread_barrierattr_destroy(attr: *mut crate::pthread_barrierattr_t) -> c_int;
9696

9797
#[cfg(any(target_os = "android", target_os = "linux"))]
@@ -100,16 +100,16 @@ extern "C" {
100100
shared: *mut c_int,
101101
) -> c_int;
102102

103-
#[cfg(any(target_os = "android", target_os = "linux"))]
103+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
104104
pub fn pthread_barrierattr_init(attr: *mut crate::pthread_barrierattr_t) -> c_int;
105105

106-
#[cfg(any(target_os = "android", target_os = "linux"))]
106+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
107107
pub fn pthread_barrierattr_setpshared(
108108
attr: *mut crate::pthread_barrierattr_t,
109109
shared: c_int,
110110
) -> c_int;
111111

112-
#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
112+
#[cfg(any(target_os = "l4re", all(target_os = "linux", not(target_env = "ohos"))))]
113113
pub fn pthread_cancel(thread: crate::pthread_t) -> c_int;
114114

115115
#[cfg(any(
@@ -123,7 +123,7 @@ extern "C" {
123123
clock_id: *mut crate::clockid_t,
124124
) -> c_int;
125125

126-
#[cfg(any(target_os = "android", target_os = "linux"))]
126+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
127127
pub fn pthread_condattr_getpshared(
128128
attr: *const crate::pthread_condattr_t,
129129
pshared: *mut c_int,
@@ -151,7 +151,12 @@ extern "C" {
151151
pshared: c_int,
152152
) -> c_int;
153153

154-
#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))]
154+
#[cfg(any(
155+
target_os = "android",
156+
target_os = "emscripten",
157+
target_os = "l4re",
158+
target_os = "linux"
159+
))]
155160
pub fn pthread_create(
156161
native: *mut crate::pthread_t,
157162
attr: *const crate::pthread_attr_t,
@@ -162,7 +167,7 @@ extern "C" {
162167
#[cfg(any(target_os = "android", target_os = "linux"))]
163168
pub fn pthread_getcpuclockid(thread: crate::pthread_t, clk_id: *mut crate::clockid_t) -> c_int;
164169

165-
#[cfg(any(target_os = "android", target_os = "linux"))]
170+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
166171
pub fn pthread_getschedparam(
167172
native: crate::pthread_t,
168173
policy: *mut c_int,
@@ -171,13 +176,13 @@ extern "C" {
171176

172177
// FIXME(reorg): In recent POSIX versions, this is a signal.h function and not required
173178
// in pthread.
174-
#[cfg(any(target_os = "android", target_os = "linux"))]
179+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
175180
pub fn pthread_kill(thread: crate::pthread_t, sig: c_int) -> c_int;
176181

177182
#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
178183
pub fn pthread_mutex_consistent(mutex: *mut crate::pthread_mutex_t) -> c_int;
179184

180-
#[cfg(any(target_os = "android", target_os = "linux"))]
185+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
181186
#[cfg_attr(gnu_time_bits64, link_name = "__pthread_mutex_timedlock64")]
182187
pub fn pthread_mutex_timedlock(
183188
lock: *mut crate::pthread_mutex_t,
@@ -190,7 +195,7 @@ extern "C" {
190195
protocol: *mut c_int,
191196
) -> c_int;
192197

193-
#[cfg(any(target_os = "android", target_os = "linux"))]
198+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
194199
pub fn pthread_mutexattr_getpshared(
195200
attr: *const crate::pthread_mutexattr_t,
196201
pshared: *mut c_int,
@@ -247,10 +252,10 @@ extern "C" {
247252
val: c_int,
248253
) -> c_int;
249254

250-
#[cfg(target_os = "linux")]
255+
#[cfg(any(target_os = "l4re", target_os = "linux"))]
251256
pub fn pthread_once(control: *mut crate::pthread_once_t, routine: extern "C" fn()) -> c_int;
252257

253-
#[cfg(any(target_os = "android", target_os = "linux"))]
258+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
254259
pub fn pthread_setschedparam(
255260
native: crate::pthread_t,
256261
policy: c_int,
@@ -262,25 +267,25 @@ extern "C" {
262267

263268
// FIXME(reorg): In recent POSIX versions, this is a signal.h function and not required
264269
// in pthread.
265-
#[cfg(any(target_os = "android", target_os = "linux"))]
270+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
266271
pub fn pthread_sigmask(
267272
how: c_int,
268273
set: *const crate::sigset_t,
269274
oldset: *mut crate::sigset_t,
270275
) -> c_int;
271276

272-
#[cfg(any(target_os = "android", target_os = "linux"))]
277+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
273278
pub fn pthread_spin_destroy(lock: *mut crate::pthread_spinlock_t) -> c_int;
274279

275-
#[cfg(any(target_os = "android", target_os = "linux"))]
280+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
276281
pub fn pthread_spin_init(lock: *mut crate::pthread_spinlock_t, pshared: c_int) -> c_int;
277282

278-
#[cfg(any(target_os = "android", target_os = "linux"))]
283+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
279284
pub fn pthread_spin_lock(lock: *mut crate::pthread_spinlock_t) -> c_int;
280285

281-
#[cfg(any(target_os = "android", target_os = "linux"))]
286+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
282287
pub fn pthread_spin_trylock(lock: *mut crate::pthread_spinlock_t) -> c_int;
283288

284-
#[cfg(any(target_os = "android", target_os = "linux"))]
289+
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
285290
pub fn pthread_spin_unlock(lock: *mut crate::pthread_spinlock_t) -> c_int;
286291
}

src/new/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,12 @@ cfg_if! {
207207
cfg_if! {
208208
if #[cfg(target_family = "unix")] {
209209
// FIXME(pthread): eventually all platforms should use this module
210-
#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))]
210+
#[cfg(any(
211+
target_os = "android",
212+
target_os = "emscripten",
213+
target_os = "l4re",
214+
target_os = "linux"
215+
))]
211216
pub use pthread::*;
212217
pub use unistd::*;
213218
}

src/new/uclibc/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
//! * About: <https://uclibc.org/>
44
//! * Headers: <https://github.com/kraj/uClibc> (mirror)
55
6-
#[cfg(target_os = "linux")]
76
pub(crate) mod pthread;
87
pub(crate) mod unistd;

src/new/uclibc/pthread.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
//! Header: `pthread.h`
2+
//!
3+
//! Note that The l4re port of uclibc doesn't yet support all `pthread_*` API that is
4+
//! available upstream.
25
6+
pub use crate::new::common::linux_like::pthread::pthread_getattr_np;
7+
#[cfg(not(target_os = "l4re"))]
38
pub use crate::new::common::linux_like::pthread::{
49
pthread_getaffinity_np,
5-
pthread_getattr_np,
610
pthread_getname_np,
711
pthread_setaffinity_np,
812
pthread_setname_np,
913
};
14+
#[cfg(not(target_os = "l4re"))]
1015
pub use crate::new::common::posix::pthread::{
1116
pthread_atfork,
17+
pthread_barrierattr_getpshared,
18+
pthread_getcpuclockid,
19+
pthread_mutex_consistent,
20+
pthread_mutexattr_getprotocol,
21+
pthread_mutexattr_getrobust,
22+
pthread_mutexattr_setprotocol,
23+
pthread_mutexattr_setrobust,
24+
pthread_setschedprio,
25+
};
26+
pub use crate::new::common::posix::pthread::{
1227
pthread_attr_getguardsize,
1328
pthread_attr_getinheritsched,
1429
pthread_attr_getschedparam,
@@ -23,7 +38,6 @@ pub use crate::new::common::posix::pthread::{
2338
pthread_barrier_init,
2439
pthread_barrier_wait,
2540
pthread_barrierattr_destroy,
26-
pthread_barrierattr_getpshared,
2741
pthread_barrierattr_init,
2842
pthread_barrierattr_setpshared,
2943
pthread_cancel,
@@ -32,22 +46,15 @@ pub use crate::new::common::posix::pthread::{
3246
pthread_condattr_setclock,
3347
pthread_condattr_setpshared,
3448
pthread_create,
35-
pthread_getcpuclockid,
3649
pthread_getschedparam,
3750
pthread_kill,
38-
pthread_mutex_consistent,
3951
pthread_mutex_timedlock,
40-
pthread_mutexattr_getprotocol,
4152
pthread_mutexattr_getpshared,
42-
pthread_mutexattr_getrobust,
43-
pthread_mutexattr_setprotocol,
4453
pthread_mutexattr_setpshared,
45-
pthread_mutexattr_setrobust,
4654
pthread_once,
4755
pthread_rwlockattr_getpshared,
4856
pthread_rwlockattr_setpshared,
4957
pthread_setschedparam,
50-
pthread_setschedprio,
5158
pthread_sigmask,
5259
pthread_spin_destroy,
5360
pthread_spin_init,

0 commit comments

Comments
 (0)