#else
/* clock_gettime */
+// gh-115714: Don't use CLOCK_PROCESS_CPUTIME_ID on WASI.
+/* CLOCK_PROF is defined on NetBSD, but not supported.
+ * CLOCK_PROCESS_CPUTIME_ID is broken on NetBSD for the same reason as
+ * CLOCK_THREAD_CPUTIME_ID (see comment below).
+ */
#if defined(HAVE_CLOCK_GETTIME) \
- && (defined(CLOCK_PROCESS_CPUTIME_ID) || defined(CLOCK_PROF))
+ && (defined(CLOCK_PROCESS_CPUTIME_ID) || defined(CLOCK_PROF)) \
+ && !defined(__NetBSD__)
struct timespec ts;
if (HAVE_CLOCK_GETTIME_RUNTIME) {
return 0;
}
+/* CLOCK_THREAD_CPUTIME_ID is broken on NetBSD: the result of clock_gettime()
+ * includes the sleeping time, that defeats the purpose of the clock.
+ * Also, clock_getres() does not support it.
+ * https://github.com/python/cpython/issues/123978
+ * https://gnats.netbsd.org/57512
+ */
#elif defined(HAVE_CLOCK_GETTIME) && \
- defined(CLOCK_PROCESS_CPUTIME_ID) && \
- !defined(__EMSCRIPTEN__) && !defined(__wasi__)
+ defined(CLOCK_THREAD_CPUTIME_ID) && \
+ !defined(__EMSCRIPTEN__) && !defined(__wasi__) && \
+ !defined(__NetBSD__)
#define HAVE_THREAD_TIME
#if defined(__APPLE__) && defined(__has_attribute) && __has_attribute(availability)