|
From: Florian K. <br...@ac...> - 2011-07-28 13:50:17
|
On 07/28/2011 05:23 AM, Bart Van Assche wrote:
>
> I'd rather prefer a patch like the (untested) patch below:
>
> Index: drd/drd_pthread_intercepts.c
> ===================================================================
> --- drd/drd_pthread_intercepts.c (revision 11922)
> +++ drd/drd_pthread_intercepts.c (working copy)
> @@ -49,6 +49,7 @@
> #endif
>
> #include <assert.h> /* assert() */
> +#include <errno.h>
> #include <pthread.h> /* pthread_mutex_t */
> #include <semaphore.h> /* sem_t */
> #include <stdint.h> /* uintptr_t */
> @@ -58,7 +59,10 @@
> #ifdef __linux__
> #include <asm/unistd.h> /* __NR_futex */
> #include <linux/futex.h> /* FUTEX_WAIT */
> +#ifndef FUTEX_PRIVATE_FLAG
> +#define FUTEX_PRIVATE_FLAG 0
> #endif
> +#endif
> #include "config.h" /* HAVE_PTHREAD_MUTEX_ADAPTIVE_NP etc. */
> #include "drd_basics.h" /* DRD_() */
> #include "drd_clientreq.h"
> @@ -187,13 +191,18 @@
>
> static void DRD_(sema_down)(DrdSema* sema)
> {
> + int res = ENOSYS;
> +
> while (sema->counter == 0) {
> -#ifdef __linux__
> - syscall(__NR_futex, (UWord)&sema->counter,
> - FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0);
> -#else
> - sched_yield();
> +#if defined(__linux__) && defined(__NR_futex)
> + if (syscall(__NR_futex, (UWord)&sema->counter,
> + FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0) == 0)
> + res = 0;
> + else
> + res = errno;
> #endif
> + if (res != 0 && res != EWOULDBLOCK)
> + sched_yield();
> }
> sema->counter--;
> }
> @@ -201,7 +210,7 @@
> static void DRD_(sema_up)(DrdSema* sema)
> {
> sema->counter++;
> -#ifdef __linux__
> +#if defined(__linux__) && defined(__NR_futex)
> syscall(__NR_futex, (UWord)&sema->counter,
> FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1);
> #endif
>
With that patch it compiles and links fine.
I don't run DRD tests on that old machine so I can't say whether
this is going to be OK. Some of them make the machine hang...
I'd say go ahead and apply it. The next nightly build will tell
whether there are any regressions.
Florian
|