X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fworkqueue.c;h=b6361adafb5b97f2116ac9b864111c8cc2a55d92;hb=7c40d7f5b2139ec9151daf8410b6b934234220d5;hp=e5931b5e74bfee68c3efd1ff61b53e9bc68af23f;hpb=014775106c60f02818ca755b331f887030bd440f;p=urcu.git diff --git a/src/workqueue.c b/src/workqueue.c index e5931b5..b6361ad 100644 --- a/src/workqueue.c +++ b/src/workqueue.c @@ -131,16 +131,25 @@ static void futex_wait(int32_t *futex) { /* Read condition before read futex */ cmm_smp_mb(); - if (uatomic_read(futex) != -1) - return; - 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. */ return; case EINTR: /* Retry if interrupted by signal. */ - break; /* Get out of switch. */ + break; /* Get out of switch. Check again. */ default: /* Unexpected error. */ urcu_die(errno);