yu.dong | c33b307 | 2024-08-21 23:14:49 -0700 | [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) 2005 |
| 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 | * |
| 38 | * Filename: |
| 39 | * --------- |
| 40 | * lcd_lqueue.h |
| 41 | * |
| 42 | * Project: |
| 43 | * -------- |
| 44 | * Maui_Software |
| 45 | * |
| 46 | * Description: |
| 47 | * ------------ |
| 48 | * Light weight C Data structures library: Linear Queue. |
| 49 | * |
| 50 | * Author: |
| 51 | * ------- |
| 52 | * ------- |
| 53 | * |
| 54 | *============================================================================ |
| 55 | * HISTORY |
| 56 | * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 57 | *------------------------------------------------------------------------------ |
| 58 | * removed! |
| 59 | * removed! |
| 60 | * removed! |
| 61 | * |
| 62 | * removed! |
| 63 | * removed! |
| 64 | * removed! |
| 65 | * |
| 66 | * removed! |
| 67 | * removed! |
| 68 | * removed! |
| 69 | * |
| 70 | * removed! |
| 71 | * removed! |
| 72 | * removed! |
| 73 | * |
| 74 | * removed! |
| 75 | * removed! |
| 76 | * removed! |
| 77 | * |
| 78 | * removed! |
| 79 | * removed! |
| 80 | * removed! |
| 81 | * |
| 82 | * removed! |
| 83 | * removed! |
| 84 | * removed! |
| 85 | * |
| 86 | * removed! |
| 87 | * removed! |
| 88 | * removed! |
| 89 | * |
| 90 | * removed! |
| 91 | * removed! |
| 92 | * removed! |
| 93 | * |
| 94 | * removed! |
| 95 | * removed! |
| 96 | * removed! |
| 97 | * |
| 98 | * removed! |
| 99 | * removed! |
| 100 | * removed! |
| 101 | * removed! |
| 102 | * removed! |
| 103 | * removed! |
| 104 | * removed! |
| 105 | * removed! |
| 106 | * removed! |
| 107 | * removed! |
| 108 | * removed! |
| 109 | * removed! |
| 110 | * removed! |
| 111 | *------------------------------------------------------------------------------ |
| 112 | * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 113 | *============================================================================ |
| 114 | ****************************************************************************/ |
| 115 | |
| 116 | /********************************************************************* |
| 117 | (C) _____ (year of first publication) Sasken communication |
| 118 | Technologies Limited, All rights reserved. |
| 119 | * This file provides a template for .c files. This space |
| 120 | * should be used to describe the file contents |
| 121 | * Component-specific prefix : xxxx |
| 122 | *********************************************************************/ |
| 123 | |
| 124 | #ifndef _LCD_LQUEUE_H |
| 125 | #define _LCD_LQUEUE_H |
| 126 | /*RHR*/ |
| 127 | #include "kal_general_types.h" |
| 128 | //#include "stacklib.h" |
| 129 | #include "lcd.h" |
| 130 | #include "kal_public_api.h" |
| 131 | /*RHR*/ |
| 132 | /************************************************************************* |
| 133 | * Macros Without Parameters |
| 134 | *************************************************************************/ |
| 135 | #define BIN_OVERHEAD 2 |
| 136 | |
| 137 | /************************************************************************* |
| 138 | * Data structure definition |
| 139 | *************************************************************************/ |
| 140 | typedef enum { |
| 141 | NOT_SET, |
| 142 | BY_FN_P, |
| 143 | BY_USR_MEM |
| 144 | }mem_for_items; |
| 145 | |
| 146 | /************************************************************************* |
| 147 | * Arbitrary Size Linear Queue |
| 148 | *************************************************************************/ |
| 149 | |
| 150 | /* This queue works by maintaining a doubly linked list of bins of |
| 151 | * size bin_size, when the current bin is full a new bin is allocated |
| 152 | * and chained to the end of the current bin. Likewise when the last |
| 153 | * item in a bin is removed and the next bin is there, the current |
| 154 | * bin is freed and the head is moved to the first item in the next |
| 155 | * bin. See figure given bellow. |
| 156 | * |
| 157 | * ____ ____ ____ ____ |
| 158 | * | | | | | | | | |
| 159 | * |____| |____| |____| |____| |
| 160 | * head ->| | | | | | | | |
| 161 | * |____| |____| |____| |____| |
| 162 | * | | | | | | | | <- tail |
| 163 | * |____| |____| |____| |____| |
| 164 | * | | | | | | | | |
| 165 | * |____|<---|____|<---|____|<---|____| |
| 166 | * | | | | | | | | |
| 167 | * |____| |____| |____| |____| |
| 168 | * |______^ |______^ |_______^ |
| 169 | * |
| 170 | */ |
| 171 | |
| 172 | typedef void * * lcd_lqueue_bin; |
| 173 | |
| 174 | typedef struct lcd_lqueue { |
| 175 | unsigned int bin_size; |
| 176 | /* The first bin. */ |
| 177 | lcd_lqueue_bin start; |
| 178 | /* The position of the head within the bin. */ |
| 179 | unsigned int head; |
| 180 | /* The last bin. */ |
| 181 | lcd_lqueue_bin end; |
| 182 | /* The position of the tail within the bin. */ |
| 183 | unsigned int tail; |
| 184 | /* Number of bins allocated so far. */ |
| 185 | unsigned int bin_count; |
| 186 | /* Indicates the type of memory for items. */ |
| 187 | mem_for_items item_mem; |
| 188 | kal_bool is_empty; |
| 189 | malloc_fp_t alloc_fn_p; |
| 190 | free_fp_t free_fn_p; |
| 191 | } lcd_lqueue; |
| 192 | |
| 193 | /************************************************************************* |
| 194 | * Exported Function Prototypes |
| 195 | *************************************************************************/ |
| 196 | extern void lcd_lqueue_init(unsigned int bin_size, |
| 197 | malloc_fp_t alloc_fn_p, |
| 198 | free_fp_t free_fn_p, |
| 199 | lcd_lqueue *q); |
| 200 | |
| 201 | extern kal_uint32 lcd_lqueue_mem_size(unsigned int bin_size); |
| 202 | |
| 203 | extern kal_bool lcd_lqueue_insert_at_rear(lcd_lqueue *q, |
| 204 | void *item); |
| 205 | |
| 206 | extern kal_bool lcd_lqueue_insert_at_front(lcd_lqueue *q, |
| 207 | void *item); |
| 208 | |
| 209 | /* The following function will be removed once variable |
| 210 | * length array is implemented. |
| 211 | */ |
| 212 | extern void *lcd_lqueue_remove(lcd_lqueue *q, void **mem_to_free); |
| 213 | |
| 214 | extern void *lcd_lqueue_remove_rear(lcd_lqueue *q, void **mem_to_free); |
| 215 | |
| 216 | extern kal_bool lcd_lqueue_is_empty(lcd_lqueue *q); |
| 217 | |
| 218 | extern unsigned int lcd_lqueue_num_of_items(lcd_lqueue *q); |
| 219 | |
| 220 | extern void *lcd_lqueue_index(lcd_lqueue *q, unsigned int idx); |
| 221 | |
| 222 | extern void lcd_lqueue_map(lcd_lqueue *q, lcd_mapfunc f, void *info); |
| 223 | |
| 224 | /* The following function is a conditional map function |
| 225 | * which stop mapping items when function 'f' returns |
| 226 | * KAL_FALSE.If mapping is done for all items, it returns |
| 227 | * KAL_TRUE, else returns KAL_FALSE. |
| 228 | */ |
| 229 | extern kal_bool lcd_lqueue_cmap(lcd_lqueue *q, lcd_cmapfunc f, void *info); |
| 230 | |
| 231 | extern void lcd_lqueue_delete_all(lcd_lqueue *q); |
| 232 | |
| 233 | #ifdef _DEBUG_LCD_LQUEUE |
| 234 | extern void lcd_lqueue_print(lcd_lqueue *q); |
| 235 | #endif |
| 236 | #endif /* _LCD_LQUEUE_H */ |
| 237 | |
| 238 | |