450
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /*
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This C module is a reconstruction based on the disassembly of
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 * os_sem.obj in frame_na7_db_ir.lib from the Leonardo package.
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 */
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 /* set of included headers from COFF symtab: */
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdio.h>
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <string.h>
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include "gpfconf.h" /* FreeCalypso addition */
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include "../../nucleus/nucleus.h"
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include "typedefs.h"
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include "os.h"
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include "gdi.h"
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 #include "os_types.h"
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 #include "os_glob.h"
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 extern T_OS_SEM_TABLE_ENTRY SemTable[];
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 extern unsigned os_time_to_tick_multiplier;
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 int
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 ReleaseSemaphoreCB(NU_SEMAPHORE *SemCB)
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 {
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 if (NU_Release_Semaphore(SemCB) == NU_SUCCESS)
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 return(OS_OK);
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 else
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 return(OS_ERROR);
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 }
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28
|
451
|
29 GLOBAL LONG
|
|
30 os_ReleaseSemaphore(OS_HANDLE TaskHandle, OS_HANDLE SemHandle)
|
|
31 {
|
|
32 if (NU_Release_Semaphore(&SemTable[SemHandle].SemCB) == NU_SUCCESS)
|
|
33 return(OS_OK);
|
|
34 else
|
|
35 return(OS_ERROR);
|
|
36 }
|
|
37
|
450
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 int
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 ObtainSemaphoreCB(NU_SEMAPHORE *SemCB, ULONG Timeout, USHORT wait_check)
|
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 {
|
452
|
41 UNSIGNED nu_timeout;
|
|
42 STATUS sts;
|
|
43 int ret;
|
450
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44
|
452
|
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 }
|
450
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 }
|
453
|
85
|
|
86 GLOBAL LONG
|
|
87 os_ObtainSemaphore(OS_HANDLE TaskHandle, OS_HANDLE SemHandle, ULONG Timeout)
|
|
88 {
|
|
89 if (SemHandle > MaxSemaphores)
|
|
90 return(OS_ERROR);
|
|
91 return ObtainSemaphoreCB(&SemTable[SemHandle].SemCB, Timeout, 0);
|
|
92 }
|