changeset 452:d461c532c76d

os_sem_ir.c: ObtainSemaphoreCB() done
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 23 Jun 2014 03:22:41 +0000
parents 578ba9dfc369
children d2b93cfe8e4c
files gsm-fw/gpf/osl/os_sem_ir.c
diffstat 1 files changed, 42 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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);
+		}
+	}
 }