X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fcommon%2Ffutex.cpp;h=e178b7e1b4f1e8a99de25e42b10733266353ada0;hb=36962e16797b5ca590c54a385ca594e2859ef8c2;hp=3eadf096bc8086760e36b24f3a342341d048c9fa;hpb=21cf9b6b1843774306a76f4dccddddd706b64f79;p=lttng-tools.git diff --git a/src/common/futex.cpp b/src/common/futex.cpp index 3eadf096b..e178b7e1b 100644 --- a/src/common/futex.cpp +++ b/src/common/futex.cpp @@ -12,9 +12,9 @@ #include #include -#include +#include -#include "futex.h" +#include "futex.hpp" /* * This futex wait/wake scheme only works for N wakers / 1 waiters. Hence the @@ -72,16 +72,25 @@ void futex_nto1_wait(int32_t *futex) { cmm_smp_mb(); - if (uatomic_read(futex) != -1) - goto end; - while (futex_async(futex, FUTEX_WAIT, -1, NULL, NULL, 0)) { + while (uatomic_read(futex) == -1) { + if (!futex_async(futex, FUTEX_WAIT, -1, NULL, NULL, 0)) { + /* + * Prior queued wakeups queued by unrelated code + * using the same address can cause futex wait to + * return 0 even through the futex value is still + * -1 (spurious wakeups). Check the value again + * in user-space to validate whether it really + * differs from -1. + */ + continue; + } switch (errno) { - case EWOULDBLOCK: + case EAGAIN: /* Value already changed. */ goto end; case EINTR: /* Retry if interrupted by signal. */ - break; /* Get out of switch. */ + break; /* Get out of switch. Check again. */ default: /* Unexpected error. */ PERROR("futex_async");