lib: work around unnamed structs/unions
[dpdk.git] / lib / librte_mempool / rte_mempool.h
index b2a5197..0243f9e 100644 (file)
@@ -74,6 +74,8 @@
 #include <rte_memory.h>
 #include <rte_branch_prediction.h>
 #include <rte_ring.h>
+#include <rte_memcpy.h>
+#include <rte_common.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -122,7 +124,9 @@ struct rte_mempool_objsz {
        /**< Total size of an object (header + elt + trailer). */
 };
 
-#define RTE_MEMPOOL_NAMESIZE 32 /**< Maximum length of a memory pool. */
+/**< Maximum length of a memory pool's name. */
+#define RTE_MEMPOOL_NAMESIZE (RTE_RING_NAMESIZE - \
+                             sizeof(RTE_MEMPOOL_MZ_PREFIX) + 1)
 #define RTE_MEMPOOL_MZ_PREFIX "MP_"
 
 /* "MP_<name>" */
@@ -162,6 +166,8 @@ struct rte_mempool_objhdr {
  */
 STAILQ_HEAD(rte_mempool_objhdr_list, rte_mempool_objhdr);
 
+#ifdef RTE_LIBRTE_MEMPOOL_DEBUG
+
 /**
  * Mempool object trailer structure
  *
@@ -169,11 +175,11 @@ STAILQ_HEAD(rte_mempool_objhdr_list, rte_mempool_objhdr);
  * trailer structure containing a cookie preventing memory corruptions.
  */
 struct rte_mempool_objtlr {
-#ifdef RTE_LIBRTE_MEMPOOL_DEBUG
        uint64_t cookie;                 /**< Debug cookie. */
-#endif
 };
 
+#endif
+
 /**
  * A list of memory where objects are stored
  */
@@ -205,7 +211,13 @@ struct rte_mempool_memhdr {
  * The RTE mempool structure.
  */
 struct rte_mempool {
-       char name[RTE_MEMPOOL_NAMESIZE]; /**< Name of mempool. */
+       /*
+        * Note: this field kept the RTE_MEMZONE_NAMESIZE size due to ABI
+        * compatibility requirements, it could be changed to
+        * RTE_MEMPOOL_NAMESIZE next time the ABI changes
+        */
+       char name[RTE_MEMZONE_NAMESIZE]; /**< Name of mempool. */
+       RTE_STD_C11
        union {
                void *pool_data;         /**< Ring or pool to store objects. */
                uint64_t pool_id;        /**< External mempool identifier. */
@@ -1028,7 +1040,6 @@ static inline void __attribute__((always_inline))
 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
                      unsigned n, struct rte_mempool_cache *cache, int flags)
 {
-       uint32_t index;
        void **cache_objs;
 
        /* increment stat now, adding in mempool always success */
@@ -1052,8 +1063,7 @@ __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
         */
 
        /* Add elements back into the cache */
-       for (index = 0; index < n; ++index, obj_table++)
-               cache_objs[index] = *obj_table;
+       rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
 
        cache->len += n;
 
@@ -1499,9 +1509,41 @@ rte_mempool_get(struct rte_mempool *mp, void **obj_p)
  * @return
  *   The number of entries in the mempool.
  */
+unsigned int rte_mempool_avail_count(const struct rte_mempool *mp);
+
+/**
+ * @deprecated
+ * Return the number of entries in the mempool.
+ *
+ * When cache is enabled, this function has to browse the length of
+ * all lcores, so it should not be used in a data path, but only for
+ * debug purposes.
+ *
+ * @param mp
+ *   A pointer to the mempool structure.
+ * @return
+ *   The number of entries in the mempool.
+ */
+__rte_deprecated
 unsigned rte_mempool_count(const struct rte_mempool *mp);
 
 /**
+ * Return the number of elements which have been allocated from the mempool
+ *
+ * When cache is enabled, this function has to browse the length of
+ * all lcores, so it should not be used in a data path, but only for
+ * debug purposes.
+ *
+ * @param mp
+ *   A pointer to the mempool structure.
+ * @return
+ *   The number of free entries in the mempool.
+ */
+unsigned int
+rte_mempool_in_use_count(const struct rte_mempool *mp);
+
+/**
+ * @deprecated
  * Return the number of free entries in the mempool ring.
  * i.e. how many entries can be freed back to the mempool.
  *
@@ -1518,10 +1560,11 @@ unsigned rte_mempool_count(const struct rte_mempool *mp);
  * @return
  *   The number of free entries in the mempool.
  */
+__rte_deprecated
 static inline unsigned
 rte_mempool_free_count(const struct rte_mempool *mp)
 {
-       return mp->size - rte_mempool_count(mp);
+       return rte_mempool_in_use_count(mp);
 }
 
 /**
@@ -1540,7 +1583,7 @@ rte_mempool_free_count(const struct rte_mempool *mp)
 static inline int
 rte_mempool_full(const struct rte_mempool *mp)
 {
-       return !!(rte_mempool_count(mp) == mp->size);
+       return !!(rte_mempool_avail_count(mp) == mp->size);
 }
 
 /**
@@ -1559,7 +1602,7 @@ rte_mempool_full(const struct rte_mempool *mp)
 static inline int
 rte_mempool_empty(const struct rte_mempool *mp)
 {
-       return !!(rte_mempool_count(mp) == 0);
+       return !!(rte_mempool_avail_count(mp) == 0);
 }
 
 /**