Add simple queue implementation
authorKrzysztof Opasiak <k.opasiak@samsung.com>
Thu, 20 Apr 2017 18:39:24 +0000 (20:39 +0200)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Thu, 20 Apr 2017 18:39:24 +0000 (20:39 +0200)
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
src/core/queue.h [new file with mode: 0644]

diff --git a/src/core/queue.h b/src/core/queue.h
new file mode 100644 (file)
index 0000000..a83d270
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * faultd
+ *
+ * Copyright © 2017 Samsung Electronics
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FAULTD_QUEUE_H
+#define FAULTD_QUEUE_H
+
+#include "list.h"
+
+/*
+ * Simple queue which use list for storing elements
+ */
+
+#define queue_head list_head
+
+#define QUEUE_INIT LIST_INIT
+
+#define INIT_QUEUE_HEAD INIT_LIST_HEAD;
+
+#define queue_append(head, new) list_add_tail(new, head);
+
+#define queue_pop(head, type, member) \
+        list_first_entry_or_null(head, type, member)
+
+#define queue_empty(head) list_empty(head)
+
+#define queue_for_each(pos, head) \
+        list_for_each(pos, head)
+
+#define queue_for_each_safe(pos, n, head)       \
+        list_for_each_safe(pos, n, head)
+
+#define queue_for_each_entry(pos, head, member) \
+        list_for_each_entry(pos, head, member)
+
+#define queue_for_each_entry_safe(pos, n, head, member) \
+        list_for_each_entry_safe(pos, n, head, member)
+
+#endif /* FAULTD_QUEUE_H */