Skip to content

Commit 0a8373a

Browse files
committed
support gettid on macos
1 parent 7b5dd78 commit 0a8373a

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

src/sys/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,6 @@ pub mod statfs;
8484
target_arch = "arm")),
8585
)]
8686
pub mod statvfs;
87+
88+
#[cfg(unix)]
89+
pub mod pthread;

src/sys/pthread.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use libc::{self, pid_t};
2+
3+
4+
/// Obtain ID of the calling thread (see
5+
/// [pthread_self(3)](http://man7.org/linux/man-pages/man3/pthread_self.3.html)
6+
///
7+
/// The thread ID returned by pthread_self() is not the same thing as
8+
/// the kernel thread ID returned by a call to gettid(2).
9+
#[inline]
10+
pub fn pthread_self() -> pid_t {
11+
unsafe { libc::pthread_self() as pid_t }
12+
}

test/sys/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ mod test_uio;
1212

1313
#[cfg(target_os = "linux")]
1414
mod test_epoll;
15+
#[cfg(unix)]
16+
mod test_pthread;

test/sys/test_pthread.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use nix::sys::pthread::*;
2+
#[test]
3+
fn test_pthread_self() {
4+
let tid = pthread_self();
5+
assert!(tid > 0);
6+
}

0 commit comments

Comments
 (0)