Use RCU for statedump
[libside.git] / src / rcu.c
index 2e8be1c1b238a17ea337104ca4b90d4defb93b2b..9652725fdc1f037e9bf2eada107fdf954c489b90 100644 (file)
--- a/src/rcu.c
+++ b/src/rcu.c
@@ -89,9 +89,14 @@ void wait_gp(struct side_rcu_gp_state *gp_state)
        } else {
                __atomic_thread_fence(__ATOMIC_SEQ_CST);
        }
-       if (__atomic_load_n(&gp_state->futex, __ATOMIC_RELAXED) != -1)
-               return;
-       while (futex(&gp_state->futex, FUTEX_WAIT, -1, NULL, NULL, 0)) {
+       while (__atomic_load_n(&gp_state->futex, __ATOMIC_RELAXED) == -1) {
+               if (!futex(&gp_state->futex, FUTEX_WAIT, -1, NULL, NULL, 0)) {
+                       /*
+                        * May be awakened by either spurious wake up or
+                        * because the state is now as expected.
+                        */
+                       continue;
+               }
                switch (errno) {
                case EWOULDBLOCK:
                        /* Value already changed. */
@@ -286,7 +291,8 @@ void side_rcu_gp_init(struct side_rcu_gp_state *rcu_gp)
        if (!rcu_gp->nr_cpus)
                abort();
        pthread_mutex_init(&rcu_gp->gp_lock, NULL);
-       rcu_gp->percpu_state = calloc(rcu_gp->nr_cpus, sizeof(struct side_rcu_cpu_gp_state));
+       rcu_gp->percpu_state = (struct side_rcu_cpu_gp_state *)
+               calloc(rcu_gp->nr_cpus, sizeof(struct side_rcu_cpu_gp_state));
        if (!rcu_gp->percpu_state)
                abort();
        if (!membarrier(MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED, 0, 0))
This page took 0.038163 seconds and 4 git commands to generate.