Skip to content

Commit 445c247

Browse files
committed
Add pthread_self
1 parent 64ac43a commit 445c247

File tree

5 files changed

+24
-0
lines changed

5 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
88
### Added
99
- Added `sys::signal::SigAction::{ flags, mask, handler}`
1010
([#611](https://github.com/nix-rust/nix/pull/609)
11+
- Added `nix::sys::pthread::pthread_self`
12+
([#591](https://github.com/nix-rust/nix/pull/591)
1113
- Added `AioCb::from_boxed_slice`
1214
([#582](https://github.com/nix-rust/nix/pull/582)
1315
- Added `nix::unistd::{openat, fstatat, readlink, readlinkat}`

src/sys/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,4 @@ pub mod statfs;
8484
target_arch = "arm")),
8585
)]
8686
pub mod statvfs;
87+
pub mod pthread;

src/sys/pthread.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use libc::{self, pthread_t};
2+
3+
pub type Pthread = pthread_t;
4+
5+
/// Obtain ID of the calling thread (see
6+
/// [pthread_self(3)](http://man7.org/linux/man-pages/man3/pthread_self.3.html)
7+
///
8+
/// The thread ID returned by pthread_self() is not the same thing as
9+
/// the kernel thread ID returned by a call to gettid(2).
10+
#[inline]
11+
pub fn pthread_self() -> Pthread {
12+
unsafe { libc::pthread_self() }
13+
}

test/sys/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ mod test_uio;
1212

1313
#[cfg(target_os = "linux")]
1414
mod test_epoll;
15+
mod test_pthread;

test/sys/test_pthread.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use nix::sys::pthread::*;
2+
3+
#[test]
4+
fn test_pthread_self() {
5+
let tid = pthread_self();
6+
assert!(tid > 0);
7+
}

0 commit comments

Comments
 (0)