From: Bart Van Assche Date: Thu, 28 Jul 2011 15:04:08 +0000 (+0000) Subject: drd: Make drd_pthread_intercepts.c compile again on systems where X-Git-Tag: svn/VALGRIND_3_7_0~308 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08eecbf85d21d640a1b4344d3e1038bc1869bc7e;p=thirdparty%2Fvalgrind.git drd: Make drd_pthread_intercepts.c compile again on systems where FUTEX_PRIVATE_FLAG has not been defined in , e.g. older System z systems. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11929 --- diff --git a/drd/drd_pthread_intercepts.c b/drd/drd_pthread_intercepts.c index ebc2cc8559..b3fa771dfc 100644 --- a/drd/drd_pthread_intercepts.c +++ b/drd/drd_pthread_intercepts.c @@ -49,6 +49,7 @@ #endif #include /* assert() */ +#include #include /* pthread_mutex_t */ #include /* sem_t */ #include /* uintptr_t */ @@ -58,6 +59,9 @@ #ifdef __linux__ #include /* __NR_futex */ #include /* 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_() */ @@ -187,13 +191,26 @@ static void DRD_(sema_destroy)(DrdSema* sema) 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; + assert(res == EWOULDBLOCK || res == ENOSYS); + } #endif + /* + * Invoke sched_yield() on non-Linux systems, if the futex syscall has + * not been invoked or if this code has been built on a Linux system + * where __NR_futex is defined and is run on a Linux system that does + * not support the futex syscall. + */ + if (res == ENOSYS) + sched_yield(); } sema->counter--; } @@ -201,7 +218,7 @@ static void DRD_(sema_down)(DrdSema* sema) 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