#include <pthread.h>
#include <stdio.h>
#include <signal.h>
-#include <assert.h>
#include <string.h>
#include <errno.h>
#include <poll.h>
#include "urcu/futex.h"
+#include <urcu/assert.h>
#include <urcu/compiler.h>
#include <urcu/arch.h>
#include <urcu/uatomic.h>
#include <urcu/system.h>
#include <urcu/tls-compat.h>
#include "urcu-die.h"
+#include "urcu-utils.h"
/*
* Number of entries in the per-thread defer queue. Must be power of 2.
};
/* Do not #define _LGPL_SOURCE to ensure we can emit the wrapper symbols */
-#include "urcu-defer.h"
+#include <urcu/defer.h>
void __attribute__((destructor)) rcu_defer_exit(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);
* Worse-case: must allow 2 supplementary entries for fct pointer.
*/
if (caa_unlikely(head - tail >= DEFER_QUEUE_SIZE - 2)) {
- assert(head - tail <= DEFER_QUEUE_SIZE);
+ urcu_posix_assert(head - tail <= DEFER_QUEUE_SIZE);
rcu_defer_barrier_thread();
- assert(head - CMM_LOAD_SHARED(URCU_TLS(defer_queue).tail) == 0);
+ urcu_posix_assert(head - CMM_LOAD_SHARED(URCU_TLS(defer_queue).tail) == 0);
}
/*
wake_up_defer();
}
-static void *thr_defer(void *args)
+static void *thr_defer(void *args __attribute__((unused)))
{
for (;;) {
/*
int ret;
ret = pthread_create(&tid_defer, NULL, thr_defer, NULL);
- assert(!ret);
+ urcu_posix_assert(!ret);
}
static void stop_defer_thread(void)
wake_up_defer();
ret = pthread_join(tid_defer, &tret);
- assert(!ret);
+ urcu_posix_assert(!ret);
CMM_STORE_SHARED(defer_thread_stop, 0);
/* defer thread should always exit when futex value is 0 */
- assert(uatomic_read(&defer_thread_futex) == 0);
+ urcu_posix_assert(uatomic_read(&defer_thread_futex) == 0);
}
int rcu_defer_register_thread(void)
{
int was_empty;
- assert(URCU_TLS(defer_queue).last_head == 0);
- assert(URCU_TLS(defer_queue).q == NULL);
+ urcu_posix_assert(URCU_TLS(defer_queue).last_head == 0);
+ urcu_posix_assert(URCU_TLS(defer_queue).q == NULL);
URCU_TLS(defer_queue).q = malloc(sizeof(void *) * DEFER_QUEUE_SIZE);
if (!URCU_TLS(defer_queue).q)
return -ENOMEM;
void rcu_defer_exit(void)
{
- assert(cds_list_empty(®istry_defer));
+ urcu_posix_assert(cds_list_empty(®istry_defer));
}
#endif /* _URCU_DEFER_IMPL_H */