Skip to content

Commit

Permalink
Merge #591
Browse files Browse the repository at this point in the history
591: Add pthread_self r=asomers
  • Loading branch information
bors[bot] committed Jun 5, 2017
2 parents 64ac43a + 445c247 commit 3be3e70
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added
- Added `sys::signal::SigAction::{ flags, mask, handler}`
([#611](https://github.com/nix-rust/nix/pull/609)
- Added `nix::sys::pthread::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
1 change: 1 addition & 0 deletions src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ pub mod statfs;
target_arch = "arm")),
)]
pub mod statvfs;
pub mod pthread;
13 changes: 13 additions & 0 deletions src/sys/pthread.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use libc::{self, pthread_t};

pub type Pthread = 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 {
unsafe { libc::pthread_self() }
}
1 change: 1 addition & 0 deletions test/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ mod test_uio;

#[cfg(target_os = "linux")]
mod test_epoll;
mod test_pthread;
7 changes: 7 additions & 0 deletions test/sys/test_pthread.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use nix::sys::pthread::*;

#[test]
fn test_pthread_self() {
let tid = pthread_self();
assert!(tid > 0);
}

0 comments on commit 3be3e70

Please sign in to comment.