From 50266570943a755e42b96e0158ef85e579d2fcf0 Mon Sep 17 00:00:00 2001
From: Sergey Korolev <s.korolev@ndmsystems.com>
Date: Tue, 25 Apr 2017 02:14:59 +0300
Subject: [PATCH] pthread_getcpuclockid.c: fix clockid calculation
According to newer linux kernel sources (since 2.6.24)
MAKE_THREAD_CPUCLOCK macro-like computations used to get clockid.
---
.../unix/sysv/linux/pthread_getcpuclockid.c | 22 ++++------------------
1 file changed, 4 insertions(+), 18 deletions(-)
@@ -20,6 +20,8 @@
#include <sys/time.h>
#include <tls.h>
+#define CPUCLOCK_PERTHREAD_MASK 4
+#define CPUCLOCK_SCHED 2
int
pthread_getcpuclockid (
@@ -33,24 +35,8 @@ pthread_getcpuclockid (
/* Not a valid thread handle. */
return ESRCH;
-#ifdef CLOCK_THREAD_CPUTIME_ID
- /* We need to store the thread ID in the CLOCKID variable together
- with a number identifying the clock. We reserve the low 3 bits
- for the clock ID and the rest for the thread ID. This is
- problematic if the thread ID is too large. But 29 bits should be
- fine.
-
- If some day more clock IDs are needed the ID part can be
- enlarged. The IDs are entirely internal. */
- if (pd->tid >= 1 << (8 * sizeof (*clockid) - CLOCK_IDFIELD_SIZE))
- return ERANGE;
-
- /* Store the number. */
- *clockid = CLOCK_THREAD_CPUTIME_ID | (pd->tid << CLOCK_IDFIELD_SIZE);
+ *clockid = ((~(clockid_t) (pd->tid)) << CLOCK_IDFIELD_SIZE)
+ | CPUCLOCK_SCHED | CPUCLOCK_PERTHREAD_MASK;
return 0;
-#else
- /* We don't have a timer for that. */
- return ENOENT;
-#endif
}
--
2.7.4