summaryrefslogtreecommitdiffstats
path: root/src/framework/event/epoll/eprb_tree.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/framework/event/epoll/eprb_tree.h')
-rw-r--r--src/framework/event/epoll/eprb_tree.h82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/framework/event/epoll/eprb_tree.h b/src/framework/event/epoll/eprb_tree.h
new file mode 100644
index 0000000..e23e91c
--- /dev/null
+++ b/src/framework/event/epoll/eprb_tree.h
@@ -0,0 +1,82 @@
+/*
+*
+* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+* 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 _EPRB_TREE_H_
+#define _EPRB_TREE_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "types.h"
+#include "nsfw_mem_api.h"
+#ifdef __cplusplus
+/* *INDENT-OFF* */
+extern "C" {
+/* *INDENT-ON* */
+#endif
+
+#define EP_RB_RED 0
+#define EP_RB_BLACK 1
+
+struct ep_rb_node
+{
+ int color;
+
+ struct ep_rb_node *rb_parent;
+ struct ep_rb_node *rb_right;
+ struct ep_rb_node *rb_left;
+};
+
+/* The alignment might seem pointless, but allegedly CRIS needs it */
+
+struct ep_rb_root
+{
+ struct ep_rb_node *rb_node;
+};
+
+#define ep_rb_parent(r) ((struct ep_rb_node *)((r)->rb_parent))
+
+static inline void ep_rb_set_parent(struct ep_rb_node *rb,
+ struct ep_rb_node *p)
+{
+ rb->rb_parent = (struct ep_rb_node *) SHMEM_ADDR_LTOSH_EXT(p);
+}
+
+#define ep_rb_entry(ptr, type, member) container_of(ptr, type, member)
+
+extern void ep_rb_insert_color(struct ep_rb_node *, struct ep_rb_root *);
+extern void ep_rb_erase(struct ep_rb_node *, struct ep_rb_root *);
+struct ep_rb_node *ep_rb_first(const struct ep_rb_root *);
+
+static inline void ep_rb_link_node(struct ep_rb_node *node,
+ struct ep_rb_node *parent,
+ struct ep_rb_node **rb_link)
+{
+
+ node->rb_parent = (struct ep_rb_node *) SHMEM_ADDR_LTOSH_EXT(parent);
+ node->rb_left = node->rb_right = NULL;
+
+ *rb_link = (struct ep_rb_node *) SHMEM_ADDR_LTOSH_EXT(node);
+ node->color = EP_RB_RED;
+
+}
+
+#ifdef __cplusplus
+/* *INDENT-OFF* */
+}
+/* *INDENT-ON* */
+#endif
+
+#endif