rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1 | /***************************************************************************** |
| 2 | * Copyright Statement: |
| 3 | * -------------------- |
| 4 | * This software is protected by Copyright and the information contained |
| 5 | * herein is confidential. The software may not be copied and the information |
| 6 | * contained herein may not be used or disclosed except with the written |
| 7 | * permission of MediaTek Inc. (C) 2012 |
| 8 | * |
| 9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| 12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| 18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| 19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| 20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| 21 | * |
| 22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| 23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| 26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 27 | * |
| 28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| 29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| 30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| 31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| 32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| 33 | * |
| 34 | *****************************************************************************/ |
| 35 | |
| 36 | /******************************************************************************* |
| 37 | * Filename: |
| 38 | * --------- |
| 39 | * llist.h |
| 40 | * |
| 41 | * Project: |
| 42 | * -------- |
| 43 | * MOLY |
| 44 | * |
| 45 | * Description: |
| 46 | * ------------ |
| 47 | * |
| 48 | * |
| 49 | * Author: |
| 50 | * ------- |
| 51 | * ------- |
| 52 | * |
| 53 | * |
| 54 | * ========================================================================== |
| 55 | * $Log$ |
| 56 | * |
| 57 | * 07 26 2018 hubert.wang |
| 58 | * [MOLY00342443] [KAL] Coding convention |
| 59 | * |
| 60 | * [KAL] Coding Convention |
| 61 | * |
| 62 | * 05 02 2018 hubert.wang |
| 63 | * [MOLY00323821] [UMOLYE][LLIST] Add a new macro List_ForEachPrevSafe() for llist |
| 64 | * |
| 65 | * [UMOLYE][LLIST] Request by Aric Chiu |
| 66 | * |
| 67 | * 09 29 2017 tee-yuen.chun |
| 68 | * [MOLY00281026] [Gen93][Mlib_dll] Remove llist.c and use Mlib_dll to implement llist |
| 69 | * . Remove list.c and replace it with Mlib_dll |
| 70 | ****************************************************************************/ |
| 71 | /** |
| 72 | * @file llist.h |
| 73 | * @brief high efficient doubly "embedded" linked-list implementation |
| 74 | * |
| 75 | * @author Howard Chen, Moja Hsu ,HR Hsu |
| 76 | * |
| 77 | * @date 2006 , 7 |
| 78 | * |
| 79 | **/ |
| 80 | #ifndef LLIST0630 |
| 81 | #define LLIST0630 |
| 82 | |
| 83 | #include "mlib_dll.h" |
| 84 | |
| 85 | /** |
| 86 | * @brief the embedded linked list |
| 87 | */ |
| 88 | typedef list_node llist_t; |
| 89 | |
| 90 | #define LIST_Empty(ptr) ((ptr)->next == (ptr)) |
| 91 | |
| 92 | /** |
| 93 | * @brief the llist_t initializator |
| 94 | */ |
| 95 | #define LIST_VALUE(name) \ |
| 96 | { \ |
| 97 | &(name), &(name) \ |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * @brief the llist_t constructor |
| 102 | */ |
| 103 | #define LIST_Init(ptr) mlib_dll_insert_at_end(NULL, ptr) |
| 104 | |
| 105 | /** |
| 106 | * @brief Insert a _new entry after the specified head. |
| 107 | * @param _new _new entry to be added |
| 108 | * @param head list head to add it after |
| 109 | * |
| 110 | */ |
| 111 | #define LIST_Add(new_ptr, head_ptr) mlib_dll_insert_at_start(head_ptr, new_ptr) |
| 112 | |
| 113 | /** |
| 114 | * @brief Insert a _new entry before the specified head. |
| 115 | * @param _new: _new entry to be added |
| 116 | * @param head: list head to add it before |
| 117 | * |
| 118 | */ |
| 119 | #define LIST_AddTail(new_ptr, head_ptr) mlib_dll_insert_at_end(head_ptr, new_ptr) |
| 120 | |
| 121 | /** |
| 122 | * @brief deletes entry from list. |
| 123 | * @param entry: the element to delete from the list. |
| 124 | * @note: list_empty on entry does not return true after this, the entry is in an undefined state. |
| 125 | */ |
| 126 | #define LIST_Del(entry) mlib_dll_delete(NULL, entry) |
| 127 | |
| 128 | /** |
| 129 | * @brief deletes entry from list and reinitialize it. |
| 130 | * @param entry: the element to delete from the list. |
| 131 | */ |
| 132 | #define LIST_DelInit(entry) \ |
| 133 | do { \ |
| 134 | LIST_Del(entry); \ |
| 135 | LIST_Init(entry); \ |
| 136 | } while (0) |
| 137 | |
| 138 | /** |
| 139 | * @brief get the struct for this entry |
| 140 | * @param ptr the &struct list_head pointer. |
| 141 | * @param type the type of the struct this is embedded in. |
| 142 | * @param member the name of the list_struct within the struct. |
| 143 | */ |
| 144 | #define LIST_Entry(ptr, type, member) List2Container(ptr, type, member) |
| 145 | |
| 146 | /** |
| 147 | * @brief iterate over a list |
| 148 | * @param pos the &struct list_head to use as a loop counter. |
| 149 | * @param head the head for your list. |
| 150 | */ |
| 151 | #define LIST_ForEach(pos, head) \ |
| 152 | for (pos = (head)->next; pos != (head); pos = pos->next) |
| 153 | |
| 154 | /** |
| 155 | * @brief iterate over a list safe against removal of list entry |
| 156 | * @param pos the &struct list_head to use as a loop counter. |
| 157 | * @param n another &struct list_head to use as temporary storage |
| 158 | * @param head the head for your list. |
| 159 | */ |
| 160 | #define LIST_ForEachSafe(pos, n, head) \ |
| 161 | for (pos = (head)->next, n = pos->next; pos != (head); pos = n, n = pos->next) |
| 162 | |
| 163 | /** |
| 164 | * @brief LIST_for_each_prev - iterate over a list in reverse order |
| 165 | * @param pos the &struct list_head to use as a loop counter. |
| 166 | * @param head the head for your list. |
| 167 | */ |
| 168 | #define LIST_ForEachPrev(pos, head) \ |
| 169 | for (pos = (head)->prev; pos != (head); pos = pos->prev) |
| 170 | |
| 171 | /** |
| 172 | * @brief iterate over a list safe against removal of list entry |
| 173 | * @param pos the &struct list_head to use as a loop counter. |
| 174 | * @param n another &struct list_head to use as temporary storage |
| 175 | * @param head the head for your list. |
| 176 | */ |
| 177 | #define LIST_ForEachPrevSafe(pos, n, head) \ |
| 178 | for (pos = (head)->prev, n = pos->prev; pos != (head); pos = n, n = pos->prev) |
| 179 | |
| 180 | /** |
| 181 | * @brief Get the first of the linked list |
| 182 | */ |
| 183 | #define LIST_GetFirst(head, type, member) \ |
| 184 | (((head)->next != (head)) ? (LIST_Entry((head)->next, type, member)) : (NULL)) |
| 185 | |
| 186 | |
| 187 | #endif |