From 5841e4cb4981179b51e1fd92d7f6fcac53590be6 Mon Sep 17 00:00:00 2001 From: king6cong Date: Tue, 18 Apr 2017 20:03:23 +0800 Subject: [PATCH] support gettid on macos --- src/unistd.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/unistd.rs b/src/unistd.rs index 187154bd80..a8541e9f4f 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -165,7 +165,7 @@ pub fn getpgrp() -> pid_t { /// Get the caller's thread ID (see /// [gettid(2)](http://man7.org/linux/man-pages/man2/gettid.2.html). /// -/// This function is only available on Linux based systems. In a single +/// This implementation is only available on Linux based systems. In a single /// threaded process, the main thread will have the same ID as the process. In /// a multithreaded process, each thread will have a unique thread id but the /// same process ID. @@ -178,6 +178,15 @@ pub fn gettid() -> pid_t { unsafe { libc::syscall(libc::SYS_gettid) as pid_t } } +/// Get the caller's thread ID +/// This is the macos implementation +#[cfg(target_os = "macos")] +#[inline] +pub fn gettid() -> pid_t { + unsafe { libc::pthread_self() as pid_t } +} + + /// Create a copy of the specified file descriptor (see /// [dup(2)](http://man7.org/linux/man-pages/man2/dup.2.html)). /// @@ -272,7 +281,7 @@ pub fn fchdir(dirfd: RawFd) -> Result<()> { /// - the path already exists /// - the path name is too long (longer than `PATH_MAX`, usually 4096 on linux, 1024 on OS X) /// -/// For a full list consult +/// For a full list consult /// [man mkdir(2)](http://man7.org/linux/man-pages/man2/mkdir.2.html#ERRORS) /// /// # Example