aboutsummaryrefslogtreecommitdiff
path: root/helper/include
diff options
context:
space:
mode:
authorDmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>2017-08-28 15:55:34 +0300
committerMaxim Uvarov <maxim.uvarov@linaro.org>2017-08-28 18:55:17 +0300
commit11fed684507a320fbb79dc86769c8f1755d0276f (patch)
tree68936137292e56cddf52c1402ca458df96280675 /helper/include
parent6a360e61978d03d12dbfff8c34c20cf95170a1c3 (diff)
helper: move include files to helper/include
Repair build with --enable-helper-linux option. https://bugs.linaro.org/show_bug.cgi?id=3216 Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'helper/include')
-rw-r--r--helper/include/odph_debug.h89
-rw-r--r--helper/include/odph_list_internal.h85
2 files changed, 174 insertions, 0 deletions
diff --git a/helper/include/odph_debug.h b/helper/include/odph_debug.h
new file mode 100644
index 000000000..36c743c2e
--- /dev/null
+++ b/helper/include/odph_debug.h
@@ -0,0 +1,89 @@
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+/**
+ * @file
+ *
+ * HELPER debug
+ */
+
+#ifndef HELPER_DEBUG_H_
+#define HELPER_DEBUG_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * log level.
+ */
+typedef enum HELPER_log_level {
+ ODPH_LOG_DBG,
+ ODPH_LOG_ERR,
+ ODPH_LOG_ABORT
+} HELPER_log_level_e;
+
+/**
+ * default LOG macro.
+ */
+#define ODPH_LOG(level, fmt, ...) \
+do { \
+ switch (level) { \
+ case ODPH_LOG_ERR: \
+ fprintf(stderr, "%s:%d:%s():" fmt, __FILE__, \
+ __LINE__, __func__, ##__VA_ARGS__); \
+ break; \
+ case ODPH_LOG_DBG: \
+ if (ODPH_DEBUG_PRINT == 1) \
+ fprintf(stderr, "%s:%d:%s():" fmt, __FILE__, \
+ __LINE__, __func__, ##__VA_ARGS__); \
+ break; \
+ case ODPH_LOG_ABORT: \
+ fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
+ __LINE__, __func__, ##__VA_ARGS__); \
+ abort(); \
+ break; \
+ default: \
+ fprintf(stderr, "Unknown LOG level"); \
+ break;\
+ } \
+} while (0)
+
+/**
+ * Debug printing macro, which prints output when DEBUG flag is set.
+ */
+#define ODPH_DBG(fmt, ...) \
+ ODPH_LOG(ODPH_LOG_DBG, fmt, ##__VA_ARGS__)
+
+/**
+ * Print output to stderr (file, line and function).
+ */
+#define ODPH_ERR(fmt, ...) \
+ ODPH_LOG(ODPH_LOG_ERR, fmt, ##__VA_ARGS__)
+
+/**
+ * Print output to stderr (file, line and function),
+ * then abort.
+ */
+#define ODPH_ABORT(fmt, ...) \
+ ODPH_LOG(ODPH_LOG_ABORT, fmt, ##__VA_ARGS__)
+
+/**
+ * @}
+ */
+
+/**
+ * Mark intentionally unused argument for functions
+ */
+#define ODPH_UNUSED __attribute__((__unused__))
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/helper/include/odph_list_internal.h b/helper/include/odph_list_internal.h
new file mode 100644
index 000000000..9e532b088
--- /dev/null
+++ b/helper/include/odph_list_internal.h
@@ -0,0 +1,85 @@
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/**
+ * @file
+ *
+ * ODP list
+ * a simple implementation of Doubly linked list
+ */
+
+#ifndef ODPH_LIST_INTER_H_
+#define ODPH_LIST_INTER_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct odph_list_object {
+ struct odph_list_object *next, *prev;
+} odph_list_object;
+
+typedef odph_list_object odph_list_head;
+
+static inline void ODPH_INIT_LIST_HEAD(odph_list_object *list)
+{
+ list->next = list;
+ list->prev = list;
+}
+
+static inline void __odph_list_add(odph_list_object *new,
+ odph_list_object *prev,
+ odph_list_object *next)
+{
+ next->prev = new;
+ new->next = next;
+ new->prev = prev;
+ prev->next = new;
+}
+
+static inline void odph_list_add(odph_list_object *new, odph_list_object *head)
+{
+ __odph_list_add(new, head, head->next);
+}
+
+static inline void odph_list_add_tail(struct odph_list_object *new,
+ odph_list_object *head)
+{
+ __odph_list_add(new, head->prev, head);
+}
+
+static inline void __odph_list_del(struct odph_list_object *prev,
+ odph_list_object *next)
+{
+ next->prev = prev;
+ prev->next = next;
+}
+
+static inline void odph_list_del(struct odph_list_object *entry)
+{
+ __odph_list_del(entry->prev, entry->next);
+ ODPH_INIT_LIST_HEAD(entry);
+}
+
+static inline int odph_list_empty(const struct odph_list_object *head)
+{
+ return head->next == head;
+}
+
+#define container_of(ptr, type, list_node) \
+ ((type *)(void *)((char *)ptr - offsetof(type, list_node)))
+
+#define ODPH_LIST_FOR_EACH(pos, list_head, type, list_node) \
+ for (pos = container_of((list_head)->next, type, list_node); \
+ &pos->list_node != (list_head); \
+ pos = container_of(pos->list_node.next, type, list_node))
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+