X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fcommon%2Ffutex.c;h=80bdb01fb6f9e834c2d27564562edc34ce51e8e4;hb=717918b72e07062b62f96baaf1ae480b0a929617;hp=3fb0368751873093593fa87213f3e5ee75890d85;hpb=c6b1a4a69e5ed001cc0e3bec2191c18b9ee8612c;p=lttng-tools.git diff --git a/src/common/futex.c b/src/common/futex.c index 3fb036875..80bdb01fb 100644 --- a/src/common/futex.c +++ b/src/common/futex.c @@ -75,16 +75,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");