summaryrefslogtreecommitdiff
path: root/sysdeps/generic/pt-condattr-setclock.c
diff options
context:
space:
mode:
authorThomas Schwinge <thomas@codesourcery.com>2012-08-30 23:29:21 +0200
committerThomas Schwinge <thomas@codesourcery.com>2012-08-30 23:29:21 +0200
commit6b1ebd29a16f2c2c91f8fcae4ce2b5dd62143821 (patch)
tree026e82163d438015f9fe828e16a174ee1a405803 /sysdeps/generic/pt-condattr-setclock.c
parent13aeb1df3614cbb0c0dc074427ab2f95160af0bb (diff)
parent0096579c8bea920f7c42b40ea22db621da6480a5 (diff)
Merge commit 'refs/top-bases/t/fix_have_kernel_resources' into t/fix_have_kernel_resourcest/fix_have_kernel_resources
Diffstat (limited to 'sysdeps/generic/pt-condattr-setclock.c')
-rw-r--r--sysdeps/generic/pt-condattr-setclock.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/sysdeps/generic/pt-condattr-setclock.c b/sysdeps/generic/pt-condattr-setclock.c
index 984c17e..c5a78ef 100644
--- a/sysdeps/generic/pt-condattr-setclock.c
+++ b/sysdeps/generic/pt-condattr-setclock.c
@@ -23,11 +23,30 @@
int
pthread_condattr_setclock (pthread_condattr_t *attr, clockid_t clock)
{
- if (__pthread_default_condattr.clock == clock)
+ /* Only a few clocks are allowed. CLOCK_REALTIME is always allowed.
+ CLOCK_MONOTONIC only if the kernel has the necessary support. */
+ if (clock == CLOCK_MONOTONIC)
{
- attr->clock = clock;
- return 0;
+ /* Check whether the clock is available. */
+ static int avail;
+
+ if (avail == 0)
+ {
+ struct timespec ts;
+ int res;
+
+ res = clock_getres (CLOCK_MONOTONIC, &ts);
+ avail = res < 0 ? -1 : 1;
+ }
+
+ if (avail < 0)
+ /* Not available. */
+ return EINVAL;
}
+ else if (clock != CLOCK_REALTIME)
+ return EINVAL;
+
+ attr->clock = clock;
- return EINVAL;
+ return 0;
}