comparison gsm-fw/gpf/osl/os_mem_fl.c @ 396:c82d093a2b89

os_mem_fl.c: os_AllocateMemory() and os_DeallocateMemory()
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 13 Jun 2014 00:55:36 +0000
parents d148403013c0
children f5b9c6d63718
comparison
equal deleted inserted replaced
395:8891c3d0c68a 396:c82d093a2b89
237 *GroupHandle = i; 237 *GroupHandle = i;
238 return(OS_OK); 238 return(OS_OK);
239 } 239 }
240 return(OS_ERROR); 240 return(OS_ERROR);
241 } 241 }
242
243 GLOBAL LONG
244 os_DeallocateMemory(OS_HANDLE TaskHandle, T_VOID_STRUCT *Buffer)
245 {
246 if (NU_Deallocate_Memory(Buffer) == NU_SUCCESS)
247 return(OS_OK);
248 else
249 return(OS_ERROR);
250 }
251
252 GLOBAL LONG
253 os_AllocateMemory(OS_HANDLE TaskHandle, T_VOID_STRUCT **Buffer, ULONG Size,
254 ULONG Suspend, OS_HANDLE PoolHandle)
255 {
256 int ret, sts;
257
258 if (Suspend == 0xFFFFFFFF)
259 Suspend = 1;
260 ret = OS_OK;
261 for (;;) {
262 sts = NU_Allocate_Memory(MemPoolTable[PoolHandle].pcb, Buffer,
263 Size, Suspend);
264 switch (sts) {
265 case NU_SUCCESS:
266 return(ret);
267 case NU_INVALID_SUSPEND:
268 Suspend = 0;
269 continue;
270 case NU_NO_MEMORY:
271 case NU_TIMEOUT:
272 if (Suspend == 1) {
273 Suspend = 0xFFFFFFFF;
274 ret = OS_WAITED;
275 continue;
276 } else {
277 *Buffer = 0;
278 return(OS_TIMEOUT);
279 }
280 default:
281 /*
282 * Disassembly reveals that the original code
283 * has an endless loop here, the equivalent
284 * of continue. My guess is that they simply
285 * forgot the default case, and so control
286 * falls onto the closing brace of the switch
287 * and then onto the closing brace of the for
288 * loop. But I prefer better error handling,
289 * hence the present addition. - Space Falcon
290 */
291 *Buffer = 0;
292 return(OS_ERROR);
293 }
294 }
295 }