summaryrefslogtreecommitdiff
path: root/libusb/os
diff options
context:
space:
mode:
Diffstat (limited to 'libusb/os')
-rw-r--r--libusb/os/threads_posix.c20
-rw-r--r--libusb/os/threads_posix.h2
-rw-r--r--libusb/os/threads_windows.c4
-rw-r--r--libusb/os/threads_windows.h2
4 files changed, 28 insertions, 0 deletions
diff --git a/libusb/os/threads_posix.c b/libusb/os/threads_posix.c
index fb040ce..8e9b490 100644
--- a/libusb/os/threads_posix.c
+++ b/libusb/os/threads_posix.c
@@ -19,6 +19,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#if defined(__linux__)
+# include <unistd.h>
+# include <sys/syscall.h>
+#elif defined(__APPLE__)
+# include <mach/mach.h>
+#endif
+
#ifdef _XOPEN_SOURCE
# if _XOPEN_SOURCE < 500
# undef _XOPEN_SOURCE
@@ -53,3 +60,16 @@ finish:
return err;
}
+
+int usbi_get_tid(void)
+{
+ int ret = -1;
+#if defined(__linux__)
+ ret = syscall(SYS_gettid);
+#elif defined(__APPLE__)
+ ret = mach_thread_self();
+ mach_port_deallocate(mach_task_self(), ret);
+#endif
+/* TODO: OpenBSD and NetBSD thread ID support */
+ return ret;
+}
diff --git a/libusb/os/threads_posix.h b/libusb/os/threads_posix.h
index db4de28..5f66b6a 100644
--- a/libusb/os/threads_posix.h
+++ b/libusb/os/threads_posix.h
@@ -45,4 +45,6 @@
extern int usbi_mutex_init_recursive(pthread_mutex_t *mutex, pthread_mutexattr_t *attr);
+int usbi_get_tid(void);
+
#endif /* LIBUSB_THREADS_POSIX_H */
diff --git a/libusb/os/threads_windows.c b/libusb/os/threads_windows.c
index bb5c4c8..aceca36 100644
--- a/libusb/os/threads_windows.c
+++ b/libusb/os/threads_windows.c
@@ -204,3 +204,7 @@ int usbi_cond_timedwait(usbi_cond_t *cond,
return usbi_cond_intwait(cond, mutex, millis);
}
+
+int usbi_get_tid(void) {
+ return GetCurrentThreadId();
+}
diff --git a/libusb/os/threads_windows.h b/libusb/os/threads_windows.h
index 764a98c..3dbae02 100644
--- a/libusb/os/threads_windows.h
+++ b/libusb/os/threads_windows.h
@@ -82,4 +82,6 @@ int usbi_cond_timedwait(usbi_cond_t *cond,
int usbi_cond_broadcast(usbi_cond_t *cond);
int usbi_cond_signal(usbi_cond_t *cond);
+int usbi_get_tid(void);
+
#endif /* LIBUSB_THREADS_WINDOWS_H */