comparison src/gpf/osl/os_sem_ir.c @ 0:4e78acac3d88

src/{condat,cs,gpf,nucleus}: import from Selenite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 16 Oct 2020 06:23:26 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4e78acac3d88
1 /*
2 * This C module is a reconstruction based on the disassembly of
3 * os_sem.obj in frame_na7_db_ir.lib from the Leonardo package.
4 */
5
6 /* set of included headers from COFF symtab: */
7 #include <stdio.h>
8 #include <string.h>
9 #include "nucleus.h"
10 #include "typedefs.h"
11 #include "os.h"
12 #include "gdi.h"
13 #include "os_types.h"
14 #include "os_glob.h"
15
16 extern T_OS_SEM_TABLE_ENTRY SemTable[];
17 extern unsigned os_time_to_tick_multiplier;
18
19 int
20 ReleaseSemaphoreCB(NU_SEMAPHORE *SemCB)
21 {
22 if (NU_Release_Semaphore(SemCB) == NU_SUCCESS)
23 return(OS_OK);
24 else
25 return(OS_ERROR);
26 }
27
28 GLOBAL LONG
29 os_ReleaseSemaphore(OS_HANDLE TaskHandle, OS_HANDLE SemHandle)
30 {
31 if (NU_Release_Semaphore(&SemTable[SemHandle].SemCB) == NU_SUCCESS)
32 return(OS_OK);
33 else
34 return(OS_ERROR);
35 }
36
37 int
38 ObtainSemaphoreCB(NU_SEMAPHORE *SemCB, ULONG Timeout, USHORT wait_check)
39 {
40 UNSIGNED nu_timeout;
41 STATUS sts;
42 int ret;
43
44 ret = OS_OK;
45 if (Timeout != OS_SUSPEND)
46 nu_timeout = TIME_TO_SYSTEM_TICKS(Timeout);
47 else if (wait_check == 1)
48 nu_timeout = 1;
49 else
50 nu_timeout = NU_SUSPEND;
51 for (;;) {
52 sts = NU_Obtain_Semaphore(SemCB, nu_timeout);
53 switch (sts) {
54 case NU_SUCCESS:
55 return(ret);
56 case NU_INVALID_SEMAPHORE:
57 return(OS_ERROR);
58 case NU_INVALID_SUSPEND:
59 nu_timeout = 0;
60 continue;
61 case NU_TIMEOUT:
62 case NU_UNAVAILABLE:
63 if (nu_timeout == 1 && wait_check == 1) {
64 nu_timeout = NU_SUSPEND;
65 ret = OS_WAITED;
66 continue;
67 }
68 return(OS_TIMEOUT);
69 default:
70 /*
71 * Disassembly reveals that the original code
72 * has an endless loop here, the equivalent
73 * of continue. My guess is that they simply
74 * forgot the default case, and so control
75 * falls onto the closing brace of the switch
76 * and then onto the closing brace of the for
77 * loop. But I prefer better error handling,
78 * hence the present addition. - Space Falcon
79 */
80 return(OS_ERROR);
81 }
82 }
83 }
84
85 GLOBAL LONG
86 os_ObtainSemaphore(OS_HANDLE TaskHandle, OS_HANDLE SemHandle, ULONG Timeout)
87 {
88 if (SemHandle > MaxSemaphores)
89 return(OS_ERROR);
90 return ObtainSemaphoreCB(&SemTable[SemHandle].SemCB, Timeout, 0);
91 }