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 19, 2017
1 parent 7b5dd78 commit 0a8373a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
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, pid_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() -> pid_t {
unsafe { libc::pthread_self() as pid_t }
}
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 0a8373a

Please sign in to comment.