X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=src%2Furcu-defer-impl.h;h=603cc85fc368561efc38eb9cf1ed705fa5c97378;hb=17de0299a62acd372dd81208de6dfa79d99116cc;hp=f96553365ba4f51035f427798edd2ac4eb981f13;hpb=2f6618651c31c05ba1adbb5cdcf0d92980c38f38;p=urcu.git diff --git a/src/urcu-defer-impl.h b/src/urcu-defer-impl.h index f965533..603cc85 100644 --- a/src/urcu-defer-impl.h +++ b/src/urcu-defer-impl.h @@ -50,6 +50,7 @@ #include #include #include "urcu-die.h" +#include "urcu-utils.h" /* * Number of entries in the per-thread defer queue. Must be power of 2. @@ -107,7 +108,7 @@ struct defer_queue { }; /* Do not #define _LGPL_SOURCE to ensure we can emit the wrapper symbols */ -#include "urcu-defer.h" +#include void __attribute__((destructor)) rcu_defer_exit(void); @@ -193,17 +194,25 @@ static void wait_defer(void) uatomic_set(&defer_thread_futex, 0); } else { cmm_smp_rmb(); /* Read queue before read futex */ - if (uatomic_read(&defer_thread_futex) != -1) - return; - while (futex_noasync(&defer_thread_futex, FUTEX_WAIT, -1, - NULL, NULL, 0)) { + while (uatomic_read(&defer_thread_futex) == -1) { + if (!futex_noasync(&defer_thread_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); @@ -371,7 +380,7 @@ static void _defer_rcu(void (*fct)(void *p), void *p) wake_up_defer(); } -static void *thr_defer(void *args) +static void *thr_defer(void *args __attribute__((unused))) { for (;;) { /* @@ -402,7 +411,8 @@ static void start_defer_thread(void) int ret; ret = pthread_create(&tid_defer, NULL, thr_defer, NULL); - assert(!ret); + if (ret) + urcu_die(ret); } static void stop_defer_thread(void)