diff mbox

[PATCHv5,18/19] linux-generic: queues: add strong typing support

Message ID 1422938699-12877-19-git-send-email-bill.fischofer@linaro.org
State Accepted
Commit c0fa3c0f785ee51368f79f1b4b976df51c50ad01
Headers show

Commit Message

Bill Fischofer Feb. 3, 2015, 4:44 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 ++++----
 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 ++--
 6 files changed, 29 insertions(+), 18 deletions(-)
diff mbox

Patch

diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c
index 98dc76d..b073987 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_to_u64(pktio), dev,
-	       odp_pktio_to_u64(pktio), inq_def);
+	       odp_pktio_to_u64(pktio), odp_queue_to_u64(inq_def));
 
 	return pktio;
 }
diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
index f8377e4..1defb8f 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_to_u64(inq_def), idx,
+	       odp_queue_to_u64(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_to_u64(pktio), odp_pktio_to_u64(pktio), inq_def,
+	       odp_pktio_to_u64(pktio), odp_pktio_to_u64(pktio),
+	       odp_queue_to_u64(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 ad83968..4c02ece 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_to_u64(pktio), dev,
-	       odp_pktio_to_u64(pktio), inq_def);
+	       odp_pktio_to_u64(pktio), odp_queue_to_u64(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_to_u64(pktio), odp_pktio_to_u64(pktio),
-	       odp_pktio_inq_getdef(pktio));
+	       odp_queue_to_u64(odp_pktio_inq_getdef(pktio)));
 
 	/* Loop packets */
 	for (;;) {
diff --git a/platform/linux-generic/include/odp/plat/queue_types.h b/platform/linux-generic/include/odp/plat/queue_types.h
index cb81373..04a0be9 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_to_u64(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);
 }
 
 /******************************************************************************