Skip to content

Commit 599ae1b

Browse files
committed
Auto merge of #2245 - devnexen:pthread_spinlock_fbsd, r=JohnTitor
freebsd adding pthread_spinlock api
2 parents 5971b53 + e8e75a8 commit 599ae1b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

libc-test/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,6 +2002,9 @@ fn test_freebsd(target: &str) {
20022002
// not available until FreeBSD 12, and is an anonymous union there.
20032003
("xucred", "cr_pid__c_anonymous_union") => true,
20042004

2005+
// m_owner field is a volatile __lwpid_t
2006+
("umutex", "m_owner") => true,
2007+
20052008
_ => false,
20062009
}
20072010
});

src/unix/bsd/freebsdlike/freebsd/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub type mqd_t = *mut ::c_void;
2121
pub type posix_spawnattr_t = *mut ::c_void;
2222
pub type posix_spawn_file_actions_t = *mut ::c_void;
2323

24+
pub type pthread_spinlock_t = *mut __c_anonymous_pthread_spinlock;
25+
2426
s! {
2527
pub struct aiocb {
2628
pub aio_fildes: ::c_int,
@@ -140,6 +142,21 @@ s! {
140142
pub struct cap_rights_t {
141143
cr_rights: [u64; 2],
142144
}
145+
146+
pub struct umutex {
147+
m_owner: ::lwpid_t,
148+
m_flags: u32,
149+
m_ceilings: [u32; 2],
150+
m_rb_link: ::uintptr_t,
151+
#[cfg(target_pointer_width = "32")]
152+
m_pad: u32,
153+
m_spare: [u32; 2],
154+
155+
}
156+
157+
pub struct __c_anonymous_pthread_spinlock {
158+
s_clock: umutex,
159+
}
143160
}
144161

145162
s_no_extra_traits! {
@@ -1588,6 +1605,12 @@ extern "C" {
15881605
cpusetp: *const cpuset_t,
15891606
) -> ::c_int;
15901607

1608+
pub fn pthread_spin_init(lock: *mut pthread_spinlock_t, pshared: ::c_int) -> ::c_int;
1609+
pub fn pthread_spin_destroy(lock: *mut pthread_spinlock_t) -> ::c_int;
1610+
pub fn pthread_spin_lock(lock: *mut pthread_spinlock_t) -> ::c_int;
1611+
pub fn pthread_spin_trylock(lock: *mut pthread_spinlock_t) -> ::c_int;
1612+
pub fn pthread_spin_unlock(lock: *mut pthread_spinlock_t) -> ::c_int;
1613+
15911614
#[cfg_attr(all(target_os = "freebsd", freebsd11), link_name = "statfs@FBSD_1.0")]
15921615
pub fn statfs(path: *const ::c_char, buf: *mut statfs) -> ::c_int;
15931616
#[cfg_attr(all(target_os = "freebsd", freebsd11), link_name = "fstatfs@FBSD_1.0")]

0 commit comments

Comments
 (0)