Skip to content

Commit

Permalink
support gettid on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
king6cong committed Apr 18, 2017
1 parent 7b5dd78 commit 5841e4c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)).
///
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5841e4c

Please sign in to comment.