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 CERT_MANAGER_DOUBLE_LIST_H 17 #define CERT_MANAGER_DOUBLE_LIST_H 18 19 #include "cm_type.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 struct DoubleList { 26 struct DoubleList *prev; 27 struct DoubleList *next; 28 }; 29 30 void CmInitList(struct DoubleList *listNode); 31 32 void CmAddNodeAfterListHead(struct DoubleList *listHead, struct DoubleList *listNode); 33 34 void CmAddNodeAtListTail(struct DoubleList *listHead, struct DoubleList *listNode); 35 36 void CmRemoveNodeFromList(struct DoubleList *listNode); 37 38 #ifdef __cplusplus 39 } 40 #endif 41 42 /* 43 * CM_DLIST_ITER - iterate over double list of struct st, double list should be the first member of struct st 44 * @st: the struct in the double list 45 * @head: the head for double list. 46 */ 47 #define CM_DLIST_ITER(st, head) \ 48 struct DoubleList *p = NULL; \ 49 for (p = (head)->next, (st) = (__typeof__(st))p; p != (head); p = p->next, (st) = (__typeof__(st))p) 50 51 #define CM_DLIST_SAFT_ITER(st, head) \ 52 struct DoubleList *p = NULL; \ 53 struct DoubleList tmp = { NULL, NULL }; \ 54 for (p = (head)->next, (st) = (__typeof__(st))p, tmp = *p; p != (head); \ 55 p = tmp.next, tmp = *p, (st) = (__typeof__(st))p) 56 57 #endif /* CERT_MANAGER_DOUBLE_LIST_H */ 58 59