X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Ffutex.cpp;fp=src%2Fcommon%2Ffutex.cpp;h=e178b7e1b4f1e8a99de25e42b10733266353ada0;hp=21ab09ab7e455cc961305f6711ed2b6f53e36132;hb=36962e16797b5ca590c54a385ca594e2859ef8c2;hpb=042670db60ac672661e1bbc8de4da1d8590e20b4 diff --git a/src/common/futex.cpp b/src/common/futex.cpp index 21ab09ab7..e178b7e1b 100644 --- a/src/common/futex.cpp +++ b/src/common/futex.cpp @@ -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");