diff mbox

[1/9] api: add base macros for strong typing support

Message ID 1422592065-15875-2-git-send-email-bill.fischofer@linaro.org
State New
Headers show

Commit Message

Bill Fischofer Jan. 30, 2015, 4:27 a.m. UTC
Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
---
 platform/linux-generic/Makefile.am                 |  1 +
 .../linux-generic/include/odp/plat/strong_types.h  | 37 ++++++++++++++++++++++
 2 files changed, 38 insertions(+)
 create mode 100644 platform/linux-generic/include/odp/plat/strong_types.h
diff mbox

Patch

diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am
index addb5ec..81245b1 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -57,6 +57,7 @@  odpplatinclude_HEADERS = \
 		  $(top_srcdir)/platform/linux-generic/include/odp/plat/queue_types.h \
 		  $(top_srcdir)/platform/linux-generic/include/odp/plat/schedule_types.h \
 		  $(top_srcdir)/platform/linux-generic/include/odp/plat/shared_memory_types.h \
+		  $(top_srcdir)/platform/linux-generic/include/odp/plat/strong_types.h \
 		  $(top_srcdir)/platform/linux-generic/include/odp/plat/version_types.h
 
 odpapiincludedir= $(includedir)/odp/api
diff --git a/platform/linux-generic/include/odp/plat/strong_types.h b/platform/linux-generic/include/odp/plat/strong_types.h
new file mode 100644
index 0000000..9d73229
--- /dev/null
+++ b/platform/linux-generic/include/odp/plat/strong_types.h
@@ -0,0 +1,37 @@ 
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+
+/**
+ * @file
+ *
+ * ODP Strong Types. Common macros for implementing strong typing
+ * for ODP abstract data types
+ */
+
+#ifndef STRONG_TYPES_H_
+#define STRONG_TYPES_H_
+
+/** Use strong typing for ODP types */
+#define odp_handle_t struct {} *
+
+/** Internal typedefs for ODP strong type manipulation */
+typedef odp_handle_t _odp_handle_t;
+
+typedef union {
+	_odp_handle_t hdl;
+	uint32_t val;
+} _odp_handle_u;
+
+/** Internal macro to get value of an ODP handle */
+#define _odp_typeval(handle) (((_odp_handle_u)(_odp_handle_t)handle).val)
+
+/** Internal macro to get printable value of an ODP handle */
+#define _odp_pri(handle) ((uint64_t)_odp_typeval(handle))
+
+#define _odp_cast_scalar(type, val) ((type)(size_t)(val))
+
+#endif