equal
deleted
inserted
replaced
13 |
13 |
14 long AtomicCompareExchange(long* atomicvar, long compared, long exchange) |
14 long AtomicCompareExchange(long* atomicvar, long compared, long exchange) |
15 { |
15 { |
16 return InterlockedCompareExchange(atomicvar, exchange, compared); |
16 return InterlockedCompareExchange(atomicvar, exchange, compared); |
17 } |
17 } |
|
18 CRITICAL_SECTION Atomic64CS; |
|
19 long long AtomicCompareExchange64(long long* atomicvar, long long compared, long long exchange) |
|
20 { |
|
21 long long res; |
|
22 EnterCriticalSection(&Atomic64CS); |
|
23 res=*atomicvar; |
|
24 if(*atomicvar == compared){ |
|
25 *atomicvar = exchange; |
|
26 } |
|
27 LeaveCriticalSection(&Atomic64CS); |
|
28 return res; |
|
29 } |
18 |
30 |
19 struct _timeb timetmp; |
31 struct _timeb timetmp; |
20 void PLC_GetTime(IEC_TIME *CURRENT_TIME) |
32 void PLC_GetTime(IEC_TIME *CURRENT_TIME) |
21 { |
33 { |
22 _ftime(&timetmp); |
34 _ftime(&timetmp); |
61 |
73 |
62 #define maxval(a,b) ((a>b)?a:b) |
74 #define maxval(a,b) ((a>b)?a:b) |
63 int startPLC(int argc,char **argv) |
75 int startPLC(int argc,char **argv) |
64 { |
76 { |
65 unsigned long thread_id = 0; |
77 unsigned long thread_id = 0; |
|
78 BOOL tmp; |
66 setlocale(LC_NUMERIC, "C"); |
79 setlocale(LC_NUMERIC, "C"); |
67 /* Define Ttick to 1ms if common_ticktime not defined */ |
80 /* Define Ttick to 1ms if common_ticktime not defined */ |
68 Ttick = common_ticktime__?common_ticktime__:1000000; |
81 Ttick = common_ticktime__?common_ticktime__:1000000; |
|
82 |
|
83 InitializeCriticalSection(&Atomic64CS); |
69 |
84 |
70 debug_sem = CreateSemaphore( |
85 debug_sem = CreateSemaphore( |
71 NULL, // default security attributes |
86 NULL, // default security attributes |
72 1, // initial count |
87 1, // initial count |
73 1, // maximum count |
88 1, // maximum count |
157 int stopPLC() |
172 int stopPLC() |
158 { |
173 { |
159 CloseHandle(PLC_timer); |
174 CloseHandle(PLC_timer); |
160 WaitForSingleObject(PLC_thread, INFINITE); |
175 WaitForSingleObject(PLC_thread, INFINITE); |
161 __cleanup(); |
176 __cleanup(); |
|
177 DeleteCriticalSection(&Atomic64CS); |
162 CloseHandle(debug_wait_sem); |
178 CloseHandle(debug_wait_sem); |
163 CloseHandle(debug_sem); |
179 CloseHandle(debug_sem); |
164 CloseHandle(python_wait_sem); |
180 CloseHandle(python_wait_sem); |
165 CloseHandle(python_sem); |
181 CloseHandle(python_sem); |
166 CloseHandle(PLC_thread); |
182 CloseHandle(PLC_thread); |