diff options
author | qchang <qing.chang1@huawei.com> | 2018-03-08 17:39:22 -0800 |
---|---|---|
committer | qchang <qing.chang1@huawei.com> | 2018-03-08 17:39:22 -0800 |
commit | 697ade6190b23c80e7f60963983786e679759393 (patch) | |
tree | dd9782d1e936b8342163b26795e23571d4b1b415 /src/framework/common/include/ephlist.h | |
parent | 71a4e2f34afa8018426f0e830050e50a1de6d375 (diff) |
dmm initial commit
Change-Id: I049ee277cf4efdb83f9c2ac439365fcd421c159b
Signed-off-by: qchang <qing.chang1@huawei.com>
Diffstat (limited to 'src/framework/common/include/ephlist.h')
-rw-r--r-- | src/framework/common/include/ephlist.h | 199 |
1 files changed, 199 insertions, 0 deletions
diff --git a/src/framework/common/include/ephlist.h b/src/framework/common/include/ephlist.h new file mode 100644 index 0000000..90491b0 --- /dev/null +++ b/src/framework/common/include/ephlist.h @@ -0,0 +1,199 @@ +/* +* +* 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 _EPHLIST_H_ +#define _EPHLIST_H_ + +#include <stdio.h> +#include "types.h" +#include "common_mem_pal.h" +#include "common_mem_buf.h" +#include "common_pal_bitwide_adjust.h" +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +struct ep_hlist_node +{ + struct ep_hlist_node *next, **pprev; +}; + +struct ep_node_list +{ + struct ep_hlist_node *head; + struct ep_hlist_node *tail; +}; + +struct ep_hlist +{ + struct ep_hlist_node node; + struct ep_hlist_node *head; + struct ep_hlist_node *tail; +}; + +#define ep_hlist_entry(ptr, type, member) container_of(ptr, type, member) + +#define EP_HLIST_INIT_NODE(node) {\ + (node)->next = NULL;\ + (node)->pprev = NULL; \ + } + +#define EP_HLIST_INIT(ptr) {\ + EP_HLIST_INIT_NODE(&((ptr)->node)); \ + (ptr)->head = (struct ep_hlist_node*)ADDR_LTOSH_EXT(&((ptr)->node)); \ + (ptr)->tail = (struct ep_hlist_node*)ADDR_LTOSH_EXT(&((ptr)->node)); \ + } + +#define EP_HLIST_PREV(ptr) ((struct ep_hlist_node*)(ADDR_SHTOL((ptr)->pprev))) +/* list check may below zero check header, because if app crash before + do list->size++, it will lead problem */ +#define EP_HLIST_EMPTY(list) (NULL == ((struct ep_hlist_node*)ADDR_SHTOL((list)->head))->next) +#define EP_HLIST_NODE_LINKED(node) (!(!(node)->pprev)) + +static __inline void ep_hlist_del (struct ep_hlist *list, + struct ep_hlist_node *n); +static __inline void ep_hlist_add_tail (struct ep_hlist *list, + struct ep_hlist_node *node); + +/* + * list , n are local pointer, don't need to cast + */ +static __inline void +ep_hlist_del (struct ep_hlist *list, struct ep_hlist_node *n) +{ + if (!EP_HLIST_NODE_LINKED (n)) + return; + EP_HLIST_PREV (n)->next = n->next; + if (n->next) + { + ((struct ep_hlist_node *) ADDR_SHTOL (n->next))->pprev = n->pprev; + } + else + { + list->tail = (struct ep_hlist_node *) (n->pprev); + } + EP_HLIST_INIT_NODE (n); +} + +/** + * list, node are local pointer , don't need to case + */ +static __inline void +ep_hlist_add_tail (struct ep_hlist *list, struct ep_hlist_node *node) +{ + struct ep_hlist_node *tail = + (struct ep_hlist_node *) ADDR_SHTOL (list->tail); + EP_HLIST_INIT_NODE (node); + node->pprev = (struct ep_hlist_node **) ADDR_LTOSH_EXT (&tail->next); + tail->next = (struct ep_hlist_node *) ADDR_LTOSH_EXT (node); + list->tail = (struct ep_hlist_node *) ADDR_LTOSH_EXT (node); +} + +/*#########################################################*/ +struct list_node +{ + struct list_node *next; +}; + +struct ep_list +{ + struct list_node node; + struct list_node *head; +}; + +#define ep_list_entry(ptr, type, member) container_of(ptr, type, member) + +#define EP_LIST_INIT_NODE(node) {\ + (node)->next = NULL;\ + } + +#define EP_LIST_INIT(ptr) {\ + EP_LIST_INIT_NODE(&((ptr)->node)); \ + (ptr)->head = (struct list_node*)ADDR_LTOSH_EXT(&((ptr)->node)); \ + } + +#define EP_LIST_EMPTY(list) (NULL == ((struct list_node*)ADDR_SHTOL((list)->head))->next) + +static __inline void ep_list_del (struct ep_list *list, struct list_node *n); +static __inline void ep_list_add_tail (struct ep_list *list, + struct list_node *node); + +/* + * list , n are local pointer, don't need to cast + */ +static __inline void +ep_list_del (struct ep_list *list, struct list_node *n) +{ + if (NULL == n) + { + return; + } + + struct list_node *p_node; + struct list_node *p_prev = NULL; + p_node = ((struct list_node *) ADDR_SHTOL (list->head)); + while (NULL != p_node && p_node != n) + { + p_prev = p_node; + p_node = ((struct list_node *) ADDR_SHTOL (p_node->next)); + } + + if (p_node != n || p_prev == NULL) + { + return; + } + + p_prev->next = n->next; + + EP_LIST_INIT_NODE (n); + return; +} + +/** + * list, node are local pointer , don't need to case + */ +static __inline void +ep_list_add_tail (struct ep_list *list, struct list_node *node) +{ + + struct list_node *p_node; + struct list_node *p_prev = NULL; + p_node = ((struct list_node *) ADDR_SHTOL (list->head)); + while (NULL != p_node) + { + p_prev = p_node; + p_node = ((struct list_node *) ADDR_SHTOL (p_node->next)); + } + + if (NULL == p_prev) + { + return; + } + + EP_LIST_INIT_NODE (node); + p_prev->next = (struct list_node *) ADDR_LTOSH_EXT (node); + return; +} + +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif + +#endif /* _HLIST_H_ */ |