diff mbox

[PATCHv3,9/9] linux-generic: shm: add strong typing support

Message ID 1422749807-20228-16-git-send-email-bill.fischofer@linaro.org
State New
Headers show

Commit Message

Bill Fischofer Feb. 1, 2015, 12:16 a.m. UTC
Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
---
 include/odp/api/shared_memory.h                             | 13 +++++++++++++
 .../linux-generic/include/odp/plat/shared_memory_types.h    | 13 +++++++++++--
 platform/linux-generic/odp_shared_memory.c                  |  4 ++--
 3 files changed, 26 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/include/odp/api/shared_memory.h b/include/odp/api/shared_memory.h
index 5b27b6b..3edcc64 100644
--- a/include/odp/api/shared_memory.h
+++ b/include/odp/api/shared_memory.h
@@ -128,6 +128,19 @@  int odp_shm_info(odp_shm_t shm, odp_shm_info_t *info);
 void odp_shm_print_all(void);
 
 /**
+ * Get printable value for an odp_shm_t
+ *
+ * @param hdl  odp_shm_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_shm_t handle.
+ */
+uint64_t odp_shm_t_print(odp_shm_t hdl);
+
+/**
  * @}
  */
 
diff --git a/platform/linux-generic/include/odp/plat/shared_memory_types.h b/platform/linux-generic/include/odp/plat/shared_memory_types.h
index c044cb9..1b62d15 100644
--- a/platform/linux-generic/include/odp/plat/shared_memory_types.h
+++ b/platform/linux-generic/include/odp/plat/shared_memory_types.h
@@ -18,16 +18,25 @@ 
 extern "C" {
 #endif
 
+#include <odp/std_types.h>
+#include <odp/plat/strong_types.h>
+
 /** @addtogroup odp_shared_memory ODP SHARED MEMORY
  *  Operations on shared memory.
  *  @{
  */
 
-typedef uint32_t odp_shm_t;
+typedef odp_handle_t odp_shm_t;
 
-#define ODP_SHM_INVALID 0
+#define ODP_SHM_INVALID _odp_cast_scalar(odp_shm_t, 0)
 #define ODP_SHM_NULL ODP_SHM_INVALID
 
+/** Get printable format of odp_shm_t */
+static inline uint64_t odp_shm_t_print(odp_shm_t hdl)
+{
+	return _odp_pri(hdl);
+}
+
 /**
  * @}
  */
diff --git a/platform/linux-generic/odp_shared_memory.c b/platform/linux-generic/odp_shared_memory.c
index 96d10e8..dbaec22 100644
--- a/platform/linux-generic/odp_shared_memory.c
+++ b/platform/linux-generic/odp_shared_memory.c
@@ -64,13 +64,13 @@  static odp_shm_table_t *odp_shm_tbl;
 
 static inline uint32_t from_handle(odp_shm_t shm)
 {
-	return shm - 1;
+	return _odp_typeval(shm) - 1;
 }
 
 
 static inline odp_shm_t to_handle(uint32_t index)
 {
-	return index + 1;
+	return _odp_cast_scalar(odp_shm_t, index + 1);
 }