Skip to content

Commit

Permalink
support gettid on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
king6cong committed Apr 21, 2017
1 parent d810c10 commit af48b1e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

### Added
- Added `nix::sys::pthread::test_pthread_self`
([#591](https://github.com/nix-rust/nix/pull/591)
- Added `AioCb::from_boxed_slice`
([#582](https://github.com/nix-rust/nix/pull/582)
- Added `nix::unistd::{openat, fstatat, readlink, readlinkat}`
Expand Down
3 changes: 3 additions & 0 deletions src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,6 @@ pub mod statfs;
target_arch = "arm")),
)]
pub mod statvfs;

#[cfg(unix)]
pub mod pthread;
12 changes: 12 additions & 0 deletions src/sys/pthread.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use libc::{self, pthread_t};


/// Obtain ID of the calling thread (see
/// [pthread_self(3)](http://man7.org/linux/man-pages/man3/pthread_self.3.html)
///
/// The thread ID returned by pthread_self() is not the same thing as
/// the kernel thread ID returned by a call to gettid(2).
#[inline]
pub fn pthread_self() -> pthread_t {
unsafe { libc::pthread_self() }
}
2 changes: 2 additions & 0 deletions test/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ mod test_uio;

#[cfg(target_os = "linux")]
mod test_epoll;
#[cfg(unix)]
mod test_pthread;
6 changes: 6 additions & 0 deletions test/sys/test_pthread.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use nix::sys::pthread::*;
#[test]
fn test_pthread_self() {
let tid = pthread_self();
assert!(tid > 0);
}

0 comments on commit af48b1e

Please sign in to comment.