diff mbox

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

Message ID 1422749807-20228-14-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>
---
 example/generator/odp_generator.c                     |  5 +++--
 example/ipsec/odp_ipsec.c                             | 12 +++++++-----
 example/packet/odp_pktio.c                            |  8 ++++----
 include/odp/api/queue.h                               | 13 +++++++++++++
 platform/linux-generic/include/odp/plat/queue_types.h | 14 +++++++++++---
 platform/linux-generic/include/odp_queue_internal.h   |  4 ++--
 platform/linux-generic/odp_timer.c                    |  4 ++--
 7 files changed, 42 insertions(+), 18 deletions(-)
diff mbox

Patch

diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c
index b98aba5..26f0cde 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -322,9 +322,10 @@  static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool)
 
 	printf("  created pktio:%02" PRIu64
 	       ", dev:%s, queue mode (ATOMIC queues)\n"
-	       "          default pktio%02" PRIu64 "-INPUT queue:%u\n",
+	       "          default pktio%02" PRIu64
+	       "-INPUT queue:%" PRIu64 "\n",
 	       odp_pktio_t_print(pktio), dev,
-	       odp_pktio_t_print(pktio), inq_def);
+	       odp_pktio_t_print(pktio), odp_queue_t_print(inq_def));
 
 	return pktio;
 }
diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
index 2f7106d..04be16e 100644
--- a/example/ipsec/odp_ipsec.c
+++ b/example/ipsec/odp_ipsec.c
@@ -520,10 +520,11 @@  void initialize_loop(char *intf)
 	mac = query_loopback_db_mac(idx);
 
 	printf("Created loop:%02i, queue mode (ATOMIC queues)\n"
-	       "          default loop%02i-INPUT queue:%u\n"
-	       "          default loop%02i-OUTPUT queue:%u\n"
+	       "          default loop%02i-INPUT queue:%" PRIu64 "\n"
+	       "          default loop%02i-OUTPUT queue:%" PRIu64 "\n"
 	       "          source mac address %s\n",
-	       idx, idx, inq_def, idx, outq_def,
+	       idx, idx, odp_queue_t_print(inq_def), idx,
+	       odp_queue_t_print(outq_def),
 	       mac_addr_str(mac_str, mac));
 
 	/* Resolve any routes using this interface for output */
@@ -597,9 +598,10 @@  void initialize_intf(char *intf)
 	}
 
 	printf("Created pktio:%02" PRIu64 ", queue mode (ATOMIC queues)\n"
-	       "          default pktio%02" PRIu64 "-INPUT queue:%u\n"
+	       "          default pktio%02" PRIu64 "-INPUT queue:%" PRIu64 "\n"
 	       "          source mac address %s\n",
-	       odp_pktio_t_print(pktio), odp_pktio_t_print(pktio), inq_def,
+	       odp_pktio_t_print(pktio), odp_pktio_t_print(pktio),
+	       odp_queue_t_print(inq_def),
 	       mac_addr_str(src_mac_str, src_mac));
 
 	/* Resolve any routes using this interface for output */
diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c
index cd13576..77ac4f5 100644
--- a/example/packet/odp_pktio.c
+++ b/example/packet/odp_pktio.c
@@ -134,9 +134,9 @@  static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool, int mode)
 
 	printf("  created pktio:%02" PRIu64
 	       ", dev:%s, queue mode (ATOMIC queues)\n"
-	       "  \tdefault pktio%02" PRIu64 "-INPUT queue:%u\n",
+	       "  \tdefault pktio%02" PRIu64 "-INPUT queue:%" PRIu64 "\n",
 	       odp_pktio_t_print(pktio), dev,
-	       odp_pktio_t_print(pktio), inq_def);
+	       odp_pktio_t_print(pktio), odp_queue_t_print(inq_def));
 
 	return pktio;
 }
@@ -169,9 +169,9 @@  static void *pktio_queue_thread(void *arg)
 
 	printf("  [%02i] looked up pktio:%02" PRIu64
 	       ", queue mode (ATOMIC queues)\n"
-	       "         default pktio%02" PRIu64 "-INPUT queue:%u\n",
+	       "         default pktio%02" PRIu64 "-INPUT queue:%" PRIu64 "\n",
 	       thr, odp_pktio_t_print(pktio), odp_pktio_t_print(pktio),
-	       odp_pktio_inq_getdef(pktio));
+	       odp_queue_t_print(odp_pktio_inq_getdef(pktio)));
 
 	/* Loop packets */
 	for (;;) {
diff --git a/include/odp/api/queue.h b/include/odp/api/queue.h
index b63cc34..de609ca 100644
--- a/include/odp/api/queue.h
+++ b/include/odp/api/queue.h
@@ -298,6 +298,19 @@  odp_schedule_prio_t odp_queue_sched_prio(odp_queue_t queue);
 odp_schedule_group_t odp_queue_sched_group(odp_queue_t queue);
 
 /**
+ * Get printable value for an odp_queue_t
+ *
+ * @param hdl  odp_queue_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_queue_t handle.
+ */
+uint64_t odp_queue_t_print(odp_queue_t hdl);
+
+/**
  * @}
  */
 
diff --git a/platform/linux-generic/include/odp/plat/queue_types.h b/platform/linux-generic/include/odp/plat/queue_types.h
index cb81373..a634bac 100644
--- a/platform/linux-generic/include/odp/plat/queue_types.h
+++ b/platform/linux-generic/include/odp/plat/queue_types.h
@@ -17,16 +17,19 @@ 
 extern "C" {
 #endif
 
+#include <odp/std_types.h>
+#include <odp/plat/strong_types.h>
+
 /** @addtogroup odp_queue ODP QUEUE
  *  Macros and operation on a queue.
  *  @{
  */
 
-typedef uint32_t odp_queue_t;
+typedef odp_handle_t odp_queue_t;
 
-typedef uint32_t odp_queue_group_t;
+typedef odp_handle_t odp_queue_group_t;
 
-#define ODP_QUEUE_INVALID  0
+#define ODP_QUEUE_INVALID  _odp_cast_scalar(odp_queue_t, 0)
 
 #define ODP_QUEUE_NAME_LEN 32
 
@@ -63,6 +66,11 @@  typedef int odp_schedule_group_t;
 
 #define ODP_SCHED_GROUP_DEFAULT ODP_SCHED_GROUP_ALL
 
+/** Get printable format of odp_queue_t */
+static inline uint64_t odp_queue_t_print(odp_queue_t hdl)
+{
+	return _odp_pri(hdl);
+}
 
 /**
  * @}
diff --git a/platform/linux-generic/include/odp_queue_internal.h b/platform/linux-generic/include/odp_queue_internal.h
index 340e20d..bfa36df 100644
--- a/platform/linux-generic/include/odp_queue_internal.h
+++ b/platform/linux-generic/include/odp_queue_internal.h
@@ -105,12 +105,12 @@  int queue_sched_atomic(odp_queue_t handle);
 
 static inline uint32_t queue_to_id(odp_queue_t handle)
 {
-	return handle - 1;
+	return _odp_typeval(handle) - 1;
 }
 
 static inline odp_queue_t queue_from_id(uint32_t queue_id)
 {
-	return queue_id + 1;
+	return _odp_cast_scalar(odp_queue_t, queue_id + 1);
 }
 
 static inline queue_entry_t *queue_to_qentry(odp_queue_t handle)
diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c
index 0b2e675..727f3a1 100644
--- a/platform/linux-generic/odp_timer.c
+++ b/platform/linux-generic/odp_timer.c
@@ -132,14 +132,14 @@  static void timer_fini(odp_timer *tim, tick_buf_t *tb)
 static inline uint32_t get_next_free(odp_timer *tim)
 {
 	/* Reusing 'queue' for next free index */
-	return tim->queue;
+	return _odp_typeval(tim->queue);
 }
 
 static inline void set_next_free(odp_timer *tim, uint32_t nf)
 {
 	assert(tim->queue == ODP_QUEUE_INVALID);
 	/* Reusing 'queue' for next free index */
-	tim->queue = nf;
+	tim->queue = _odp_cast_scalar(odp_queue_t, nf);
 }
 
 /******************************************************************************