summaryrefslogtreecommitdiff
path: root/nptl
diff options
context:
space:
mode:
Diffstat (limited to 'nptl')
-rw-r--r--nptl/lll_timedlock_wait.c35
-rw-r--r--nptl/pthread_mutex_lock.c3
-rw-r--r--nptl/pthread_mutex_timedlock.c20
3 files changed, 23 insertions, 35 deletions
diff --git a/nptl/lll_timedlock_wait.c b/nptl/lll_timedlock_wait.c
index cd3cc3d371..952b042555 100644
--- a/nptl/lll_timedlock_wait.c
+++ b/nptl/lll_timedlock_wait.c
@@ -25,39 +25,38 @@
int
-__lll_clocklock_wait (int *futex, clockid_t clockid,
+__lll_clocklock_wait (int *futex, int val, clockid_t clockid,
const struct timespec *abstime, int private)
{
- /* Reject invalid timeouts. */
- if (! valid_nanoseconds (abstime->tv_nsec))
- return EINVAL;
+ struct timespec ts, *tsp = NULL;
- /* Try locking. */
- while (atomic_exchange_acq (futex, 2) != 0)
+ if (abstime != NULL)
{
- struct timespec ts;
+ /* Reject invalid timeouts. */
+ if (! valid_nanoseconds (abstime->tv_nsec))
+ return EINVAL;
- /* Get the current time. This can only fail if clockid is not
- valid. */
+ /* Get the current time. This can only fail if clockid is not valid. */
if (__glibc_unlikely (__clock_gettime (clockid, &ts) != 0))
return EINVAL;
/* Compute relative timeout. */
- struct timespec rt;
- rt.tv_sec = abstime->tv_sec - ts.tv_sec;
- rt.tv_nsec = abstime->tv_nsec - ts.tv_nsec;
- if (rt.tv_nsec < 0)
+ ts.tv_sec = abstime->tv_sec - ts.tv_sec;
+ ts.tv_nsec = abstime->tv_nsec - ts.tv_nsec;
+ if (ts.tv_nsec < 0)
{
- rt.tv_nsec += 1000000000;
- --rt.tv_sec;
+ ts.tv_nsec += 1000000000;
+ --ts.tv_sec;
}
- if (rt.tv_sec < 0)
+ if (ts.tv_sec < 0)
return ETIMEDOUT;
- /* If *futex == 2, wait until woken or timeout. */
- lll_futex_timed_wait (futex, 2, &rt, private);
+ tsp = &ts;
}
+ /* If *futex == val, wait until woken or timeout. */
+ lll_futex_timed_wait (futex, val, tsp, private);
+
return 0;
}
diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c
index 0ab890d815..ace436d5a6 100644
--- a/nptl/pthread_mutex_lock.c
+++ b/nptl/pthread_mutex_lock.c
@@ -434,7 +434,8 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex)
/* Delay the thread indefinitely. */
while (1)
- __pause_nocancel ();
+ lll_timedwait (&(int){0}, 0, 0 /* ignored */, NULL,
+ private);
}
oldval = mutex->__data.__lock;
diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c
index d6f0d9e31a..76b93bddc6 100644
--- a/nptl/pthread_mutex_timedlock.c
+++ b/nptl/pthread_mutex_timedlock.c
@@ -401,22 +401,10 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex,
/* Delay the thread until the timeout is reached.
Then return ETIMEDOUT. */
- struct timespec reltime;
- struct timespec now;
-
- INTERNAL_SYSCALL (clock_gettime, __err, 2, clockid,
- &now);
- reltime.tv_sec = abstime->tv_sec - now.tv_sec;
- reltime.tv_nsec = abstime->tv_nsec - now.tv_nsec;
- if (reltime.tv_nsec < 0)
- {
- reltime.tv_nsec += 1000000000;
- --reltime.tv_sec;
- }
- if (reltime.tv_sec >= 0)
- while (__nanosleep_nocancel (&reltime, &reltime) != 0)
- continue;
-
+ do
+ e = lll_timedwait (&(int){0}, 0, clockid, abstime,
+ private);
+ while (e != ETIMEDOUT);
return ETIMEDOUT;
}