/* config.h. Manually generated for Xcode. */
-/* On 10.12 and later, use newly available clock_*() functions */
#include <AvailabilityMacros.h>
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
-/* Define to 1 if you have the `clock_gettime' function. */
-#define HAVE_CLOCK_GETTIME 1
-#endif
/* Default visibility */
#define DEFAULT_VISIBILITY /**/
/* Message logging */
#define ENABLE_LOGGING 1
+/* Define to 1 if the compiler supports _Thread_local. */
+#define HAVE_CC_THREAD_LOCAL 1
+
+/* On 10.12 and later, use newly available clock_*() functions */
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
+/* Define to 1 if you have the `clock_gettime' function. */
+#define HAVE_CLOCK_GETTIME 1
+#endif
+
+/* On 10.6 and later, use newly available pthread_threadid_np() function */
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
+/* Define to 1 if you have the 'pthread_threadid_np' function. */
+#define HAVE_PTHREAD_THREADID_NP 1
+#endif
+
/* Define to 1 if the system has the type `nfds_t'. */
#define HAVE_NFDS_T 1
case $backend in
darwin)
AC_DEFINE([OS_DARWIN], [1], [Darwin backend])
+ AC_CHECK_FUNCS([pthread_threadid_np])
LIBS="-lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation"
LTLDFLAGS="${LTLDFLAGS} -Wl,-prebind"
;;
#if defined(__ANDROID__)
# include <unistd.h>
-#elif defined(__linux__) || defined(__OpenBSD__)
-# if defined(__OpenBSD__)
-# define _BSD_SOURCE
-# endif
+#elif defined(__HAIKU__)
+# include <os/kernel/OS.h>
+#elif defined(__linux__)
+# include <sys/syscall.h>
+# include <unistd.h>
+#elif defined(__NetBSD__)
+# include <lwp.h>
+#elif defined(__OpenBSD__)
+# define _BSD_SOURCE
# include <sys/syscall.h>
+# include <unistd.h>
+#elif defined(__sun__)
+# include <sys/lwp.h>
#endif
int usbi_cond_timedwait(pthread_cond_t *cond,
#if defined(__ANDROID__)
tid = gettid();
+#elif defined(__APPLE__)
+#ifdef HAVE_PTHREAD_THREADID_NP
+ uint64_t thread_id;
+
+ if (pthread_threadid_np(NULL, &thread_id) == 0)
+ tid = (int)thread_id;
+ else
+ tid = -1;
+#else
+ tid = (int)pthread_mach_thread_np(pthread_self());
+#endif
+#elif defined(__HAIKU__)
+ tid = get_pthread_thread_id(pthread_self());
#elif defined(__linux__)
- tid = syscall(SYS_gettid);
+ tid = (int)syscall(SYS_gettid);
+#elif defined(__NetBSD__)
+ tid = _lwp_self();
#elif defined(__OpenBSD__)
/* The following only works with OpenBSD > 5.1 as it requires
- real thread support. For 5.1 and earlier, -1 is returned. */
+ * real thread support. For 5.1 and earlier, -1 is returned. */
tid = syscall(SYS_getthrid);
-#elif defined(__APPLE__)
- tid = (int)pthread_mach_thread_np(pthread_self());
-#elif defined(__CYGWIN__)
- tid = GetCurrentThreadId();
+#elif defined(__sun__)
+ tid = _lwp_self();
+#elif defined(_WIN32)
+ tid = (int)GetCurrentThreadId();
#else
tid = -1;
#endif
-/* TODO: NetBSD thread ID support */
+
+ if (tid == -1) {
+ /* If we don't have a thread ID, at least return a unique
+ * value that can be used to distinguish individual
+ * threads. */
+ tid = (int)(intptr_t)pthread_self();
+ }
+
return tid;
}