source: svn/newcon3bcm2_21bu/BSEAV/lib/scte65/si_list.h

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 9.8 KB
Line 
1/***************************************************************
2**
3** Broadcom Corp. Confidential
4** Copyright 2003-2008 Broadcom Corp. All Rights Reserved.
5**
6** THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED
7** SOFTWARE LICENSE AGREEMENT BETWEEN THE USER AND BROADCOM.
8** YOU HAVE NO RIGHT TO USE OR EXPLOIT THIS MATERIAL EXCEPT
9** SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
10**
11** File:                si_list.h
12** Description: defines and function prototypes for general list
13**                              functions that can be used in SI processing.
14**
15** Created: 03/08/2001
16**
17** REVISION:
18**
19** $Log: $
20**
21**
22****************************************************************/
23#ifndef SI_LIST_H
24#define SI_LIST_H
25
26
27/*================== Module Overview =====================================
28This modules defines macros to control doubly linked list.
29All operations are typesafe (doesn't required typecasting) and constant time.
30
31This list allow:
32  o Insert a new entry at the head of the list
33  o Insert a new entry after/before any element in the list
34  o O(1) removal of any entry in the list
35  o Forward/Backward traversal through the list
36  o Each element requires two pointers
37  o Code size and execution time is about twice that for singly-linked list
38 
39========================================================================*/
40
41 
42/***************************************************************************
43Summary:
44    Creates new data type for the list head
45   
46Description:
47    Creates new data type for the list head, this type used to create
48variable for the lists head.
49    User should create new the list head data type for every different
50element datatype.
51   
52Input:
53   name - name for the new data type (structure)
54    type - existing user data type used for element of the list
55
56Example:   
57     SI_LST_D_HEAD(block_head, block);
58     struct block_head  head;
59
60Returns:
61    <none>
62****************************************************************************/
63#define SI_LST_D_HEAD(name, type) struct name { struct type *l_first; }
64
65/***************************************************************************
66Summary:
67    Defines links entry
68   
69Description:
70    Defines entrys for the list inside the user structure.for the element.
71   
72Input:
73    type - the datatype for element
74
75Example:
76     struct block {
77        SI_LST_D_ENTRY(block) link;
78        char string[256];
79     }; 
80
81Returns:
82    <none>
83****************************************************************************/
84#define SI_LST_D_ENTRY(type)  struct { struct type *l_next, *l_prev; }
85
86/***************************************************************************
87Summary:
88    Initializes lists head
89   
90Description:
91    Initializes the head of the list. The head shall be initialized before
92list can be used.
93    This macro used for dynamic initialization.
94   
95Input:
96    head - pointer to the list head
97
98See also:
99    SI_LST_D_INITIALIZER
100
101Example:
102    SI_LST_D_INIT(&head);
103
104Returns:
105    <none>
106****************************************************************************/
107#define SI_LST_D_INIT(head) ((head)->l_first=NULL)
108
109
110/***************************************************************************
111Summary:
112    Initializes link entry
113   
114Description:
115    Initializes the link entry. The entry shall be initialized before
116link can be used.
117    This macro used for dynamic initialization.
118   
119Input:
120    entry - pointer to the link entry
121
122See also:
123   
124
125Example:
126    SI_LST_D_INIT_ENTRY(&entry);
127
128Returns:
129    <none>
130****************************************************************************/
131#define SI_LST_D_INIT_ENTRY(entry) ((entry)->l_next=(entry)->l_prev=NULL)
132
133
134/***************************************************************************
135Summary:
136    Initializes lists head
137   
138Description:
139    Initializes the head of the list. The head shall be initialized before
140list can be used.
141    This macro used for static initialization.
142   
143Input:
144    head - pointer to the list head
145
146See also:
147    SI_LST_D_INIT
148
149Example:
150    static struct block_head  head = SI_LST_D_INITIALIZER(head);
151
152Returns:
153    <none>
154****************************************************************************/
155#define SI_LST_D_INITIALIZER(head) {NULL}
156
157/***************************************************************************
158Summary:
159    Tests if list is empty
160   
161Description:
162    Tests if list is empty.
163   
164Input:
165    head - pointer to the list head
166
167Returns:
168    true - list empty
169    false - list has elements
170
171Example:
172    if (SI_LST_D_EMPTY(&head) { return ; }
173
174****************************************************************************/
175#define SI_LST_D_EMPTY(head) ((head)->l_first == NULL)
176
177/***************************************************************************
178Summary:
179    Returns the lists first element
180   
181Description:
182    Returns pointer to the first element from the list
183   
184Input:
185    head - pointer to the list head
186
187Returns:
188    pointer to the first element from the list.
189
190Example:
191    struct block *first=SI_LST_D_FIRST(&head);
192****************************************************************************/
193#define SI_LST_D_FIRST(head) ((head)->l_first)
194
195/***************************************************************************
196Summary:
197    Returns next element from the lists
198   
199Description:
200    Returns pointer to the next element from the list
201   
202Input:
203    elm - pointer to the list element
204    field - name of the elements link field
205
206Returns:
207    pointer to the next element from the list
208
209Example:
210    struct block *second=SI_LST_D_NEXT(first);
211****************************************************************************/
212#define SI_LST_D_NEXT(elm, field) ((elm)->field.l_next)
213
214/***************************************************************************
215Summary:
216    Returns next element from the lists
217   
218Description:
219    Returns pointer to the previous element from the list
220   
221Input:
222    elm - pointer to the list element
223    field - name of the elements link field
224
225Returns:
226    pointer to the previous element from the list
227
228Example:
229    struct block *first=SI_LST_D_PREV(second);
230****************************************************************************/
231#define SI_LST_D_PREV(elm, field) ((elm)->field.l_prev)
232
233/***************************************************************************
234Summary:
235    Inserts element into the list
236   
237Description:
238    Inserts new element into the head of the list.
239   
240Input:
241    head - pointer to the list head
242    elm - pointer to the new element
243    field - name of the elements link field
244
245Returns:
246    <none>
247
248Example:
249    SI_LST_D_INSERT_HEAD(&head, new_block, link);
250****************************************************************************/
251#define SI_LST_D_INSERT_HEAD(head, elm, field) do { \
252                        if ( ((elm)->field.l_next = (head)->l_first) != NULL ) \
253                                (head)->l_first->field.l_prev = (elm); \
254                        (head)->l_first = (elm); \
255                        (elm)->field.l_prev = NULL; \
256                }  while(0)
257
258/***************************************************************************
259Summary:
260    Inserts element into the list
261   
262Description:
263    Inserts new element after existing element.
264   
265Input:
266    elm - pointer to the element from the list
267    new_elm - pointer to the new element
268    field - name of the elements link field
269
270Returns:
271    <none>
272
273Example:
274    SI_LST_D_INSERT_AFTER(first, second, link);
275****************************************************************************/
276#define SI_LST_D_INSERT_AFTER(elm, new_elm, field) do { \
277                        (new_elm)->field.l_prev = (elm); \
278                        if (((new_elm)->field.l_next = elm->field.l_next)!=NULL) \
279                                elm->field.l_next->field.l_prev = new_elm; \
280                        (elm)->field.l_next = (new_elm); \
281                } while(0)
282
283/***************************************************************************
284Summary:
285    Inserts element into the list
286   
287Description:
288    Inserts new element after existing element.
289   
290Input:
291    head - pointer to the list head
292    elm - pointer to the element from the list
293    new_elm - pointer to the new element
294    field - name of the elements link field
295
296Returns:
297    <none>
298
299Example:
300    SI_LST_D_INSERT_BEFORE(&head, second, first, link);
301****************************************************************************/
302#define SI_LST_D_INSERT_BEFORE(head, elm, new_elm, field) do {  \
303                        (new_elm)->field.l_next = (elm);  \
304                        if (((new_elm)->field.l_prev = (elm)->field.l_prev)!=NULL) \
305                                elm->field.l_prev->field.l_next = new_elm; \
306                        else \
307                                (head)->l_first = (new_elm); \
308                        (elm)->field.l_prev = (new_elm); \
309                } while(0)
310
311   
312
313/***************************************************************************
314Summary:
315    Removes element from the list
316   
317Description:
318    Removes element from the list.
319   
320Input:
321    head - pointer to the list head
322    elm - pointer to the list element
323    field - name of the elements link field
324
325See also:
326    SI_LST_D_REMOVE_HEAD
327
328Returns:
329    <none>
330
331Example:
332    SI_LST_D_REMOVE(&head, first, link);
333****************************************************************************/
334#define SI_LST_D_REMOVE(head, elm, field) do { \
335                        if ((elm)->field.l_next) \
336                                (elm)->field.l_next->field.l_prev = (elm)->field.l_prev; \
337                        if ((elm)->field.l_prev) \
338                                (elm)->field.l_prev->field.l_next = (elm)->field.l_next; \
339                        else \
340                                (head)->l_first = (elm)->field.l_next; \
341                } while(0)
342
343
344/***************************************************************************
345Summary:
346    Removes element from the list
347   
348Description:
349    Removes element from the head of the list.
350   
351Input:
352    head - pointer to the list head
353    field - name of the elements link field
354
355See also:
356    SI_LST_D_REMOVE
357
358Returns:
359    <none>
360
361Example:
362    SI_LST_D_REMOVE_HEAD(&head, first, link);
363****************************************************************************/
364#define SI_LST_D_REMOVE_HEAD(head, field) do { \
365                        (head)->l_first = (head)->l_first->field.l_next;  \
366                        if ((head)->l_first) \
367                        { \
368                                (head)->l_first->field.l_prev = NULL;\
369                        } \
370                } while(0)
371
372
373
374
375#endif
376
Note: See TracBrowser for help on using the repository browser.