Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pthread_self #591

Merged
merged 1 commit into from
Jun 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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::*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an empty line below this one.


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