Initial commit
[o-du/l2.git] / src / 5gnrmac / 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
33 #include "envopt.h"        /* environment options */  
34 #include "envdep.h"        /* environment dependent */
35 #include "envind.h"        /* environment independent */
36
37 #include "gen.h"           /* general layer */
38 #include "ssi.h"           /* system services */
39
40 /* header/extern include files (.x) */
41   
42 #include "gen.x"           /* general layer */
43 #include "ssi.x"           /* system services */
44 #include "rg_sch_clist.x"      /* common functions */
45
46
47 /* Linked List functions */
48
49
50 /*
51 *
52 *       Fun:   rgSCHRrCListInit
53 *
54 *       Desc:  initializes a linked list control pointer.
55 *
56 *       Ret:   ROK   - ok
57 *
58 *       Notes: None
59 *
60 *       File:  rr_clist.c
61 *
62 */
63 #ifdef ANSI
64 PUBLIC Void rgSCHRrCListInit
65 (
66 RgSchRrCListCp *lCp                /* list control point */
67 )
68 #else 
69 PUBLIC Void rgSCHRrCListInit(lCp)
70 RgSchRrCListCp *lCp;               /* list control point */
71 #endif
72 {
73    TRC2(rgSCHRrCListInit);
74    
75    lCp->first = (RgSchRrCList *)NULLP;
76    lCp->crnt  = (RgSchRrCList *)NULLP;
77    lCp->count = 0;
78
79    RETVOID;
80 } /* end of rgSCHRrCListInit */
81
82 /* LTE_ADV_FLAG_REMOVED_START */
83 /*
84  *        Fun:   rgSCHRrCListAdd2Crnt
85  * 
86  *        Desc:  adds node to linked list behind crnt.
87  * 
88  *        Ret:   ROK   - ok
89  * 
90  *        Notes: None
91  * 
92  *        File:  rr_clist.c
93  */
94 #ifdef ANSI
95 PUBLIC Void rgSCHRrCListAdd2Crnt
96 (
97  RgSchRrCListCp *lCp,               /* list control point */
98  RgSchRrCList   *node               /* node to be added */
99  )
100 #else
101 PUBLIC Void rgSCHRrCListAdd2Crnt(lCp, node)
102    RgSchRrCListCp *lCp;               /* list control point */
103    RgSchRrCList   *node;              /* node to be added */
104 #endif
105 {
106    TRC2(rgSCHRrCListAdd2Crnt);
107 #ifdef ERRCHK
108    if (lCp == (RgSchRrCListCp *)NULLP)
109       RETVOID;
110 #endif
111
112    lCp->count++;
113
114    if(!lCp->first)
115    {
116       node->prev = node;
117       node->next = node;
118       lCp->first = node;
119
120       lCp->crnt = lCp->first;
121
122       RETVOID;
123    }
124
125    node->next = lCp->crnt;
126    node->prev = lCp->crnt->prev;
127    lCp->crnt->prev->next = node;
128    lCp->crnt->prev = node;
129
130    RETVOID;
131 }
132 /* LTE_ADV_FLAG_REMOVED_END */
133
134 /*
135 *
136 *       Fun:   rgSCHRrCListAdd2Tail
137 *
138 *       Desc:  adds node to linked list after last.
139 *
140 *       Ret:   ROK   - ok
141 *
142 *       Notes: None
143 *
144 *       File:  rr_clist.c
145 *
146 */
147 #ifdef ANSI
148 PUBLIC Void rgSCHRrCListAdd2Tail
149 (
150 RgSchRrCListCp *lCp,               /* list control point */
151 RgSchRrCList   *node               /* node to be added */
152 )
153 #else 
154 PUBLIC Void rgSCHRrCListAdd2Tail(lCp, node)
155 RgSchRrCListCp *lCp;               /* list control point */
156 RgSchRrCList   *node;              /* node to be added */
157 #endif
158 {
159    TRC2(rgSCHRrCListAdd2Tail);
160
161 #ifdef ERRCHK
162    if (lCp == (RgSchRrCListCp *)NULLP)
163       RETVOID;
164 #endif
165  
166    lCp->count++;
167
168    if(!lCp->first)
169    {
170       node->prev = node;
171       node->next = node;
172       lCp->first = node;
173
174       lCp->crnt = lCp->first;
175
176       RETVOID;
177    }
178
179    node->next = lCp->first;
180    node->prev = lCp->first->prev;
181    lCp->first->prev->next = node;
182    lCp->first->prev = node;
183
184    RETVOID;
185 } /* end of rgSCHRrCListAdd2Tail */
186
187 /*
188 *
189 *       Fun:   rgSCHRrCListDelFrm
190 *
191 *       Desc:  remove node pointed to by nodePtr from list and return node.
192 *              nodePtr could be anywhere in the list.
193 *              - resets crnt to NULLP.
194 *
195 *       Ret:   pointer
196 *
197 *       Notes: None
198 *
199 *       File:  rr_clist.c
200 *
201 */
202 #ifdef ANSI
203 PUBLIC RgSchRrCList *rgSCHRrCListDelFrm
204 (
205 RgSchRrCListCp *lCp,                /* list control pointer */
206 RgSchRrCList *node                  /* node to be removed */
207 )
208 #else 
209 PUBLIC RgSchRrCList *rgSCHRrCListDelFrm(lCp, node)
210 RgSchRrCListCp *lCp;               /* list control pointer */
211 RgSchRrCList *node;                /* node to be removed */
212 #endif
213 {
214    TRC2(rgSCHRrCListDelFrm);
215   
216 #ifdef ERRCHK
217    if (lCp == (RgSchRrCListCp *)NULLP)
218       RETVALUE(NULLP);
219 #endif
220
221    if(lCp->count == 0)
222    {
223       RETVALUE(NULLP);
224    }
225    if (lCp->count == 1)
226    {
227       if(lCp->first == node)
228       {
229          lCp->first = lCp->crnt = (RgSchRrCList *)NULLP;
230          lCp->count = 0;
231          node->next = node->prev = (RgSchRrCList *)NULLP;
232          RETVALUE(node);
233       }
234       RETVALUE(NULLP);
235    }
236    
237    if (lCp->first == node)
238    {
239       lCp->first->prev->next = node->next;
240       node->next->prev = lCp->first->prev;
241       lCp->first = node->next;
242       if(lCp->crnt == node)
243       {
244          lCp->crnt = node->next;
245       }
246       node->next = node->prev = (RgSchRrCList *)NULLP;
247        /* Adding this check and guarding the decrement of counter when
248        node is deleted with reshuffling */
249       lCp->count--;
250       RETVALUE(node);
251    }
252
253    if(node->prev && node->next)
254    {
255       node->prev->next = node->next;
256       node->next->prev = node->prev;
257       lCp->count--;
258    }
259    if(lCp->crnt == node)
260    {
261       lCp->crnt = node->next;
262    }
263    node->next = node->prev = (RgSchRrCList *)NULLP;
264    RETVALUE(node);
265 } /* end of rgSCHRrCListDelFrm */
266
267 /*
268 *
269 *       Fun:   rgSCHRrCListInsrtAtCrnt
270 *
271 *       Desc:  Inserting the given node at CuRRENT and Moving present CURRENT 
272 *              node to next.
273 *
274 *       Ret:   None
275 *
276 *       Notes: None
277 *
278 *       File:  rr_clist.c
279 *
280 */
281 #ifdef ANSI
282 PUBLIC Void rgSCHRrCListInsrtAtCrnt
283 (
284 RgSchRrCListCp *lCp,                /* list control pointer */
285 RgSchRrCList *node                  /* node to be removed */
286 )
287 #else 
288 PUBLIC Void rgSCHRrCListInsrtAtCrnt(lCp, node)
289 RgSchRrCListCp *lCp;               /* list control pointer */
290 RgSchRrCList *node;                /* node to be inserted */
291 #endif
292 {
293    RgSchRrCList *crnt;
294    TRC2(rgSCHRrCListInsrtAtCrnt);
295
296 #ifdef ERRCHK
297    if (lCp == (RgSchRrCListCp *)NULLP)
298       RETVOID;
299 #endif
300
301    crnt = lCp->crnt;
302    lCp->crnt = node;
303
304    node->prev = crnt->prev;
305    crnt->prev->next = node;
306    node->next = crnt;
307    crnt->prev = node;
308
309    lCp->count++;
310
311    RETVOID;
312 }
313
314 /********************************************************************30**
315   
316          End of file
317 **********************************************************************/