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