source: svn/newcon3bcm2_21bu/nexus/app/genericlist.c @ 76

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

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

  • Property svn:executable set to *
File size: 5.2 KB
Line 
1/*****************************************************************************
2 *
3 *  @File:   LIST.C - C Based List C File
4 *  @Author: Marcus Kellerman
5 *
6 *  Broadcom Corporation Confidential
7 *  Copyright 2000 - All Rights Reserved.
8 *
9 ****************************************************************************/
10
11#include "genericlist.h"
12
13/*******************************************************************************
14** External Functions
15*******************************************************************************/
16
17/*******************************************************************************
18** Name:            initl
19** Description:     Initialize a list.
20**
21** In:  p_list      pointer to a list.
22** Out: None.
23** Ret: None.
24*******************************************************************************/
25void initl(LIST_T *p_list)
26{
27        if( !p_list )
28                return;
29
30    p_list->origin_links.p_next = (LINKS_T *)p_list;
31    p_list->origin_links.p_prev = (LINKS_T *)p_list;
32    p_list->origin_links.p_origin = (LINKS_T *)p_list;   
33    p_list->count = 0;
34}
35
36
37/*******************************************************************************
38** Name:            inslt
39** Description:     Insert an element to the tail of a list.
40**
41** In:  p_list      Pointer to a list.
42**      p_element   Pointer to an element.
43** Out: None.
44** Ret: None.
45*******************************************************************************/
46void inslt(LIST_T *p_list, void *p_element)
47{
48        if( !p_list || !p_element )
49                return;
50
51    ((LINKS_T *)p_element)->p_origin = (LINKS_T *)p_list;
52    ((LINKS_T *)p_element)->p_next = p_list->origin_links.p_prev->p_next;       
53    ((LINKS_T *)p_element)->p_prev = p_list->origin_links.p_prev;               
54    ((LINKS_T *)(p_list->origin_links.p_prev))->p_next = (LINKS_T *)p_element;
55    p_list->origin_links.p_prev  = (LINKS_T *)p_element;
56    p_list->count++;
57}
58
59/*******************************************************************************
60** Name:            inslh
61** Description:     Insert an element to the head of a list.
62**
63** In:  p_list      Pointer to a list.
64**      p_element   Pointer to an element.
65** Out: None.
66** Ret: None.
67*******************************************************************************/
68void inslh(LIST_T *p_list, void *p_element)
69{
70        if( !p_list || !p_element )
71                return;
72
73    ((LINKS_T *)p_element)->p_origin = (LINKS_T *)p_list;
74    ((LINKS_T *)p_element)->p_next = p_list->origin_links.p_next;
75    ((LINKS_T *)p_element)->p_prev = p_list->origin_links.p_next->p_prev;
76    ((LINKS_T *)(p_list->origin_links.p_next))->p_prev = (LINKS_T *)p_element;
77    p_list->origin_links.p_next = (LINKS_T *)p_element;
78    p_list->count++;
79}
80
81/*******************************************************************************
82** Name:            remlh
83** Description:     Remove an element from the head of a list.
84**
85** In:  p_list      Pointer to a list.
86** Out: None.
87** Ret: Pointer to the removed element, if it exists.  Otherwise return 0.
88*******************************************************************************/
89void *remlh(LIST_T *p_list)
90{
91        if( !p_list )
92                return 0;
93
94    if (p_list->count)
95    {
96        LINKS_T *p_element = p_list->origin_links.p_next;
97
98        /* Update the list's next pointer. */
99        ((LINKS_T *)p_list)->p_next = ((LINKS_T *)p_list)->p_next->p_next;
100
101        /* Update the previous pointer for the new head of the list. */
102        ((LINKS_T *)p_list)->p_next->p_prev = (LINKS_T *)p_list;
103
104        /* Decrement the count. */
105        p_list->count--;
106
107        /* Return a pointer to the newly removed element. */
108        return p_element;
109    }
110    else
111    {
112        /* The list is empty, return a pointer to 0. */
113        return 0;
114    }
115}
116
117/*******************************************************************************
118** Name:            reml
119** Description:     Remove an element from anywhere on a list.
120**
121** In:  p_list      Pointer to a list.
122**      p_element   Pointer to an element in that list.
123** Out: None.
124** Ret: None.
125*******************************************************************************/
126void reml(LIST_T *p_list, void *p_element)
127{
128        if( !p_list || !p_element )
129                return;
130
131    (((LINKS_T *)p_element)->p_prev)->p_next = ((LINKS_T *)p_element)->p_next; 
132    (((LINKS_T *)p_element)->p_next)->p_prev = ((LINKS_T *)p_element)->p_prev; 
133    p_list->count--;
134}
135
136/*******************************************************************************
137** Name:            inslb
138** Description:     Insert an element before another element in the list.
139**
140** In:  p_list      Pointer to a list.
141**      p_element   Pointer to an element in that list.
142**              p_newElement    Pointer to the element to insert
143** Out: None.
144** Ret: None.
145*******************************************************************************/
146void inslb(LIST_T *p_list, void *p_element, void *p_newElement)
147{
148        if( !p_list || !p_element || !p_newElement )
149                return;
150
151        ((LINKS_T *)p_newElement)->p_origin = (LINKS_T *)p_list;
152        ((LINKS_T *)p_newElement)->p_next = (LINKS_T *)p_element;
153        ((LINKS_T *)p_newElement)->p_prev = ((LINKS_T *)p_element)->p_prev;
154
155        (((LINKS_T *)p_element)->p_prev)->p_next = (LINKS_T *)p_newElement;
156        ((LINKS_T *)p_element)->p_prev = (LINKS_T *)p_newElement;
157        p_list->count++;
158}
Note: See TracBrowser for help on using the repository browser.