From: Konstantin Ananyev <[email protected]>

Add a new API that allows for the caller to downgrade from wrlock
to rdlock. Note that caller is expected to obtain wrlock before calling
that function.

Signed-off-by: Konstantin Ananyev <[email protected]>
---
 lib/eal/include/rte_pflock.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/lib/eal/include/rte_pflock.h b/lib/eal/include/rte_pflock.h
index 6797ce5920..ed5255b3b5 100644
--- a/lib/eal/include/rte_pflock.h
+++ b/lib/eal/include/rte_pflock.h
@@ -179,6 +179,27 @@ rte_pflock_write_unlock(rte_pflock_t *pf)
        rte_atomic_fetch_add_explicit(&pf->wr.out, 1, rte_memory_order_release);
 }
 
+/**
+ * Release a pflock held for writing, while keeping lock for reading.
+ *
+ * @param pf
+ *   A pointer to a pflock structure.
+ */
+static inline void
+rte_pflock_write_downgrade(rte_pflock_t *pf)
+{
+       /* Migrate from write phase to read phase. */
+       rte_atomic_fetch_add_explicit(&pf->rd.in, RTE_PFLOCK_RINC,
+               rte_memory_order_acq_rel);
+       rte_atomic_fetch_and_explicit(&pf->rd.in, RTE_PFLOCK_LSB,
+                       rte_memory_order_release);
+
+       /* Allow other writers to continue. */
+       rte_atomic_fetch_add_explicit(&pf->wr.out, 1,
+                       rte_memory_order_release);
+}
+
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.51.0

Reply via email to