Message ID | 1422720866-22194-2-git-send-email-bill.fischofer@linaro.org |
---|---|
State | New |
Headers | show |
On 01/31/2015 06:14 PM, Bill Fischofer wrote: > 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 --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; 'hdl' has a size of pointer, but 'val' is always 32 bit. Should it be uintptr_t? Otherwise _odp_pri() will print only lower 32 bits of a handle even if it can have 64 bits. > +} _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 >
No, this is the linux-generic implementation of strong typing and in this case all handles are in fact of type uint32_t. Wrapping them in a pointer type was Petri's suggestion that solves the problem of comparing handles using C's == and != operators since C allows pointers to be compared whereas it does not allow structs to be compared this way. Other implementations can use other mapping schemes that best suit their platform needs. On Sat, Jan 31, 2015 at 12:45 PM, Taras Kondratiuk < taras.kondratiuk@linaro.org> wrote: > On 01/31/2015 06:14 PM, Bill Fischofer wrote: > > 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 --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; > > 'hdl' has a size of pointer, but 'val' is always 32 bit. > Should it be uintptr_t? Otherwise _odp_pri() will print only lower 32 > bits of a handle even if it can have 64 bits. > > > +} _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 > > > > > -- > Taras Kondratiuk >
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
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