[dpdk-dev,v2,2/5] ring: add a function to return the ring size

Message ID 1487868123-30262-3-git-send-email-bruce.richardson@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Bruce Richardson Feb. 23, 2017, 4:42 p.m. UTC
  Applications and other libraries should not be reading inside the
rte_ring structure directly to get the ring size. Instead add a fn
to allow it to be queried.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/librte_ring/rte_ring.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
  

Comments

Olivier Matz March 8, 2017, 10 a.m. UTC | #1
On Thu, 23 Feb 2017 16:42:00 +0000, Bruce Richardson
<bruce.richardson@intel.com> wrote:
> Applications and other libraries should not be reading inside the
> rte_ring structure directly to get the ring size. Instead add a fn
> to allow it to be queried.
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>

Acked-by: Olivier Matz <olivier.matz@6wind.com>
  

Patch

diff --git a/lib/librte_ring/rte_ring.h b/lib/librte_ring/rte_ring.h
index e359aff..72ccca5 100644
--- a/lib/librte_ring/rte_ring.h
+++ b/lib/librte_ring/rte_ring.h
@@ -1108,6 +1108,20 @@  rte_ring_free_count(const struct rte_ring *r)
 }
 
 /**
+ * Return the size of the ring.
+ *
+ * @param r
+ *   A pointer to the ring structure.
+ * @return
+ *   The number of elements which can be stored in the ring.
+ */
+static inline unsigned int
+rte_ring_get_size(const struct rte_ring *r)
+{
+	return r->prod.size;
+}
+
+/**
  * Dump the status of all rings on the console
  *
  * @param f