[02/13] nptl: Remove futex_wait_cancelable
Commit Message
It is used solely on __pthread_cond_wait_common and the call can be
replaced by a __futex_abstimed_wait_cancelable64 one.
Checked on x86_64-linux-gnu and i686-linux-gnu.
---
nptl/pthread_cond_wait.c | 22 ++--------------------
sysdeps/nptl/futex-internal.h | 29 -----------------------------
2 files changed, 2 insertions(+), 49 deletions(-)
Comments
Hi Adhemerval,
> It is used solely on __pthread_cond_wait_common and the call can be
> replaced by a __futex_abstimed_wait_cancelable64 one.
>
> Checked on x86_64-linux-gnu and i686-linux-gnu.
> ---
> nptl/pthread_cond_wait.c | 22 ++--------------------
> sysdeps/nptl/futex-internal.h | 29 -----------------------------
> 2 files changed, 2 insertions(+), 49 deletions(-)
>
> diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c
> index 7d158d553f..685dbca32f 100644
> --- a/nptl/pthread_cond_wait.c
> +++ b/nptl/pthread_cond_wait.c
> @@ -501,26 +501,8 @@ __pthread_cond_wait_common (pthread_cond_t
> *cond, pthread_mutex_t *mutex, cbuffer.private = private;
> __pthread_cleanup_push (&buffer,
> __condvar_cleanup_waiting, &cbuffer);
> - if (abstime == NULL)
> - {
> - /* Block without a timeout. */
> - err = futex_wait_cancelable (
> - cond->__data.__g_signals + g, 0, private);
> - }
> - else
> - {
> - /* Block, but with a timeout.
> - Work around the fact that the kernel rejects
> negative timeout
> - values despite them being valid. */
> - if (__glibc_unlikely (abstime->tv_sec < 0))
> - err = ETIMEDOUT;
> - else
> - {
> - err = __futex_abstimed_wait_cancelable64
> - (cond->__data.__g_signals + g, 0, clockid,
> abstime,
> - private);
> - }
> - }
> + err = __futex_abstimed_wait_cancelable64 (
> + cond->__data.__g_signals + g, 0, clockid, abstime,
> private);
The __futex_abstimed_wait_cancelable64 can handle NULL abstime. Thanks
for cleaning this up :-).
> __pthread_cleanup_pop (&buffer, 0);
>
> diff --git a/sysdeps/nptl/futex-internal.h
> b/sysdeps/nptl/futex-internal.h index 21e3b74be6..96d1318091 100644
> --- a/sysdeps/nptl/futex-internal.h
> +++ b/sysdeps/nptl/futex-internal.h
> @@ -177,35 +177,6 @@ futex_wait_simple (unsigned int *futex_word,
> unsigned int expected, ignore_value (futex_wait (futex_word,
> expected, private)); }
>
> -
> -/* Like futex_wait but is a POSIX cancellation point. */
> -static __always_inline int
> -futex_wait_cancelable (unsigned int *futex_word, unsigned int
> expected,
> - int private)
> -{
> - int oldtype;
> - oldtype = __pthread_enable_asynccancel ();
> - int err = lll_futex_timed_wait (futex_word, expected, NULL,
> private);
> - __pthread_disable_asynccancel (oldtype);
> - switch (err)
> - {
> - case 0:
> - case -EAGAIN:
> - case -EINTR:
> - return -err;
> -
> - case -ETIMEDOUT: /* Cannot have happened as we provided no
> timeout. */
> - case -EFAULT: /* Must have been caused by a glibc or application
> bug. */
> - case -EINVAL: /* Either due to wrong alignment or due to the
> timeout not
> - being normalized. Must have been caused by a
> glibc or
> - application bug. */
> - case -ENOSYS: /* Must have been caused by a glibc bug. */
> - /* No other errors are documented at this time. */
> - default:
> - futex_fatal_error ();
> - }
> -}
> -
> /* Like futex_wait, but will eventually time out (i.e., stop being
> blocked) after the duration of time provided (i.e., RELTIME) has
> passed. The caller must provide a normalized RELTIME. RELTIME
> can also
Reviewed-by: Lukasz Majewski <lukma@denx.de>
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de
@@ -501,26 +501,8 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex,
cbuffer.private = private;
__pthread_cleanup_push (&buffer, __condvar_cleanup_waiting, &cbuffer);
- if (abstime == NULL)
- {
- /* Block without a timeout. */
- err = futex_wait_cancelable (
- cond->__data.__g_signals + g, 0, private);
- }
- else
- {
- /* Block, but with a timeout.
- Work around the fact that the kernel rejects negative timeout
- values despite them being valid. */
- if (__glibc_unlikely (abstime->tv_sec < 0))
- err = ETIMEDOUT;
- else
- {
- err = __futex_abstimed_wait_cancelable64
- (cond->__data.__g_signals + g, 0, clockid, abstime,
- private);
- }
- }
+ err = __futex_abstimed_wait_cancelable64 (
+ cond->__data.__g_signals + g, 0, clockid, abstime, private);
__pthread_cleanup_pop (&buffer, 0);
@@ -177,35 +177,6 @@ futex_wait_simple (unsigned int *futex_word, unsigned int expected,
ignore_value (futex_wait (futex_word, expected, private));
}
-
-/* Like futex_wait but is a POSIX cancellation point. */
-static __always_inline int
-futex_wait_cancelable (unsigned int *futex_word, unsigned int expected,
- int private)
-{
- int oldtype;
- oldtype = __pthread_enable_asynccancel ();
- int err = lll_futex_timed_wait (futex_word, expected, NULL, private);
- __pthread_disable_asynccancel (oldtype);
- switch (err)
- {
- case 0:
- case -EAGAIN:
- case -EINTR:
- return -err;
-
- case -ETIMEDOUT: /* Cannot have happened as we provided no timeout. */
- case -EFAULT: /* Must have been caused by a glibc or application bug. */
- case -EINVAL: /* Either due to wrong alignment or due to the timeout not
- being normalized. Must have been caused by a glibc or
- application bug. */
- case -ENOSYS: /* Must have been caused by a glibc bug. */
- /* No other errors are documented at this time. */
- default:
- futex_fatal_error ();
- }
-}
-
/* Like futex_wait, but will eventually time out (i.e., stop being
blocked) after the duration of time provided (i.e., RELTIME) has
passed. The caller must provide a normalized RELTIME. RELTIME can also