Skip to content

Commit e14b27e

Browse files
committed
linux-like: Move pthread API in to the new module
1 parent 8c4abbe commit e14b27e

File tree

9 files changed

+143
-29
lines changed

9 files changed

+143
-29
lines changed

src/new/bionic_libc/pthread.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
11
//! Header: `unistd.h`
22
3-
pub use crate::new::common::linux_like::pthread::pthread_setname_np;
3+
pub use crate::new::common::linux_like::pthread::{
4+
pthread_getattr_np,
5+
pthread_setname_np,
6+
};
47
pub use crate::new::common::posix::pthread::{
58
pthread_atfork,
69
pthread_attr_getguardsize,
710
pthread_attr_getinheritsched,
11+
pthread_attr_getstack,
812
pthread_attr_setguardsize,
913
pthread_attr_setinheritsched,
14+
pthread_attr_setstack,
1015
pthread_barrier_destroy,
1116
pthread_barrier_init,
1217
pthread_barrier_wait,
1318
pthread_barrierattr_destroy,
1419
pthread_barrierattr_getpshared,
1520
pthread_barrierattr_init,
1621
pthread_barrierattr_setpshared,
22+
pthread_condattr_getclock,
1723
pthread_condattr_getpshared,
24+
pthread_condattr_setclock,
25+
pthread_condattr_setpshared,
1826
pthread_create,
1927
pthread_getcpuclockid,
2028
pthread_getschedparam,
2129
pthread_kill,
2230
pthread_mutex_timedlock,
2331
pthread_mutexattr_getpshared,
32+
pthread_mutexattr_setpshared,
33+
pthread_rwlockattr_getpshared,
34+
pthread_rwlockattr_setpshared,
2435
pthread_setschedparam,
2536
pthread_sigmask,
2637
pthread_spin_destroy,

src/new/common/linux_like/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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 = "linux"))]
3+
#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))]
44
pub(crate) mod pthread;

src/new/common/linux_like/pthread.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ extern "C" {
88
cpuset: *mut crate::cpu_set_t,
99
) -> c_int;
1010

11+
pub fn pthread_getattr_np(native: crate::pthread_t, attr: *mut crate::pthread_attr_t) -> c_int;
12+
1113
#[cfg(target_os = "linux")]
1214
pub fn pthread_getname_np(thread: crate::pthread_t, name: *mut c_char, len: size_t) -> c_int;
1315

src/new/common/posix/pthread.rs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ extern "C" {
3636
policy: *mut c_int,
3737
) -> c_int;
3838

39+
#[cfg(any(
40+
target_os = "android",
41+
target_os = "emscripten",
42+
target_os = "linux",
43+
target_os = "l4re"
44+
))]
45+
pub fn pthread_attr_getstack(
46+
attr: *const crate::pthread_attr_t,
47+
stackaddr: *mut *mut c_void,
48+
stacksize: *mut size_t,
49+
) -> c_int;
50+
3951
#[cfg(any(target_os = "android", target_os = "linux"))]
4052
pub fn pthread_attr_setguardsize(attr: *mut crate::pthread_attr_t, guardsize: size_t) -> c_int;
4153

@@ -54,6 +66,18 @@ extern "C" {
5466
#[cfg(target_os = "linux")]
5567
pub fn pthread_attr_setschedpolicy(attr: *mut crate::pthread_attr_t, policy: c_int) -> c_int;
5668

69+
#[cfg(any(
70+
target_os = "android",
71+
target_os = "emscripten",
72+
target_os = "linux",
73+
target_os = "l4re"
74+
))]
75+
pub fn pthread_attr_setstack(
76+
attr: *mut crate::pthread_attr_t,
77+
stackaddr: *mut c_void,
78+
stacksize: size_t,
79+
) -> c_int;
80+
5781
#[cfg(any(target_os = "android", target_os = "linux"))]
5882
pub fn pthread_barrier_destroy(barrier: *mut crate::pthread_barrier_t) -> c_int;
5983

@@ -88,12 +112,45 @@ extern "C" {
88112
#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
89113
pub fn pthread_cancel(thread: crate::pthread_t) -> c_int;
90114

115+
#[cfg(any(
116+
target_os = "android",
117+
target_os = "emscripten",
118+
target_os = "linux",
119+
target_os = "l4re"
120+
))]
121+
pub fn pthread_condattr_getclock(
122+
attr: *const crate::pthread_condattr_t,
123+
clock_id: *mut crate::clockid_t,
124+
) -> c_int;
125+
91126
#[cfg(any(target_os = "android", target_os = "linux"))]
92127
pub fn pthread_condattr_getpshared(
93128
attr: *const crate::pthread_condattr_t,
94129
pshared: *mut c_int,
95130
) -> c_int;
96131

132+
#[cfg(any(
133+
target_os = "android",
134+
target_os = "emscripten",
135+
target_os = "linux",
136+
target_os = "l4re"
137+
))]
138+
pub fn pthread_condattr_setclock(
139+
attr: *mut crate::pthread_condattr_t,
140+
clock_id: crate::clockid_t,
141+
) -> c_int;
142+
143+
#[cfg(any(
144+
target_os = "android",
145+
target_os = "emscripten",
146+
target_os = "linux",
147+
target_os = "l4re"
148+
))]
149+
pub fn pthread_condattr_setpshared(
150+
attr: *mut crate::pthread_condattr_t,
151+
pshared: c_int,
152+
) -> c_int;
153+
97154
#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))]
98155
pub fn pthread_create(
99156
native: *mut crate::pthread_t,
@@ -151,12 +208,45 @@ extern "C" {
151208
protocol: c_int,
152209
) -> c_int;
153210

211+
#[cfg(any(
212+
target_os = "android",
213+
target_os = "emscripten",
214+
target_os = "linux",
215+
target_os = "l4re"
216+
))]
217+
pub fn pthread_mutexattr_setpshared(
218+
attr: *mut crate::pthread_mutexattr_t,
219+
pshared: c_int,
220+
) -> c_int;
221+
154222
#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
155223
pub fn pthread_mutexattr_setrobust(
156224
attr: *mut crate::pthread_mutexattr_t,
157225
robustness: c_int,
158226
) -> c_int;
159227

228+
#[cfg(any(
229+
target_os = "android",
230+
target_os = "emscripten",
231+
target_os = "linux",
232+
target_os = "l4re"
233+
))]
234+
pub fn pthread_rwlockattr_getpshared(
235+
attr: *const crate::pthread_rwlockattr_t,
236+
val: *mut c_int,
237+
) -> c_int;
238+
239+
#[cfg(any(
240+
target_os = "android",
241+
target_os = "emscripten",
242+
target_os = "linux",
243+
target_os = "l4re"
244+
))]
245+
pub fn pthread_rwlockattr_setpshared(
246+
attr: *mut crate::pthread_rwlockattr_t,
247+
val: c_int,
248+
) -> c_int;
249+
160250
#[cfg(target_os = "linux")]
161251
pub fn pthread_once(control: *mut crate::pthread_once_t, routine: extern "C" fn()) -> c_int;
162252

src/new/emscripten/pthread.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
//! Header: `pthread.h`
22
3-
pub use crate::new::common::posix::pthread::pthread_create;
3+
pub use crate::new::common::linux_like::pthread::pthread_getattr_np;
4+
pub use crate::new::common::posix::pthread::{
5+
pthread_attr_getstack,
6+
pthread_attr_setstack,
7+
pthread_condattr_getclock,
8+
pthread_condattr_setclock,
9+
pthread_condattr_setpshared,
10+
pthread_create,
11+
pthread_rwlockattr_setpshared,
12+
};

src/new/glibc/sysdeps/nptl/pthread.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
pub use crate::new::common::linux_like::pthread::{
66
pthread_getaffinity_np,
7+
pthread_getattr_np,
78
pthread_getname_np,
89
pthread_setaffinity_np,
910
pthread_setname_np,
@@ -14,10 +15,12 @@ pub use crate::new::common::posix::pthread::{
1415
pthread_attr_getinheritsched,
1516
pthread_attr_getschedparam,
1617
pthread_attr_getschedpolicy,
18+
pthread_attr_getstack,
1719
pthread_attr_setguardsize,
1820
pthread_attr_setinheritsched,
1921
pthread_attr_setschedparam,
2022
pthread_attr_setschedpolicy,
23+
pthread_attr_setstack,
2124
pthread_barrier_destroy,
2225
pthread_barrier_init,
2326
pthread_barrier_wait,
@@ -26,7 +29,10 @@ pub use crate::new::common::posix::pthread::{
2629
pthread_barrierattr_init,
2730
pthread_barrierattr_setpshared,
2831
pthread_cancel,
32+
pthread_condattr_getclock,
2933
pthread_condattr_getpshared,
34+
pthread_condattr_setclock,
35+
pthread_condattr_setpshared,
3036
pthread_create,
3137
pthread_getcpuclockid,
3238
pthread_getschedparam,
@@ -37,8 +43,11 @@ pub use crate::new::common::posix::pthread::{
3743
pthread_mutexattr_getpshared,
3844
pthread_mutexattr_getrobust,
3945
pthread_mutexattr_setprotocol,
46+
pthread_mutexattr_setpshared,
4047
pthread_mutexattr_setrobust,
4148
pthread_once,
49+
pthread_rwlockattr_getpshared,
50+
pthread_rwlockattr_setpshared,
4251
pthread_setschedparam,
4352
pthread_setschedprio,
4453
pthread_sigmask,

src/new/musl/pthread.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
pub use crate::new::common::linux_like::pthread::{
66
pthread_getaffinity_np,
7+
pthread_getattr_np,
78
pthread_getname_np,
89
pthread_setaffinity_np,
910
pthread_setname_np,
@@ -14,18 +15,23 @@ pub use crate::new::common::posix::pthread::{
1415
pthread_attr_getinheritsched,
1516
pthread_attr_getschedparam,
1617
pthread_attr_getschedpolicy,
18+
pthread_attr_getstack,
1719
pthread_attr_setguardsize,
1820
pthread_attr_setinheritsched,
1921
pthread_attr_setschedparam,
2022
pthread_attr_setschedpolicy,
23+
pthread_attr_setstack,
2124
pthread_barrier_destroy,
2225
pthread_barrier_init,
2326
pthread_barrier_wait,
2427
pthread_barrierattr_destroy,
2528
pthread_barrierattr_getpshared,
2629
pthread_barrierattr_init,
2730
pthread_barrierattr_setpshared,
31+
pthread_condattr_getclock,
2832
pthread_condattr_getpshared,
33+
pthread_condattr_setclock,
34+
pthread_condattr_setpshared,
2935
pthread_create,
3036
pthread_getcpuclockid,
3137
pthread_getschedparam,
@@ -34,7 +40,10 @@ pub use crate::new::common::posix::pthread::{
3440
pthread_mutexattr_getprotocol,
3541
pthread_mutexattr_getpshared,
3642
pthread_mutexattr_setprotocol,
43+
pthread_mutexattr_setpshared,
3744
pthread_once,
45+
pthread_rwlockattr_getpshared,
46+
pthread_rwlockattr_setpshared,
3847
pthread_setschedparam,
3948
pthread_setschedprio,
4049
pthread_sigmask,

src/new/uclibc/pthread.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
pub use crate::new::common::linux_like::pthread::{
44
pthread_getaffinity_np,
5+
pthread_getattr_np,
56
pthread_getname_np,
67
pthread_setaffinity_np,
78
pthread_setname_np,
@@ -12,10 +13,12 @@ pub use crate::new::common::posix::pthread::{
1213
pthread_attr_getinheritsched,
1314
pthread_attr_getschedparam,
1415
pthread_attr_getschedpolicy,
16+
pthread_attr_getstack,
1517
pthread_attr_setguardsize,
1618
pthread_attr_setinheritsched,
1719
pthread_attr_setschedparam,
1820
pthread_attr_setschedpolicy,
21+
pthread_attr_setstack,
1922
pthread_barrier_destroy,
2023
pthread_barrier_init,
2124
pthread_barrier_wait,
@@ -24,7 +27,10 @@ pub use crate::new::common::posix::pthread::{
2427
pthread_barrierattr_init,
2528
pthread_barrierattr_setpshared,
2629
pthread_cancel,
30+
pthread_condattr_getclock,
2731
pthread_condattr_getpshared,
32+
pthread_condattr_setclock,
33+
pthread_condattr_setpshared,
2834
pthread_create,
2935
pthread_getcpuclockid,
3036
pthread_getschedparam,
@@ -35,8 +41,11 @@ pub use crate::new::common::posix::pthread::{
3541
pthread_mutexattr_getpshared,
3642
pthread_mutexattr_getrobust,
3743
pthread_mutexattr_setprotocol,
44+
pthread_mutexattr_setpshared,
3845
pthread_mutexattr_setrobust,
3946
pthread_once,
47+
pthread_rwlockattr_getpshared,
48+
pthread_rwlockattr_setpshared,
4049
pthread_setschedparam,
4150
pthread_setschedprio,
4251
pthread_sigmask,

src/unix/linux_like/mod.rs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,17 +1880,6 @@ extern "C" {
18801880

18811881
pub fn dirfd(dirp: *mut crate::DIR) -> c_int;
18821882

1883-
pub fn pthread_getattr_np(native: crate::pthread_t, attr: *mut crate::pthread_attr_t) -> c_int;
1884-
pub fn pthread_attr_getstack(
1885-
attr: *const crate::pthread_attr_t,
1886-
stackaddr: *mut *mut c_void,
1887-
stacksize: *mut size_t,
1888-
) -> c_int;
1889-
pub fn pthread_attr_setstack(
1890-
attr: *mut crate::pthread_attr_t,
1891-
stackaddr: *mut c_void,
1892-
stacksize: size_t,
1893-
) -> c_int;
18941883
pub fn memalign(align: size_t, size: size_t) -> *mut c_void;
18951884
pub fn setgroups(ngroups: size_t, ptr: *const crate::gid_t) -> c_int;
18961885
pub fn pipe2(fds: *mut c_int, flags: c_int) -> c_int;
@@ -1915,21 +1904,7 @@ extern "C" {
19151904
pub fn newlocale(mask: c_int, locale: *const c_char, base: crate::locale_t) -> crate::locale_t;
19161905
pub fn uselocale(loc: crate::locale_t) -> crate::locale_t;
19171906
pub fn mknodat(dirfd: c_int, pathname: *const c_char, mode: mode_t, dev: dev_t) -> c_int;
1918-
pub fn pthread_condattr_getclock(
1919-
attr: *const pthread_condattr_t,
1920-
clock_id: *mut clockid_t,
1921-
) -> c_int;
1922-
pub fn pthread_condattr_setclock(
1923-
attr: *mut pthread_condattr_t,
1924-
clock_id: crate::clockid_t,
1925-
) -> c_int;
1926-
pub fn pthread_condattr_setpshared(attr: *mut pthread_condattr_t, pshared: c_int) -> c_int;
1927-
pub fn pthread_mutexattr_setpshared(attr: *mut pthread_mutexattr_t, pshared: c_int) -> c_int;
1928-
pub fn pthread_rwlockattr_getpshared(
1929-
attr: *const pthread_rwlockattr_t,
1930-
val: *mut c_int,
1931-
) -> c_int;
1932-
pub fn pthread_rwlockattr_setpshared(attr: *mut pthread_rwlockattr_t, val: c_int) -> c_int;
1907+
19331908
pub fn ptsname_r(fd: c_int, buf: *mut c_char, buflen: size_t) -> c_int;
19341909
pub fn clearenv() -> c_int;
19351910
pub fn waitid(

0 commit comments

Comments
 (0)