comparison gsm-fw/gpf/osl/os_sem_ir.c @ 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
comparison
equal deleted inserted replaced
451:578ba9dfc369 452:d461c532c76d
36 } 36 }
37 37
38 int 38 int
39 ObtainSemaphoreCB(NU_SEMAPHORE *SemCB, ULONG Timeout, USHORT wait_check) 39 ObtainSemaphoreCB(NU_SEMAPHORE *SemCB, ULONG Timeout, USHORT wait_check)
40 { 40 {
41 UNSIGNED nu_timeout;
42 STATUS sts;
43 int ret;
41 44
42 45 ret = OS_OK;
46 if (Timeout != OS_SUSPEND)
47 nu_timeout = TIME_TO_SYSTEM_TICKS(Timeout);
48 else if (wait_check == 1)
49 nu_timeout = 1;
50 else
51 nu_timeout = NU_SUSPEND;
52 for (;;) {
53 sts = NU_Obtain_Semaphore(SemCB, nu_timeout);
54 switch (sts) {
55 case NU_SUCCESS:
56 return(ret);
57 case NU_INVALID_SEMAPHORE:
58 return(OS_ERROR);
59 case NU_INVALID_SUSPEND:
60 nu_timeout = 0;
61 continue;
62 case NU_TIMEOUT:
63 case NU_UNAVAILABLE:
64 if (nu_timeout == 1 && wait_check == 1) {
65 nu_timeout = NU_SUSPEND;
66 ret = OS_WAITED;
67 continue;
68 }
69 return(OS_TIMEOUT);
70 default:
71 /*
72 * Disassembly reveals that the original code
73 * has an endless loop here, the equivalent
74 * of continue. My guess is that they simply
75 * forgot the default case, and so control
76 * falls onto the closing brace of the switch
77 * and then onto the closing brace of the for
78 * loop. But I prefer better error handling,
79 * hence the present addition. - Space Falcon
80 */
81 return(OS_ERROR);
82 }
83 }
43 } 84 }