+/*
+ * synchronize_rcu() waiting. Single thread.
+ */
+static void wait_gp(void)
+{
+ /* Read reader_gp before read futex */
+ smp_mb_master(RCU_MB_GROUP);
+ if (uatomic_read(&gp_futex) == -1)
+ futex_async(&gp_futex, FUTEX_WAIT, -1,
+ NULL, NULL, 0);
+}
+
+void update_counter_and_wait(void)
+{
+ LIST_HEAD(qsreaders);
+ int wait_loops = 0;
+ struct rcu_reader *index, *tmp;
+
+ /* Switch parity: 0 -> 1, 1 -> 0 */
+ STORE_SHARED(rcu_gp_ctr, rcu_gp_ctr ^ RCU_GP_CTR_PHASE);
+
+ /*
+ * Must commit qparity update to memory before waiting for other parity
+ * quiescent state. Failure to do so could result in the writer waiting
+ * forever while new readers are always accessing data (no progress).
+ * Ensured by STORE_SHARED and LOAD_SHARED.
+ */
+
+ /*
+ * Adding a smp_mb() which is _not_ formally required, but makes the
+ * model easier to understand. It does not have a big performance impact
+ * anyway, given this is the write-side.
+ */
+ smp_mb();
+
+ /*
+ * Wait for each thread rcu_reader.ctr count to become 0.