Skip to content

Commit af48b1e

Browse files
committed
support gettid on macos
1 parent d810c10 commit af48b1e

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
66
## [Unreleased]
77

88
### Added
9+
- Added `nix::sys::pthread::test_pthread_self`
10+
([#591](https://github.com/nix-rust/nix/pull/591)
911
- Added `AioCb::from_boxed_slice`
1012
([#582](https://github.com/nix-rust/nix/pull/582)
1113
- Added `nix::unistd::{openat, fstatat, readlink, readlinkat}`

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, pthread_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() -> pthread_t {
11+
unsafe { libc::pthread_self() }
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)