Skip to content

Commit af044aa

Browse files
committed
android: Move android-specific pthread bits to the new module
1 parent 7b1449a commit af044aa

File tree

8 files changed

+64
-101
lines changed

8 files changed

+64
-101
lines changed

src/new/bionic_libc/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
//!
33
//! <https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/include/>
44
5+
pub(crate) mod pthread;
56
pub(crate) mod sys;
67
pub(crate) mod unistd;

src/new/bionic_libc/pthread.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//! Header: `unistd.h`
2+
3+
pub use crate::new::common::linux_like::pthread::pthread_setname_np;
4+
pub use crate::new::common::posix::pthread::{
5+
pthread_atfork,
6+
pthread_attr_getguardsize,
7+
pthread_attr_getinheritsched,
8+
pthread_attr_setguardsize,
9+
pthread_attr_setinheritsched,
10+
pthread_barrier_destroy,
11+
pthread_barrier_init,
12+
pthread_barrier_wait,
13+
pthread_barrierattr_destroy,
14+
pthread_barrierattr_getpshared,
15+
pthread_barrierattr_init,
16+
pthread_barrierattr_setpshared,
17+
pthread_condattr_getpshared,
18+
pthread_create,
19+
pthread_getcpuclockid,
20+
pthread_getschedparam,
21+
pthread_kill,
22+
pthread_mutex_timedlock,
23+
pthread_mutexattr_getpshared,
24+
pthread_setschedparam,
25+
pthread_sigmask,
26+
pthread_spin_destroy,
27+
pthread_spin_init,
28+
pthread_spin_lock,
29+
pthread_spin_trylock,
30+
pthread_spin_unlock,
31+
};

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(target_os = "linux")]
3+
#[cfg(any(target_os = "android", target_os = "linux"))]
44
pub(crate) mod pthread;

src/new/common/linux_like/pthread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ extern "C" {
1818
cpuset: *const crate::cpu_set_t,
1919
) -> c_int;
2020

21-
#[cfg(target_os = "linux")]
21+
#[cfg(any(target_os = "android", target_os = "linux"))]
2222
pub fn pthread_setname_np(thread: crate::pthread_t, name: *const c_char) -> c_int;
2323
}

src/new/common/posix/mod.rs

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

src/new/common/posix/pthread.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
use crate::prelude::*;
66

77
extern "C" {
8-
#[cfg(target_os = "linux")]
8+
#[cfg(any(target_os = "android", target_os = "linux"))]
99
pub fn pthread_atfork(
1010
prepare: Option<unsafe extern "C" fn()>,
1111
parent: Option<unsafe extern "C" fn()>,
1212
child: Option<unsafe extern "C" fn()>,
1313
) -> c_int;
1414

15-
#[cfg(target_os = "linux")]
15+
#[cfg(any(target_os = "android", 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(target_os = "linux")]
21+
#[cfg(any(target_os = "android", target_os = "linux"))]
2222
pub fn pthread_attr_getinheritsched(
2323
attr: *const crate::pthread_attr_t,
2424
inheritsched: *mut c_int,
@@ -36,10 +36,10 @@ extern "C" {
3636
policy: *mut c_int,
3737
) -> c_int;
3838

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

42-
#[cfg(target_os = "linux")]
42+
#[cfg(any(target_os = "android", target_os = "linux"))]
4343
pub fn pthread_attr_setinheritsched(
4444
attr: *mut crate::pthread_attr_t,
4545
inheritsched: c_int,
@@ -54,32 +54,32 @@ extern "C" {
5454
#[cfg(target_os = "linux")]
5555
pub fn pthread_attr_setschedpolicy(attr: *mut crate::pthread_attr_t, policy: c_int) -> c_int;
5656

57-
#[cfg(target_os = "linux")]
57+
#[cfg(any(target_os = "android", target_os = "linux"))]
5858
pub fn pthread_barrier_destroy(barrier: *mut crate::pthread_barrier_t) -> c_int;
5959

60-
#[cfg(target_os = "linux")]
60+
#[cfg(any(target_os = "android", target_os = "linux"))]
6161
pub fn pthread_barrier_init(
6262
barrier: *mut crate::pthread_barrier_t,
6363
attr: *const crate::pthread_barrierattr_t,
6464
count: c_uint,
6565
) -> c_int;
6666

67-
#[cfg(target_os = "linux")]
67+
#[cfg(any(target_os = "android", target_os = "linux"))]
6868
pub fn pthread_barrier_wait(barrier: *mut crate::pthread_barrier_t) -> c_int;
6969

70-
#[cfg(target_os = "linux")]
70+
#[cfg(any(target_os = "android", target_os = "linux"))]
7171
pub fn pthread_barrierattr_destroy(attr: *mut crate::pthread_barrierattr_t) -> c_int;
7272

73-
#[cfg(target_os = "linux")]
73+
#[cfg(any(target_os = "android", target_os = "linux"))]
7474
pub fn pthread_barrierattr_getpshared(
7575
attr: *const crate::pthread_barrierattr_t,
7676
shared: *mut c_int,
7777
) -> c_int;
7878

79-
#[cfg(target_os = "linux")]
79+
#[cfg(any(target_os = "android", target_os = "linux"))]
8080
pub fn pthread_barrierattr_init(attr: *mut crate::pthread_barrierattr_t) -> c_int;
8181

82-
#[cfg(target_os = "linux")]
82+
#[cfg(any(target_os = "android", target_os = "linux"))]
8383
pub fn pthread_barrierattr_setpshared(
8484
attr: *mut crate::pthread_barrierattr_t,
8585
shared: c_int,
@@ -88,24 +88,24 @@ extern "C" {
8888
#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
8989
pub fn pthread_cancel(thread: crate::pthread_t) -> c_int;
9090

91-
#[cfg(target_os = "linux")]
91+
#[cfg(any(target_os = "android", target_os = "linux"))]
9292
pub fn pthread_condattr_getpshared(
9393
attr: *const crate::pthread_condattr_t,
9494
pshared: *mut c_int,
9595
) -> c_int;
9696

97-
#[cfg(target_os = "linux")]
97+
#[cfg(any(target_os = "android", target_os = "linux"))]
9898
pub fn pthread_create(
9999
native: *mut crate::pthread_t,
100100
attr: *const crate::pthread_attr_t,
101101
f: extern "C" fn(*mut c_void) -> *mut c_void,
102102
value: *mut c_void,
103103
) -> c_int;
104104

105-
#[cfg(target_os = "linux")]
105+
#[cfg(any(target_os = "android", target_os = "linux"))]
106106
pub fn pthread_getcpuclockid(thread: crate::pthread_t, clk_id: *mut crate::clockid_t) -> c_int;
107107

108-
#[cfg(target_os = "linux")]
108+
#[cfg(any(target_os = "android", target_os = "linux"))]
109109
pub fn pthread_getschedparam(
110110
native: crate::pthread_t,
111111
policy: *mut c_int,
@@ -114,13 +114,13 @@ extern "C" {
114114

115115
// FIXME(reorg): In recent POSIX versions, this is a signal.h function and not required
116116
// in pthread.
117-
#[cfg(target_os = "linux")]
117+
#[cfg(any(target_os = "android", target_os = "linux"))]
118118
pub fn pthread_kill(thread: crate::pthread_t, sig: c_int) -> c_int;
119119

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

123-
#[cfg(target_os = "linux")]
123+
#[cfg(any(target_os = "android", target_os = "linux"))]
124124
#[cfg_attr(gnu_time_bits64, link_name = "__pthread_mutex_timedlock64")]
125125
pub fn pthread_mutex_timedlock(
126126
lock: *mut crate::pthread_mutex_t,
@@ -133,7 +133,7 @@ extern "C" {
133133
protocol: *mut c_int,
134134
) -> c_int;
135135

136-
#[cfg(target_os = "linux")]
136+
#[cfg(any(target_os = "android", target_os = "linux"))]
137137
pub fn pthread_mutexattr_getpshared(
138138
attr: *const crate::pthread_mutexattr_t,
139139
pshared: *mut c_int,
@@ -160,7 +160,7 @@ extern "C" {
160160
#[cfg(target_os = "linux")]
161161
pub fn pthread_once(control: *mut crate::pthread_once_t, routine: extern "C" fn()) -> c_int;
162162

163-
#[cfg(target_os = "linux")]
163+
#[cfg(any(target_os = "android", target_os = "linux"))]
164164
pub fn pthread_setschedparam(
165165
native: crate::pthread_t,
166166
policy: c_int,
@@ -172,25 +172,25 @@ extern "C" {
172172

173173
// FIXME(reorg): In recent POSIX versions, this is a signal.h function and not required
174174
// in pthread.
175-
#[cfg(target_os = "linux")]
175+
#[cfg(any(target_os = "android", target_os = "linux"))]
176176
pub fn pthread_sigmask(
177177
how: c_int,
178178
set: *const crate::sigset_t,
179179
oldset: *mut crate::sigset_t,
180180
) -> c_int;
181181

182-
#[cfg(target_os = "linux")]
182+
#[cfg(any(target_os = "android", target_os = "linux"))]
183183
pub fn pthread_spin_destroy(lock: *mut crate::pthread_spinlock_t) -> c_int;
184184

185-
#[cfg(target_os = "linux")]
185+
#[cfg(any(target_os = "android", target_os = "linux"))]
186186
pub fn pthread_spin_init(lock: *mut crate::pthread_spinlock_t, pshared: c_int) -> c_int;
187187

188-
#[cfg(target_os = "linux")]
188+
#[cfg(any(target_os = "android", target_os = "linux"))]
189189
pub fn pthread_spin_lock(lock: *mut crate::pthread_spinlock_t) -> c_int;
190190

191-
#[cfg(target_os = "linux")]
191+
#[cfg(any(target_os = "android", target_os = "linux"))]
192192
pub fn pthread_spin_trylock(lock: *mut crate::pthread_spinlock_t) -> c_int;
193193

194-
#[cfg(target_os = "linux")]
194+
#[cfg(any(target_os = "android", target_os = "linux"))]
195195
pub fn pthread_spin_unlock(lock: *mut crate::pthread_spinlock_t) -> c_int;
196196
}

src/new/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ cfg_if! {
207207
cfg_if! {
208208
if #[cfg(target_family = "unix")] {
209209
// FIXME(pthread): eventually all platforms should use this module
210-
#[cfg(target_os = "linux")]
210+
#[cfg(any(target_os = "android", target_os = "linux"))]
211211
pub use pthread::*;
212212
pub use unistd::*;
213213
}

src/unix/linux_like/android/mod.rs

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3508,11 +3508,6 @@ extern "C" {
35083508
timeout: c_int,
35093509
) -> c_int;
35103510
pub fn epoll_ctl(epfd: c_int, op: c_int, fd: c_int, event: *mut crate::epoll_event) -> c_int;
3511-
pub fn pthread_getschedparam(
3512-
native: crate::pthread_t,
3513-
policy: *mut c_int,
3514-
param: *mut crate::sched_param,
3515-
) -> c_int;
35163511
pub fn unshare(flags: c_int) -> c_int;
35173512
pub fn umount(target: *const c_char) -> c_int;
35183513
pub fn sched_get_priority_max(policy: c_int) -> c_int;
@@ -3553,32 +3548,7 @@ extern "C" {
35533548
timeout: *const crate::timespec,
35543549
sigmask: *const sigset_t,
35553550
) -> c_int;
3556-
pub fn pthread_mutex_timedlock(
3557-
lock: *mut pthread_mutex_t,
3558-
abstime: *const crate::timespec,
3559-
) -> c_int;
3560-
pub fn pthread_barrierattr_init(attr: *mut crate::pthread_barrierattr_t) -> c_int;
3561-
pub fn pthread_barrierattr_destroy(attr: *mut crate::pthread_barrierattr_t) -> c_int;
3562-
pub fn pthread_barrierattr_getpshared(
3563-
attr: *const crate::pthread_barrierattr_t,
3564-
shared: *mut c_int,
3565-
) -> c_int;
3566-
pub fn pthread_barrierattr_setpshared(
3567-
attr: *mut crate::pthread_barrierattr_t,
3568-
shared: c_int,
3569-
) -> c_int;
3570-
pub fn pthread_barrier_init(
3571-
barrier: *mut pthread_barrier_t,
3572-
attr: *const crate::pthread_barrierattr_t,
3573-
count: c_uint,
3574-
) -> c_int;
3575-
pub fn pthread_barrier_destroy(barrier: *mut pthread_barrier_t) -> c_int;
3576-
pub fn pthread_barrier_wait(barrier: *mut pthread_barrier_t) -> c_int;
3577-
pub fn pthread_spin_init(lock: *mut crate::pthread_spinlock_t, pshared: c_int) -> c_int;
3578-
pub fn pthread_spin_destroy(lock: *mut crate::pthread_spinlock_t) -> c_int;
3579-
pub fn pthread_spin_lock(lock: *mut crate::pthread_spinlock_t) -> c_int;
3580-
pub fn pthread_spin_trylock(lock: *mut crate::pthread_spinlock_t) -> c_int;
3581-
pub fn pthread_spin_unlock(lock: *mut crate::pthread_spinlock_t) -> c_int;
3551+
35823552
pub fn clone(
35833553
cb: extern "C" fn(*mut c_void) -> c_int,
35843554
child_stack: *mut c_void,
@@ -3593,29 +3563,11 @@ extern "C" {
35933563
rqtp: *const crate::timespec,
35943564
rmtp: *mut crate::timespec,
35953565
) -> c_int;
3596-
pub fn pthread_attr_getguardsize(
3597-
attr: *const crate::pthread_attr_t,
3598-
guardsize: *mut size_t,
3599-
) -> c_int;
3600-
pub fn pthread_attr_setguardsize(attr: *mut crate::pthread_attr_t, guardsize: size_t) -> c_int;
3601-
pub fn pthread_attr_getinheritsched(
3602-
attr: *const crate::pthread_attr_t,
3603-
flag: *mut c_int,
3604-
) -> c_int;
3605-
pub fn pthread_attr_setinheritsched(attr: *mut crate::pthread_attr_t, flag: c_int) -> c_int;
3566+
36063567
pub fn sethostname(name: *const c_char, len: size_t) -> c_int;
36073568
pub fn sched_get_priority_min(policy: c_int) -> c_int;
3608-
pub fn pthread_condattr_getpshared(
3609-
attr: *const pthread_condattr_t,
3610-
pshared: *mut c_int,
3611-
) -> c_int;
36123569
pub fn sysinfo(info: *mut crate::sysinfo) -> c_int;
36133570
pub fn umount2(target: *const c_char, flags: c_int) -> c_int;
3614-
pub fn pthread_setschedparam(
3615-
native: crate::pthread_t,
3616-
policy: c_int,
3617-
param: *const crate::sched_param,
3618-
) -> c_int;
36193571
pub fn swapon(path: *const c_char, swapflags: c_int) -> c_int;
36203572
pub fn sched_setscheduler(
36213573
pid: crate::pid_t,
@@ -3643,10 +3595,8 @@ extern "C" {
36433595
buflen: size_t,
36443596
result: *mut *mut crate::group,
36453597
) -> c_int;
3646-
pub fn pthread_sigmask(how: c_int, set: *const sigset_t, oldset: *mut sigset_t) -> c_int;
36473598
pub fn sem_open(name: *const c_char, oflag: c_int, ...) -> *mut sem_t;
36483599
pub fn getgrnam(name: *const c_char) -> *mut crate::group;
3649-
pub fn pthread_kill(thread: crate::pthread_t, sig: c_int) -> c_int;
36503600
pub fn sem_unlink(name: *const c_char) -> c_int;
36513601
pub fn daemon(nochdir: c_int, noclose: c_int) -> c_int;
36523602
pub fn getpwnam_r(
@@ -3669,11 +3619,6 @@ extern "C" {
36693619
timeout: *const crate::timespec,
36703620
) -> c_int;
36713621
pub fn sigwait(set: *const sigset_t, sig: *mut c_int) -> c_int;
3672-
pub fn pthread_atfork(
3673-
prepare: Option<unsafe extern "C" fn()>,
3674-
parent: Option<unsafe extern "C" fn()>,
3675-
child: Option<unsafe extern "C" fn()>,
3676-
) -> c_int;
36773622
pub fn getgrgid(gid: crate::gid_t) -> *mut crate::group;
36783623
pub fn getgrouplist(
36793624
user: *const c_char,
@@ -3682,18 +3627,8 @@ extern "C" {
36823627
ngroups: *mut c_int,
36833628
) -> c_int;
36843629
pub fn initgroups(user: *const c_char, group: crate::gid_t) -> c_int;
3685-
pub fn pthread_mutexattr_getpshared(
3686-
attr: *const pthread_mutexattr_t,
3687-
pshared: *mut c_int,
3688-
) -> c_int;
36893630
pub fn popen(command: *const c_char, mode: *const c_char) -> *mut crate::FILE;
36903631
pub fn faccessat(dirfd: c_int, pathname: *const c_char, mode: c_int, flags: c_int) -> c_int;
3691-
pub fn pthread_create(
3692-
native: *mut crate::pthread_t,
3693-
attr: *const crate::pthread_attr_t,
3694-
f: extern "C" fn(*mut c_void) -> *mut c_void,
3695-
value: *mut c_void,
3696-
) -> c_int;
36973632
pub fn __errno() -> *mut c_int;
36983633
pub fn inotify_rm_watch(fd: c_int, wd: u32) -> c_int;
36993634
pub fn inotify_init() -> c_int;
@@ -3729,8 +3664,6 @@ extern "C" {
37293664
pub fn getrandom(buf: *mut c_void, buflen: size_t, flags: c_uint) -> ssize_t;
37303665
pub fn getentropy(buf: *mut c_void, buflen: size_t) -> c_int;
37313666

3732-
pub fn pthread_setname_np(thread: crate::pthread_t, name: *const c_char) -> c_int;
3733-
37343667
pub fn __system_property_set(__name: *const c_char, __value: *const c_char) -> c_int;
37353668
pub fn __system_property_get(__name: *const c_char, __value: *mut c_char) -> c_int;
37363669
pub fn __system_property_find(__name: *const c_char) -> *const prop_info;
@@ -3755,8 +3688,6 @@ extern "C" {
37553688

37563689
pub fn reallocarray(ptr: *mut c_void, nmemb: size_t, size: size_t) -> *mut c_void;
37573690

3758-
pub fn pthread_getcpuclockid(thread: crate::pthread_t, clk_id: *mut crate::clockid_t) -> c_int;
3759-
37603691
pub fn dirname(path: *const c_char) -> *mut c_char;
37613692
pub fn basename(path: *const c_char) -> *mut c_char;
37623693
pub fn getopt_long(

0 commit comments

Comments
 (0)