mirror of
https://sourceware.org/git/glibc.git
synced 2026-01-06 11:51:29 +03:00
nptl: Replace non cancellable pause/nanosleep with futex
To help y2038 work avoid duplicate all the logic of nanosleep on
non cancellable version, the patch replace it with a new futex
operation, lll_timedwait. The changes are:
- Add a expected value for __lll_clocklock_wait, so it can be used
to wait for generic values.
- Remove its internal atomic operation and move the logic to
__lll_clocklock. It makes __lll_clocklock_wait even more generic
and __lll_clocklock slight faster on fast-path (since it won't
require a function call anymore).
- Add lll_timedwait, which uses __lll_clocklock_wait, to replace both
__pause_nocancel and __nanosleep_nocancel.
It also allows remove the sparc32 __lll_clocklock_wait implementation
(since it is similar to the generic one).
Checked on x86_64-linux-gnu, sparcv9-linux-gnu, and i686-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
This commit is contained in:
@@ -1 +0,0 @@
|
||||
/* __lll_clocklock_wait is in lowlevellock.c. */
|
||||
@@ -50,46 +50,4 @@ __lll_lock_wait (int *futex, int private)
|
||||
}
|
||||
while (atomic_compare_and_exchange_val_24_acq (futex, 2, 0) != 0);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
__lll_clocklock_wait (int *futex, clockid_t clockid,
|
||||
const struct timespec *abstime, int private)
|
||||
{
|
||||
/* Reject invalid timeouts. */
|
||||
if (! valid_nanoseconds (abstime->tv_nsec))
|
||||
return EINVAL;
|
||||
|
||||
do
|
||||
{
|
||||
struct timespec ts;
|
||||
struct timespec rt;
|
||||
|
||||
/* 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. */
|
||||
rt.tv_sec = abstime->tv_sec - ts.tv_sec;
|
||||
rt.tv_nsec = abstime->tv_nsec - ts.tv_nsec;
|
||||
if (rt.tv_nsec < 0)
|
||||
{
|
||||
rt.tv_nsec += 1000000000;
|
||||
--rt.tv_sec;
|
||||
}
|
||||
|
||||
/* Already timed out? */
|
||||
if (rt.tv_sec < 0)
|
||||
return ETIMEDOUT;
|
||||
|
||||
/* Wait. */
|
||||
int oldval = atomic_compare_and_exchange_val_24_acq (futex, 2, 1);
|
||||
if (oldval != 0)
|
||||
lll_futex_timed_wait (futex, 2, &rt, private);
|
||||
}
|
||||
while (atomic_compare_and_exchange_val_24_acq (futex, 2, 0) != 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user