1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HKS_DOUBLE_LIST_H 17 #define HKS_DOUBLE_LIST_H 18 19 struct DoubleList { 20 struct DoubleList *prev; 21 struct DoubleList *next; 22 }; 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 void InitializeDoubleList(struct DoubleList *node); 29 30 void AddNodeAfterDoubleListHead(struct DoubleList *head, struct DoubleList *node); 31 32 void AddNodeAtDoubleListTail(struct DoubleList *head, struct DoubleList *node); 33 34 void RemoveDoubleListNode(struct DoubleList *node); 35 36 #ifdef __cplusplus 37 } 38 #endif 39 40 /* 41 * HKS_DLIST_ITER - iterate over double list of struct st, double list should be the first member of struct st 42 * @st: the struct in the double list 43 * @head: the head for double list. 44 */ 45 #define HKS_DLIST_ITER(st, head) \ 46 struct DoubleList *p = NULL; \ 47 if ((void*)(head) != NULL) { \ 48 p = (head)->next; \ 49 (st) = (__typeof__(st))p; \ 50 } \ 51 for (; p != NULL && p != (head); p = p->next, (st) = (__typeof__(st))p) 52 53 #define HKS_DLIST_SAFT_ITER(st, head) \ 54 struct DoubleList *p = NULL; \ 55 struct DoubleList _tmp = { NULL, NULL }; \ 56 for (p = (head)->next, (st) = (__typeof__(st))p, _tmp = *p; p != (head); \ 57 p = _tmp.next, _tmp = *p, (st) = (__typeof__(st))p) 58 59 #endif 60