diff mbox

[PATCHv2,7/9] linux-generic: pool: add strong typing support

Message ID 1422720866-22194-8-git-send-email-bill.fischofer@linaro.org
State New
Headers show

Commit Message

Bill Fischofer Jan. 31, 2015, 4:14 p.m. UTC
Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
---
 include/odp/api/pool.h                                    | 13 +++++++++++++
 platform/linux-generic/include/odp/plat/pool_types.h      | 13 +++++++++++--
 platform/linux-generic/include/odp_buffer_inlines.h       |  4 +++-
 platform/linux-generic/include/odp_buffer_pool_internal.h |  4 ++--
 platform/linux-generic/odp_buffer.c                       |  3 ++-
 platform/linux-generic/odp_buffer_pool.c                  |  3 ++-
 6 files changed, 33 insertions(+), 7 deletions(-)
diff mbox

Patch

diff --git a/include/odp/api/pool.h b/include/odp/api/pool.h
index 1582102..6771932 100644
--- a/include/odp/api/pool.h
+++ b/include/odp/api/pool.h
@@ -184,6 +184,19 @@  int odp_pool_info(odp_pool_t pool, odp_pool_info_t *info);
 void odp_pool_print(odp_pool_t pool);
 
 /**
+ * Get printable value for an odp_pool_t
+ *
+ * @param hdl  odp_pool_t handle to be printed
+ * @return     uint64_t value that can be used to print/display this
+ *             handle
+ *
+ * @note This routine is intended to be used for diagnostic purposes
+ * to enable applications to generate a printable value that represents
+ * an odp_pool_t handle.
+ */
+uint64_t odp_pool_t_print(odp_pool_t hdl);
+
+/**
  * Buffer alloc
  *
  * The validity of a buffer can be cheked at any time with odp_buffer_is_valid()
diff --git a/platform/linux-generic/include/odp/plat/pool_types.h b/platform/linux-generic/include/odp/plat/pool_types.h
index 7bfbbfc..a755354 100644
--- a/platform/linux-generic/include/odp/plat/pool_types.h
+++ b/platform/linux-generic/include/odp/plat/pool_types.h
@@ -13,6 +13,9 @@ 
 #ifndef ODP_POOL_TYPES_H_
 #define ODP_POOL_TYPES_H_
 
+#include <odp/std_types.h>
+#include <odp/plat/strong_types.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -22,9 +25,15 @@  extern "C" {
  *  @{
  */
 
-typedef uint32_t odp_pool_t;
+typedef odp_handle_t odp_pool_t;
+
+#define ODP_POOL_INVALID _odp_cast_scalar(odp_pool_t, 0xffffffff)
 
-#define ODP_POOL_INVALID (0xffffffff)
+/** Get printable format of odp_pool_t */
+static inline uint64_t odp_pool_t_print(odp_pool_t hdl)
+{
+	return _odp_pri(hdl);
+}
 
 /**
  * @}
diff --git a/platform/linux-generic/include/odp_buffer_inlines.h b/platform/linux-generic/include/odp_buffer_inlines.h
index ba358f1..f6eef3d 100644
--- a/platform/linux-generic/include/odp_buffer_inlines.h
+++ b/platform/linux-generic/include/odp_buffer_inlines.h
@@ -106,7 +106,9 @@  static inline odp_buffer_hdr_t *validate_buf(odp_buffer_t buf)
 	if (handle.seg != 0 || handle.pool_id >= ODP_CONFIG_POOLS)
 		return NULL;
 
-	pool_entry_t *pool = odp_pool_to_entry(handle.pool_id);
+	pool_entry_t *pool =
+		odp_pool_to_entry(_odp_cast_scalar(odp_pool_t,
+						   handle.pool_id));
 
 	/* If pool not created, handle is invalid */
 	if (pool->s.pool_shm == ODP_SHM_INVALID)
diff --git a/platform/linux-generic/include/odp_buffer_pool_internal.h b/platform/linux-generic/include/odp_buffer_pool_internal.h
index e02e35a..c5354e5 100644
--- a/platform/linux-generic/include/odp_buffer_pool_internal.h
+++ b/platform/linux-generic/include/odp_buffer_pool_internal.h
@@ -335,12 +335,12 @@  static inline void flush_cache(local_cache_t *buf_cache,
 
 static inline odp_pool_t pool_index_to_handle(uint32_t pool_id)
 {
-	return pool_id;
+	return _odp_cast_scalar(odp_pool_t, pool_id);
 }
 
 static inline uint32_t pool_handle_to_index(odp_pool_t pool_hdl)
 {
-	return pool_hdl;
+	return _odp_typeval(pool_hdl);
 }
 
 static inline void *get_pool_entry(uint32_t pool_id)
diff --git a/platform/linux-generic/odp_buffer.c b/platform/linux-generic/odp_buffer.c
index eb59a66..4f9e9dc 100644
--- a/platform/linux-generic/odp_buffer.c
+++ b/platform/linux-generic/odp_buffer.c
@@ -76,7 +76,8 @@  int odp_buffer_snprint(char *str, uint32_t n, odp_buffer_t buf)
 	len += snprintf(&str[len], n-len,
 			"Buffer\n");
 	len += snprintf(&str[len], n-len,
-			"  pool         %i\n",        hdr->pool_hdl);
+			"  pool         %" PRIu64 "\n",
+			odp_pool_t_print(hdr->pool_hdl));
 	len += snprintf(&str[len], n-len,
 			"  addr         %p\n",        hdr->addr);
 	len += snprintf(&str[len], n-len,
diff --git a/platform/linux-generic/odp_buffer_pool.c b/platform/linux-generic/odp_buffer_pool.c
index 3e13e6f..1a1957f 100644
--- a/platform/linux-generic/odp_buffer_pool.c
+++ b/platform/linux-generic/odp_buffer_pool.c
@@ -558,7 +558,8 @@  void odp_pool_print(odp_pool_t pool_hdl)
 
 	ODP_DBG("Pool info\n");
 	ODP_DBG("---------\n");
-	ODP_DBG(" pool            %i\n", pool->s.pool_hdl);
+	ODP_DBG(" pool            %" PRIu64 "\n",
+		odp_pool_t_print(pool->s.pool_hdl));
 	ODP_DBG(" name            %s\n",
 		pool->s.flags.has_name ? pool->s.name : "Unnamed Pool");
 	ODP_DBG(" pool type       %s\n",