17 |
17 |
18 procedure ipcToEngine(s: shortstring); |
18 procedure ipcToEngine(s: shortstring); |
19 function ipcReadFromEngine: shortstring; |
19 function ipcReadFromEngine: shortstring; |
20 function ipcCheckFromEngine: boolean; |
20 function ipcCheckFromEngine: boolean; |
21 |
21 |
|
22 procedure ipcToFrontend(s: shortstring); |
|
23 function ipcReadFromFrontend: shortstring; |
|
24 function ipcCheckFromFrontend: boolean; |
|
25 |
22 implementation |
26 implementation |
|
27 |
|
28 procedure ipcSend(var s: shortstring; var msg: TIPCMessage; mut: PSDL_mutex; cond: PSDL_cond); |
|
29 begin |
|
30 SDL_LockMutex(mut); |
|
31 while (msg.str[0] > #0) or (msg.buf <> nil) do |
|
32 SDL_CondWait(cond, mut); |
|
33 |
|
34 msg.str:= s; |
|
35 SDL_CondSignal(cond); |
|
36 SDL_UnlockMutex(mut) |
|
37 end; |
|
38 |
|
39 function ipcRead(var msg: TIPCMessage; mut: PSDL_mutex; cond: PSDL_cond): shortstring; |
|
40 begin |
|
41 SDL_LockMutex(mut); |
|
42 while (msg.str[0] = #0) and (msg.buf = nil) do |
|
43 SDL_CondWait(cond, mut); |
|
44 |
|
45 ipcRead:= msg.str; |
|
46 msg.str[0]:= #0; |
|
47 if msg.buf <> nil then |
|
48 begin |
|
49 FreeMem(msg.buf, msg.len); |
|
50 msg.buf:= nil |
|
51 end; |
|
52 |
|
53 SDL_CondSignal(cond); |
|
54 SDL_UnlockMutex(mut) |
|
55 end; |
|
56 |
|
57 function ipcCheck(var msg: TIPCMessage; mut: PSDL_mutex): boolean; |
|
58 begin |
|
59 SDL_LockMutex(mut); |
|
60 ipcCheck:= (msg.str[0] > #0) or (msg.buf <> nil); |
|
61 SDL_UnlockMutex(mut) |
|
62 end; |
23 |
63 |
24 procedure ipcToEngine(s: shortstring); |
64 procedure ipcToEngine(s: shortstring); |
25 begin |
65 begin |
26 SDL_LockMutex(mutEngine); |
66 ipcSend(s, msgEngine, mutEngine, condEngine) |
27 while (msgEngine.str[0] > #0) or (msgEngine.buf <> nil) do |
67 end; |
28 SDL_CondWait(condEngine, mutEngine); |
|
29 |
68 |
30 msgEngine.str:= s; |
69 procedure ipcToFrontend(s: shortstring); |
31 SDL_CondSignal(condEngine); |
70 begin |
32 SDL_UnlockMutex(mutEngine) |
71 ipcSend(s, msgFrontend, mutFrontend, condFrontend) |
33 end; |
72 end; |
34 |
73 |
35 function ipcReadFromEngine: shortstring; |
74 function ipcReadFromEngine: shortstring; |
36 begin |
75 begin |
37 SDL_LockMutex(mutFrontend); |
76 ipcReadFromEngine:= ipcRead(msgFrontend, mutFrontend, condFrontend) |
38 while (msgFrontend.str[0] = #0) and (msgFrontend.buf = nil) do |
77 end; |
39 SDL_CondWait(condFrontend, mutFrontend); |
|
40 |
78 |
41 ipcReadFromEngine:= msgFrontend.str; |
79 function ipcReadFromFrontend: shortstring; |
42 msgFrontend.str[0]:= #0; |
80 begin |
43 if msgFrontend.buf <> nil then |
81 ipcReadFromFrontend:= ipcRead(msgEngine, mutEngine, condEngine) |
44 begin |
|
45 FreeMem(msgFrontend.buf, msgFrontend.len); |
|
46 msgFrontend.buf:= nil |
|
47 end; |
|
48 |
|
49 SDL_CondSignal(condFrontend); |
|
50 SDL_UnlockMutex(mutFrontend) |
|
51 end; |
82 end; |
52 |
83 |
53 function ipcCheckFromEngine: boolean; |
84 function ipcCheckFromEngine: boolean; |
54 begin |
85 begin |
55 SDL_LockMutex(mutFrontend); |
86 ipcCheckFromEngine:= ipcCheck(msgFrontend, mutFrontend) |
56 ipcCheckFromEngine:= (msgFrontend.str[0] > #0) or (msgFrontend.buf <> nil); |
87 end; |
57 SDL_UnlockMutex(mutFrontend) |
88 |
|
89 function ipcCheckFromFrontend: boolean; |
|
90 begin |
|
91 ipcCheckFromFrontend:= ipcCheck(msgEngine, mutEngine) |
58 end; |
92 end; |
59 |
93 |
60 procedure initIPC; |
94 procedure initIPC; |
61 begin |
95 begin |
62 msgFrontend.str:= ''; |
96 msgFrontend.str:= ''; |