Add simple queue implementation
authorKrzysztof Opasiak <k.opasiak@samsung.com>
Mon, 8 May 2017 20:51:24 +0000 (22:51 +0200)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Wed, 10 May 2017 18:42:58 +0000 (20:42 +0200)
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
src/util/queue.h [new file with mode: 0644]

diff --git a/src/util/queue.h b/src/util/queue.h
new file mode 100644 (file)
index 0000000..7ba2cc9
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * 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(name) LIST_HEAD_INIT(name)
+
+#define INIT_QUEUE_HEAD(head) INIT_LIST_HEAD(head);
+
+#define queue_append(head, new) list_add_tail(new, head);
+
+#define queue_pop(head, type, member) ({                                                       \
+       type *elem__;                                                                                                   \
+       elem__ = list_first_entry_or_null(head, type, member);                  \
+       if (elem__)                                                                                                             \
+               list_del(&elem__->member);                                                                      \
+       elem__;                                                                                                                 \
+})
+
+#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 */