FreeCalypso > hg > freecalypso-sw
changeset 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 | 8891c3d0c68a |
children | f5b9c6d63718 |
files | gsm-fw/gpf/osl/os_mem_fl.c |
diffstat | 1 files changed, 54 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/gsm-fw/gpf/osl/os_mem_fl.c Wed Jun 11 17:49:13 2014 +0000 +++ b/gsm-fw/gpf/osl/os_mem_fl.c Fri Jun 13 00:55:36 2014 +0000 @@ -239,3 +239,57 @@ } return(OS_ERROR); } + +GLOBAL LONG +os_DeallocateMemory(OS_HANDLE TaskHandle, T_VOID_STRUCT *Buffer) +{ + if (NU_Deallocate_Memory(Buffer) == NU_SUCCESS) + return(OS_OK); + else + return(OS_ERROR); +} + +GLOBAL LONG +os_AllocateMemory(OS_HANDLE TaskHandle, T_VOID_STRUCT **Buffer, ULONG Size, + ULONG Suspend, OS_HANDLE PoolHandle) +{ + int ret, sts; + + if (Suspend == 0xFFFFFFFF) + Suspend = 1; + ret = OS_OK; + for (;;) { + sts = NU_Allocate_Memory(MemPoolTable[PoolHandle].pcb, Buffer, + Size, Suspend); + switch (sts) { + case NU_SUCCESS: + return(ret); + case NU_INVALID_SUSPEND: + Suspend = 0; + continue; + case NU_NO_MEMORY: + case NU_TIMEOUT: + if (Suspend == 1) { + Suspend = 0xFFFFFFFF; + ret = OS_WAITED; + continue; + } else { + *Buffer = 0; + return(OS_TIMEOUT); + } + default: + /* + * Disassembly reveals that the original code + * has an endless loop here, the equivalent + * of continue. My guess is that they simply + * forgot the default case, and so control + * falls onto the closing brace of the switch + * and then onto the closing brace of the for + * loop. But I prefer better error handling, + * hence the present addition. - Space Falcon + */ + *Buffer = 0; + return(OS_ERROR); + } + } +}