• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define HUKS_DISABLE_LOG_AT_FILE_TO_REDUCE_ROM_SIZE
16 
17 #include "hks_double_list.h"
18 
19 #ifndef NULL
20 #define NULL ((void *)0)
21 #endif
22 
InitializeDoubleList(struct DoubleList * node)23 void InitializeDoubleList(struct DoubleList *node)
24 {
25     if (node == NULL) {
26         return;
27     }
28 
29     node->prev = node;
30     node->next = node;
31 }
32 
AddNodeAfterDoubleListHead(struct DoubleList * head,struct DoubleList * node)33 void AddNodeAfterDoubleListHead(struct DoubleList *head, struct DoubleList *node)
34 {
35     if ((head == NULL) || (node == NULL)) {
36         return;
37     }
38 
39     if (head->next == NULL) {
40         head->next = head;
41     }
42 
43     head->next->prev = node;
44     node->next = head->next;
45     node->prev = head;
46     head->next = node;
47 }
48 
AddNodeAtDoubleListTail(struct DoubleList * head,struct DoubleList * node)49 void AddNodeAtDoubleListTail(struct DoubleList *head, struct DoubleList *node)
50 {
51     if ((head == NULL) || (node == NULL)) {
52         return;
53     }
54 
55     if (head->prev == NULL) {
56         head->prev = head;
57     }
58 
59     head->prev->next = node;
60     node->next = head;
61     node->prev = head->prev;
62     head->prev = node;
63 }
64 
RemoveDoubleListNode(struct DoubleList * node)65 void RemoveDoubleListNode(struct DoubleList *node)
66 {
67     if (node == NULL) {
68         return;
69     }
70 
71     if (node->next != NULL) {
72         node->next->prev = node->prev;
73     }
74 
75     if (node->prev != NULL) {
76         node->prev->next = node->next;
77     }
78 
79     node->prev = NULL;
80     node->next = NULL;
81 }
82 
83