# HG changeset patch # User Michael Spacefalcon # Date 1403493761 0 # Node ID d461c532c76dc67d07f429f2e4025078b2cca2b3 # Parent 578ba9dfc369fbfe8cbeb3fb11b2e2d649c9171f os_sem_ir.c: ObtainSemaphoreCB() done diff -r 578ba9dfc369 -r d461c532c76d gsm-fw/gpf/osl/os_sem_ir.c --- a/gsm-fw/gpf/osl/os_sem_ir.c Mon Jun 23 02:58:34 2014 +0000 +++ b/gsm-fw/gpf/osl/os_sem_ir.c Mon Jun 23 03:22:41 2014 +0000 @@ -38,6 +38,47 @@ int ObtainSemaphoreCB(NU_SEMAPHORE *SemCB, ULONG Timeout, USHORT wait_check) { - + UNSIGNED nu_timeout; + STATUS sts; + int ret; + ret = OS_OK; + if (Timeout != OS_SUSPEND) + nu_timeout = TIME_TO_SYSTEM_TICKS(Timeout); + else if (wait_check == 1) + nu_timeout = 1; + else + nu_timeout = NU_SUSPEND; + for (;;) { + sts = NU_Obtain_Semaphore(SemCB, nu_timeout); + switch (sts) { + case NU_SUCCESS: + return(ret); + case NU_INVALID_SEMAPHORE: + return(OS_ERROR); + case NU_INVALID_SUSPEND: + nu_timeout = 0; + continue; + case NU_TIMEOUT: + case NU_UNAVAILABLE: + if (nu_timeout == 1 && wait_check == 1) { + nu_timeout = NU_SUSPEND; + ret = OS_WAITED; + continue; + } + 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 + */ + return(OS_ERROR); + } + } }