Skip to content

Commit 004406b

Browse files
committed
linux/android adding pthread_spin_lock api
closes #2229
1 parent b456f76 commit 004406b

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

libc-test/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,6 +2600,8 @@ fn test_linux(target: &str) {
26002600
// (`c_uint`) and this clashes with the type of the `rlimit` APIs
26012601
// which expect a `c_int` even though both are ABI compatible.
26022602
"__rlimit_resource_t" => true,
2603+
// on Linux, this is a volatile int
2604+
"pthread_spinlock_t" => true,
26032605

26042606
_ => false,
26052607
}

src/unix/linux_like/android/b32/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ s! {
120120
__reserved: [::c_char; 12],
121121
}
122122

123+
pub struct pthread_spinlock_t {
124+
__private: [i32; 2],
125+
}
126+
123127
pub struct passwd {
124128
pub pw_name: *mut ::c_char,
125129
pub pw_passwd: *mut ::c_char,

src/unix/linux_like/android/b64/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ s! {
105105
pub f_namemax: ::c_ulong,
106106
__f_spare: [::c_int; 6],
107107
}
108+
109+
pub struct pthread_spinlock_t {
110+
__private: i64,
111+
}
108112
}
109113

110114
s_no_extra_traits! {

src/unix/linux_like/android/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2677,6 +2677,11 @@ extern "C" {
26772677
lock: *mut pthread_mutex_t,
26782678
abstime: *const ::timespec,
26792679
) -> ::c_int;
2680+
pub fn pthread_spin_init(lock: *mut ::pthread_spinlock_t, pshared: ::c_int) -> ::c_int;
2681+
pub fn pthread_spin_destroy(lock: *mut ::pthread_spinlock_t) -> ::c_int;
2682+
pub fn pthread_spin_lock(lock: *mut ::pthread_spinlock_t) -> ::c_int;
2683+
pub fn pthread_spin_trylock(lock: *mut ::pthread_spinlock_t) -> ::c_int;
2684+
pub fn pthread_spin_unlock(lock: *mut ::pthread_spinlock_t) -> ::c_int;
26802685
pub fn clone(
26812686
cb: extern "C" fn(*mut ::c_void) -> ::c_int,
26822687
child_stack: *mut ::c_void,

src/unix/linux_like/linux/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub type nl_item = ::c_int;
1414
pub type idtype_t = ::c_uint;
1515
pub type loff_t = ::c_longlong;
1616
pub type pthread_key_t = ::c_uint;
17+
pub type pthread_spinlock_t = ::c_int;
1718

1819
pub type __u8 = ::c_uchar;
1920
pub type __u16 = ::c_ushort;
@@ -3557,6 +3558,11 @@ extern "C" {
35573558
lock: *mut pthread_mutex_t,
35583559
abstime: *const ::timespec,
35593560
) -> ::c_int;
3561+
pub fn pthread_spin_init(lock: *mut ::pthread_spinlock_t, pshared: ::c_int) -> ::c_int;
3562+
pub fn pthread_spin_destroy(lock: *mut ::pthread_spinlock_t) -> ::c_int;
3563+
pub fn pthread_spin_lock(lock: *mut ::pthread_spinlock_t) -> ::c_int;
3564+
pub fn pthread_spin_trylock(lock: *mut ::pthread_spinlock_t) -> ::c_int;
3565+
pub fn pthread_spin_unlock(lock: *mut ::pthread_spinlock_t) -> ::c_int;
35603566
pub fn clone(
35613567
cb: extern "C" fn(*mut ::c_void) -> ::c_int,
35623568
child_stack: *mut ::c_void,

0 commit comments

Comments
 (0)