summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/sys/mod.rs1
-rw-r--r--src/sys/pthread.rs13
-rw-r--r--test/sys/mod.rs1
-rw-r--r--test/sys/test_pthread.rs7
5 files changed, 24 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 60965d1e..9209f0bc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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}`
diff --git a/src/sys/mod.rs b/src/sys/mod.rs
index 7675f944..69632f00 100644
--- a/src/sys/mod.rs
+++ b/src/sys/mod.rs
@@ -84,3 +84,4 @@ pub mod statfs;
target_arch = "arm")),
)]
pub mod statvfs;
+pub mod pthread;
diff --git a/src/sys/pthread.rs b/src/sys/pthread.rs
new file mode 100644
index 00000000..83b4669a
--- /dev/null
+++ b/src/sys/pthread.rs
@@ -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() }
+}
diff --git a/test/sys/mod.rs b/test/sys/mod.rs
index 5e5eed41..e93b0d28 100644
--- a/test/sys/mod.rs
+++ b/test/sys/mod.rs
@@ -12,3 +12,4 @@ mod test_uio;
#[cfg(target_os = "linux")]
mod test_epoll;
+mod test_pthread;
diff --git a/test/sys/test_pthread.rs b/test/sys/test_pthread.rs
new file mode 100644
index 00000000..092a95aa
--- /dev/null
+++ b/test/sys/test_pthread.rs
@@ -0,0 +1,7 @@
+use nix::sys::pthread::*;
+
+#[test]
+fn test_pthread_self() {
+ let tid = pthread_self();
+ assert!(tid > 0);
+}