9a73cb1278e394c1e730f39f512530e5b5b70136
[o-du/l2.git] / src / 5gnrsch / rg_sch_utl_clist.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /********************************************************************20**
20   
21      Name:     common functions - linked list management
22   
23      Type:     C source file
24   
25      Desc:     common functions for linked lists
26   
27      File:     rg_sch_utl_clist.c
28   
29 *********************************************************************21*/
30   
31 /* header include files (.h) */
32 #include "common_def.h"
33
34 /* header/extern include files (.x) */
35 #include "rg_sch_clist.x"      /* common functions */
36
37
38 /* Linked List functions */
39
40
41 /*
42 *
43 *       Fun:   rgSCHRrCListInit
44 *
45 *       Desc:  initializes a linked list control pointer.
46 *
47 *       Ret:   ROK   - ok
48 *
49 *       Notes: None
50 *
51 *       File:  rr_clist.c
52 *
53 */
54 Void rgSCHRrCListInit
55 (
56 RgSchRrCListCp *lCp                /* list control point */
57 )
58 {
59    
60    lCp->first = (RgSchRrCList *)NULLP;
61    lCp->crnt  = (RgSchRrCList *)NULLP;
62    lCp->count = 0;
63
64    return;
65 } /* end of rgSCHRrCListInit */
66
67 /* LTE_ADV_FLAG_REMOVED_START */
68 /*
69  *        Fun:   rgSCHRrCListAdd2Crnt
70  * 
71  *        Desc:  adds node to linked list behind crnt.
72  * 
73  *        Ret:   ROK   - ok
74  * 
75  *        Notes: None
76  * 
77  *        File:  rr_clist.c
78  */
79 Void rgSCHRrCListAdd2Crnt
80 (
81 RgSchRrCListCp *lCp,               /* list control point */
82 RgSchRrCList   *node               /* node to be added */
83 )
84 {
85 #ifdef ERRCHK
86    if (lCp == (RgSchRrCListCp *)NULLP)
87       return;
88 #endif
89
90    lCp->count++;
91
92    if(!lCp->first)
93    {
94       node->prev = node;
95       node->next = node;
96       lCp->first = node;
97
98       lCp->crnt = lCp->first;
99
100       return;
101    }
102
103    node->next = lCp->crnt;
104    node->prev = lCp->crnt->prev;
105    lCp->crnt->prev->next = node;
106    lCp->crnt->prev = node;
107
108    return;
109 }
110 /* LTE_ADV_FLAG_REMOVED_END */
111
112 /*
113 *
114 *       Fun:   rgSCHRrCListAdd2Tail
115 *
116 *       Desc:  adds node to linked list after last.
117 *
118 *       Ret:   ROK   - ok
119 *
120 *       Notes: None
121 *
122 *       File:  rr_clist.c
123 *
124 */
125 Void rgSCHRrCListAdd2Tail
126 (
127 RgSchRrCListCp *lCp,               /* list control point */
128 RgSchRrCList   *node               /* node to be added */
129 )
130 {
131
132 #ifdef ERRCHK
133    if (lCp == (RgSchRrCListCp *)NULLP)
134       return;
135 #endif
136  
137    lCp->count++;
138
139    if(!lCp->first)
140    {
141       node->prev = node;
142       node->next = node;
143       lCp->first = node;
144
145       lCp->crnt = lCp->first;
146
147       return;
148    }
149
150    node->next = lCp->first;
151    node->prev = lCp->first->prev;
152    lCp->first->prev->next = node;
153    lCp->first->prev = node;
154
155    return;
156 } /* end of rgSCHRrCListAdd2Tail */
157
158 /*
159 *
160 *       Fun:   rgSCHRrCListDelFrm
161 *
162 *       Desc:  remove node pointed to by nodePtr from list and return node.
163 *              nodePtr could be anywhere in the list.
164 *              - resets crnt to NULLP.
165 *
166 *       Ret:   pointer
167 *
168 *       Notes: None
169 *
170 *       File:  rr_clist.c
171 *
172 */
173 RgSchRrCList *rgSCHRrCListDelFrm
174 (
175 RgSchRrCListCp *lCp,                /* list control pointer */
176 RgSchRrCList *node                  /* node to be removed */
177 )
178 {
179   
180 #ifdef ERRCHK
181    if (lCp == (RgSchRrCListCp *)NULLP)
182       return (NULLP);
183 #endif
184
185    if(lCp->count == 0)
186    {
187       return (NULLP);
188    }
189    if (lCp->count == 1)
190    {
191       if(lCp->first == node)
192       {
193          lCp->first = lCp->crnt = (RgSchRrCList *)NULLP;
194          lCp->count = 0;
195          node->next = node->prev = (RgSchRrCList *)NULLP;
196          return (node);
197       }
198       return (NULLP);
199    }
200    
201    if (lCp->first == node)
202    {
203       lCp->first->prev->next = node->next;
204       node->next->prev = lCp->first->prev;
205       lCp->first = node->next;
206       if(lCp->crnt == node)
207       {
208          lCp->crnt = node->next;
209       }
210       node->next = node->prev = (RgSchRrCList *)NULLP;
211        /* Adding this check and guarding the decrement of counter when
212        node is deleted with reshuffling */
213       lCp->count--;
214       return (node);
215    }
216
217    if(node->prev && node->next)
218    {
219       node->prev->next = node->next;
220       node->next->prev = node->prev;
221       lCp->count--;
222    }
223    if(lCp->crnt == node)
224    {
225       lCp->crnt = node->next;
226    }
227    node->next = node->prev = (RgSchRrCList *)NULLP;
228    return (node);
229 } /* end of rgSCHRrCListDelFrm */
230
231 /*
232 *
233 *       Fun:   rgSCHRrCListInsrtAtCrnt
234 *
235 *       Desc:  Inserting the given node at CuRRENT and Moving present CURRENT 
236 *              node to next.
237 *
238 *       Ret:   None
239 *
240 *       Notes: None
241 *
242 *       File:  rr_clist.c
243 *
244 */
245 Void rgSCHRrCListInsrtAtCrnt
246 (
247 RgSchRrCListCp *lCp,                /* list control pointer */
248 RgSchRrCList *node                  /* node to be removed */
249 )
250 {
251    RgSchRrCList *crnt;
252
253 #ifdef ERRCHK
254    if (lCp == (RgSchRrCListCp *)NULLP)
255       return;
256 #endif
257
258    crnt = lCp->crnt;
259    lCp->crnt = node;
260
261    node->prev = crnt->prev;
262    crnt->prev->next = node;
263    node->next = crnt;
264    crnt->prev = node;
265
266    lCp->count++;
267
268    return;
269 }
270
271 /********************************************************************30**
272   
273          End of file
274 **********************************************************************/