Skip to content

Commit 7d71db8

Browse files
committed
support gettid on macos
1 parent 7b5dd78 commit 7d71db8

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/unistd.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ pub fn getpgrp() -> pid_t {
165165
/// Get the caller's thread ID (see
166166
/// [gettid(2)](http://man7.org/linux/man-pages/man2/gettid.2.html).
167167
///
168-
/// This function is only available on Linux based systems. In a single
168+
/// This implementation is only available on Linux based systems. In a single
169169
/// threaded process, the main thread will have the same ID as the process. In
170170
/// a multithreaded process, each thread will have a unique thread id but the
171171
/// same process ID.
@@ -178,6 +178,15 @@ pub fn gettid() -> pid_t {
178178
unsafe { libc::syscall(libc::SYS_gettid) as pid_t }
179179
}
180180

181+
/// Get the caller's thread ID
182+
/// This is the macos implementation
183+
#[cfg(target_os = "macos")]
184+
#[inline]
185+
pub fn gettid() -> pid_t {
186+
unsafe { self::libc::pthread_self() as pid_t }
187+
}
188+
189+
181190
/// Create a copy of the specified file descriptor (see
182191
/// [dup(2)](http://man7.org/linux/man-pages/man2/dup.2.html)).
183192
///
@@ -272,7 +281,7 @@ pub fn fchdir(dirfd: RawFd) -> Result<()> {
272281
/// - the path already exists
273282
/// - the path name is too long (longer than `PATH_MAX`, usually 4096 on linux, 1024 on OS X)
274283
///
275-
/// For a full list consult
284+
/// For a full list consult
276285
/// [man mkdir(2)](http://man7.org/linux/man-pages/man2/mkdir.2.html#ERRORS)
277286
///
278287
/// # Example

0 commit comments

Comments
 (0)