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