summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPino Toscano <toscano.pino@tiscali.it>2012-04-22 00:44:24 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2012-04-22 01:21:07 +0200
commit581b822ea36002817f4c22b9ea715b72a0647166 (patch)
tree3960143f613b63bd7bac2d482a4fd64e026bc556
parent69e89a859882e4f675dd5491edc969159d8a4002 (diff)
pthread_condattr_setclock: allow a monotonic clock, if present
If CLOCK_MONOTONIC is requested, check (only once) for the availability of a monotonic clock using `clock_getres'. If it is not, reject CLOCK_MONOTONIC with EINVAL (as before). * sysdeps/generic/pt-condattr-setclock.c (pthread_condattr_setclock): Check for monotonic clock if requested.
-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;
}