File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed
Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 1+ Added process::pthread_getthreadid_np() on FreeBSD.
Original file line number Diff line number Diff line change @@ -403,6 +403,14 @@ pub fn getpgrp() -> Pid {
403403pub fn gettid( ) -> Pid {
404404 Pid ( unsafe { libc:: syscall( libc:: SYS_gettid ) as pid_t } )
405405}
406+
407+ /// Get the caller's thread ID (see
408+ /// [pthread_getthreadid_np(3)](https://man.freebsd.org/cgi/man.cgi?query=pthread_getthreadid_np&sektion=3&manpath=FreeBSD+15.0-RELEASE+and+Ports).
409+ #[ cfg( target_os = "freebsd" ) ]
410+ #[ inline]
411+ pub fn pthread_getthreadid_np( ) -> Pid {
412+ Pid ( unsafe { libc:: pthread_getthreadid_np( ) as pid_t } )
413+ }
406414}
407415
408416feature ! {
Original file line number Diff line number Diff line change @@ -260,6 +260,19 @@ mod linux_android {
260260 }
261261}
262262
263+ #[ cfg( target_os = "freebsd" ) ]
264+ mod freebsd {
265+ use nix:: unistd:: pthread_getthreadid_np;
266+
267+ #[ test]
268+ fn test_pthread_getthreadid_np ( ) {
269+ let tid: :: libc:: pid_t = pthread_getthreadid_np ( ) . into ( ) ;
270+ // FreeBSD has thread id namespace shared with pids, the split
271+ // is at PID_MAX = 99999.
272+ assert ! ( tid >= 100000 ) ;
273+ }
274+ }
275+
263276#[ test]
264277// `getgroups()` and `setgroups()` do not behave as expected on Apple platforms
265278#[ cfg( not( any(
You can’t perform that action at this time.
0 commit comments