author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Fri, 17 Feb 2023 13:41:10 +0100 | |
branch | wxPython4 |
changeset 3728 | 743a384f1bbb |
parent 3727 | 265fc8001d0a |
child 3731 | 549763a28934 |
permissions | -rw-r--r-- |
280
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
1 |
/** |
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
2 |
* Linux specific code |
329 | 3 |
**/ |
280
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
4 |
|
205 | 5 |
#include <stdio.h> |
6 |
#include <string.h> |
|
7 |
#include <time.h> |
|
8 |
#include <signal.h> |
|
9 |
#include <stdlib.h> |
|
3725
0043e2b9dbec
Linux runtime: fix thread waiting on wait_RT_to_nRT_signal not being waken-up when delete_RT_to_nRT_signal is invoked.
Edouard Tisserant
parents:
3334
diff
changeset
|
10 |
#include <errno.h> |
329 | 11 |
#include <pthread.h> |
568 | 12 |
#include <locale.h> |
876
179d5c455f29
Fix bug python thread blocked sometimes on Linux
Laurent Bessard
parents:
617
diff
changeset
|
13 |
#include <semaphore.h> |
205 | 14 |
|
3726
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
15 |
static unsigned long __debug_tick; |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
16 |
|
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
17 |
static pthread_t PLC_thread; |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
18 |
static pthread_mutex_t python_wait_mutex = PTHREAD_MUTEX_INITIALIZER; |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
19 |
static pthread_mutex_t python_mutex = PTHREAD_MUTEX_INITIALIZER; |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
20 |
static pthread_mutex_t debug_wait_mutex = PTHREAD_MUTEX_INITIALIZER; |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
21 |
static pthread_mutex_t debug_mutex = PTHREAD_MUTEX_INITIALIZER; |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
22 |
|
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
23 |
static int PLC_shutdown = 0; |
280
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
24 |
|
236 | 25 |
long AtomicCompareExchange(long* atomicvar,long compared, long exchange) |
205 | 26 |
{ |
27 |
return __sync_val_compare_and_swap(atomicvar, compared, exchange); |
|
28 |
} |
|
954 | 29 |
long long AtomicCompareExchange64(long long* atomicvar, long long compared, long long exchange) |
30 |
{ |
|
31 |
return __sync_val_compare_and_swap(atomicvar, compared, exchange); |
|
32 |
} |
|
205 | 33 |
|
34 |
void PLC_GetTime(IEC_TIME *CURRENT_TIME) |
|
35 |
{ |
|
592 | 36 |
struct timespec tmp; |
37 |
clock_gettime(CLOCK_REALTIME, &tmp); |
|
38 |
CURRENT_TIME->tv_sec = tmp.tv_sec; |
|
39 |
CURRENT_TIME->tv_nsec = tmp.tv_nsec; |
|
205 | 40 |
} |
41 |
||
3726
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
42 |
static long long period_ns = 0; |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
43 |
struct timespec next_abs_time; |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
44 |
|
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
45 |
static void inc_timespec(struct timespec *ts, unsigned long long value_ns) |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
46 |
{ |
3727 | 47 |
long long next_ns = ((long long) ts->tv_sec * 1000000000) + ts->tv_nsec + value_ns; |
3726
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
48 |
#ifdef __lldiv_t_defined |
3727 | 49 |
lldiv_t next_div = lldiv(next_ns, 1000000000); |
3726
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
50 |
ts->tv_sec = next_div.quot; |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
51 |
ts->tv_nsec = next_div.rem; |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
52 |
#else |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
53 |
ts->tv_sec = next_ns / 1000000000; |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
54 |
ts->tv_nsec = next_ns % 1000000000; |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
55 |
#endif |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
56 |
} |
205 | 57 |
|
518
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
485
diff
changeset
|
58 |
void PLC_SetTimer(unsigned long long next, unsigned long long period) |
205 | 59 |
{ |
3726
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
60 |
/* |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
61 |
printf("SetTimer(%lld,%lld)\n",next, period); |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
62 |
*/ |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
63 |
period_ns = period; |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
64 |
clock_gettime(CLOCK_MONOTONIC, &next_abs_time); |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
65 |
inc_timespec(&next_abs_time, next); |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
66 |
// interrupt clock_nanpsleep |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
67 |
pthread_kill(PLC_thread, SIGUSR1); |
205 | 68 |
} |
3727 | 69 |
|
205 | 70 |
void catch_signal(int sig) |
71 |
{ |
|
72 |
// signal(SIGTERM, catch_signal); |
|
73 |
signal(SIGINT, catch_signal); |
|
74 |
printf("Got Signal %d\n",sig); |
|
75 |
exit(0); |
|
76 |
} |
|
77 |
||
3726
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
78 |
void PLCThreadSignalHandler(int sig) |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
79 |
{ |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
80 |
if (sig == SIGUSR2) |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
81 |
pthread_exit(NULL); |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
82 |
} |
876
179d5c455f29
Fix bug python thread blocked sometimes on Linux
Laurent Bessard
parents:
617
diff
changeset
|
83 |
|
2173
976841968d74
Add retain basic implementation on GNU/Linux
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2171
diff
changeset
|
84 |
int ForceSaveRetainReq(void) { |
976841968d74
Add retain basic implementation on GNU/Linux
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2171
diff
changeset
|
85 |
return PLC_shutdown; |
976841968d74
Add retain basic implementation on GNU/Linux
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2171
diff
changeset
|
86 |
} |
976841968d74
Add retain basic implementation on GNU/Linux
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2171
diff
changeset
|
87 |
|
876
179d5c455f29
Fix bug python thread blocked sometimes on Linux
Laurent Bessard
parents:
617
diff
changeset
|
88 |
void PLC_thread_proc(void *arg) |
179d5c455f29
Fix bug python thread blocked sometimes on Linux
Laurent Bessard
parents:
617
diff
changeset
|
89 |
{ |
179d5c455f29
Fix bug python thread blocked sometimes on Linux
Laurent Bessard
parents:
617
diff
changeset
|
90 |
while (!PLC_shutdown) { |
3726
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
91 |
// Sleep until next PLC run |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
92 |
// TODO check result of clock_nanosleep and wait again or exit eventually |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
93 |
int res = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &next_abs_time, NULL); |
3727 | 94 |
if(res==EINTR){ |
95 |
continue; |
|
96 |
} |
|
97 |
if(res!=0){ |
|
98 |
printf("PLC thread died with error %d \n", res); |
|
99 |
return; |
|
100 |
} |
|
3726
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
101 |
PLC_GetTime(&__CURRENT_TIME); |
876
179d5c455f29
Fix bug python thread blocked sometimes on Linux
Laurent Bessard
parents:
617
diff
changeset
|
102 |
__run(); |
3726
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
103 |
inc_timespec(&next_abs_time, period_ns); |
876
179d5c455f29
Fix bug python thread blocked sometimes on Linux
Laurent Bessard
parents:
617
diff
changeset
|
104 |
} |
179d5c455f29
Fix bug python thread blocked sometimes on Linux
Laurent Bessard
parents:
617
diff
changeset
|
105 |
pthread_exit(0); |
179d5c455f29
Fix bug python thread blocked sometimes on Linux
Laurent Bessard
parents:
617
diff
changeset
|
106 |
} |
179d5c455f29
Fix bug python thread blocked sometimes on Linux
Laurent Bessard
parents:
617
diff
changeset
|
107 |
|
280
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
108 |
#define maxval(a,b) ((a>b)?a:b) |
205 | 109 |
int startPLC(int argc,char **argv) |
110 |
{ |
|
568 | 111 |
setlocale(LC_NUMERIC, "C"); |
329 | 112 |
|
876
179d5c455f29
Fix bug python thread blocked sometimes on Linux
Laurent Bessard
parents:
617
diff
changeset
|
113 |
PLC_shutdown = 0; |
179d5c455f29
Fix bug python thread blocked sometimes on Linux
Laurent Bessard
parents:
617
diff
changeset
|
114 |
|
333 | 115 |
pthread_mutex_init(&debug_wait_mutex, NULL); |
462
274e83a5534e
Now debug is not a button anymore
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
446
diff
changeset
|
116 |
pthread_mutex_init(&debug_mutex, NULL); |
333 | 117 |
pthread_mutex_init(&python_wait_mutex, NULL); |
462
274e83a5534e
Now debug is not a button anymore
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
446
diff
changeset
|
118 |
pthread_mutex_init(&python_mutex, NULL); |
329 | 119 |
|
280
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
120 |
pthread_mutex_lock(&debug_wait_mutex); |
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
121 |
pthread_mutex_lock(&python_wait_mutex); |
239
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
122 |
|
205 | 123 |
if( __init(argc,argv) == 0 ){ |
3726
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
124 |
|
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
125 |
/* Signal to wakeup PLC thread when period changes */ |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
126 |
signal(SIGUSR1, PLCThreadSignalHandler); |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
127 |
/* Signal to end PLC thread */ |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
128 |
signal(SIGUSR2, PLCThreadSignalHandler); |
205 | 129 |
/* install signal handler for manual break */ |
130 |
signal(SIGINT, catch_signal); |
|
3726
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
131 |
|
3727 | 132 |
/* initialize next occurence and period */ |
133 |
period_ns = common_ticktime__; |
|
134 |
clock_gettime(CLOCK_MONOTONIC, &next_abs_time); |
|
135 |
||
136 |
pthread_create(&PLC_thread, NULL, (void*) &PLC_thread_proc, NULL); |
|
205 | 137 |
}else{ |
138 |
return 1; |
|
139 |
} |
|
140 |
return 0; |
|
141 |
} |
|
142 |
||
239
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
143 |
int TryEnterDebugSection(void) |
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
144 |
{ |
462
274e83a5534e
Now debug is not a button anymore
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
446
diff
changeset
|
145 |
if (pthread_mutex_trylock(&debug_mutex) == 0){ |
274e83a5534e
Now debug is not a button anymore
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
446
diff
changeset
|
146 |
/* Only enter if debug active */ |
274e83a5534e
Now debug is not a button anymore
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
446
diff
changeset
|
147 |
if(__DEBUG){ |
274e83a5534e
Now debug is not a button anymore
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
446
diff
changeset
|
148 |
return 1; |
274e83a5534e
Now debug is not a button anymore
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
446
diff
changeset
|
149 |
} |
483
bc26c42d2eec
fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents:
462
diff
changeset
|
150 |
pthread_mutex_unlock(&debug_mutex); |
462
274e83a5534e
Now debug is not a button anymore
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
446
diff
changeset
|
151 |
} |
274e83a5534e
Now debug is not a button anymore
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
446
diff
changeset
|
152 |
return 0; |
239
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
153 |
} |
235 | 154 |
|
239
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
155 |
void LeaveDebugSection(void) |
235 | 156 |
{ |
239
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
157 |
pthread_mutex_unlock(&debug_mutex); |
235 | 158 |
} |
159 |
||
205 | 160 |
int stopPLC() |
161 |
{ |
|
162 |
/* Stop the PLC */ |
|
876
179d5c455f29
Fix bug python thread blocked sometimes on Linux
Laurent Bessard
parents:
617
diff
changeset
|
163 |
PLC_shutdown = 1; |
3726
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
164 |
/* Order PLCThread to exit */ |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
165 |
pthread_kill(PLC_thread, SIGUSR2); |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
166 |
pthread_join(PLC_thread, NULL); |
205 | 167 |
__cleanup(); |
329 | 168 |
pthread_mutex_destroy(&debug_wait_mutex); |
483
bc26c42d2eec
fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents:
462
diff
changeset
|
169 |
pthread_mutex_destroy(&debug_mutex); |
329 | 170 |
pthread_mutex_destroy(&python_wait_mutex); |
483
bc26c42d2eec
fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents:
462
diff
changeset
|
171 |
pthread_mutex_destroy(&python_mutex); |
386 | 172 |
return 0; |
205 | 173 |
} |
174 |
||
397
6a7ff66a811d
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
386
diff
changeset
|
175 |
extern unsigned long __tick; |
446
1edde533db19
Some cleanup in PLC status - removed that \"Starting\" state ...
ed
parents:
397
diff
changeset
|
176 |
|
1edde533db19
Some cleanup in PLC status - removed that \"Starting\" state ...
ed
parents:
397
diff
changeset
|
177 |
int WaitDebugData(unsigned long *tick) |
205 | 178 |
{ |
617
7c23fac40a2a
fixed debug with xenomai, fixed unprotected access to ___debug_tick
Edouard Tisserant
parents:
614
diff
changeset
|
179 |
int res; |
876
179d5c455f29
Fix bug python thread blocked sometimes on Linux
Laurent Bessard
parents:
617
diff
changeset
|
180 |
if (PLC_shutdown) return 1; |
617
7c23fac40a2a
fixed debug with xenomai, fixed unprotected access to ___debug_tick
Edouard Tisserant
parents:
614
diff
changeset
|
181 |
/* Wait signal from PLC thread */ |
7c23fac40a2a
fixed debug with xenomai, fixed unprotected access to ___debug_tick
Edouard Tisserant
parents:
614
diff
changeset
|
182 |
res = pthread_mutex_lock(&debug_wait_mutex); |
446
1edde533db19
Some cleanup in PLC status - removed that \"Starting\" state ...
ed
parents:
397
diff
changeset
|
183 |
*tick = __debug_tick; |
617
7c23fac40a2a
fixed debug with xenomai, fixed unprotected access to ___debug_tick
Edouard Tisserant
parents:
614
diff
changeset
|
184 |
return res; |
205 | 185 |
} |
329 | 186 |
|
205 | 187 |
/* Called by PLC thread when debug_publish finished |
188 |
* This is supposed to unlock debugger thread in WaitDebugData*/ |
|
189 |
void InitiateDebugTransfer() |
|
190 |
{ |
|
239
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
191 |
/* remember tick */ |
227
48c13b84505c
- Some improovements in debug data feedback data
etisserant
parents:
205
diff
changeset
|
192 |
__debug_tick = __tick; |
239
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
193 |
/* signal debugger thread it can read data */ |
280
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
194 |
pthread_mutex_unlock(&debug_wait_mutex); |
205 | 195 |
} |
239
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
196 |
|
614 | 197 |
int suspendDebug(int disable) |
462
274e83a5534e
Now debug is not a button anymore
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
446
diff
changeset
|
198 |
{ |
239
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
199 |
/* Prevent PLC to enter debug code */ |
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
200 |
pthread_mutex_lock(&debug_mutex); |
462
274e83a5534e
Now debug is not a button anymore
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
446
diff
changeset
|
201 |
/*__DEBUG is protected by this mutex */ |
274e83a5534e
Now debug is not a button anymore
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
446
diff
changeset
|
202 |
__DEBUG = !disable; |
485 | 203 |
if (disable) |
3726
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
204 |
pthread_mutex_unlock(&debug_mutex); |
614 | 205 |
return 0; |
239
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
206 |
} |
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
207 |
|
280
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
208 |
void resumeDebug(void) |
239
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
209 |
{ |
290
3bd617ae7a05
Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents:
280
diff
changeset
|
210 |
__DEBUG = 1; |
239
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
211 |
/* Let PLC enter debug code */ |
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
212 |
pthread_mutex_unlock(&debug_mutex); |
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
213 |
} |
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
214 |
|
280
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
215 |
/* from plc_python.c */ |
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
216 |
int WaitPythonCommands(void) |
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
217 |
{ |
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
218 |
/* Wait signal from PLC thread */ |
329 | 219 |
return pthread_mutex_lock(&python_wait_mutex); |
280
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
220 |
} |
329 | 221 |
|
280
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
222 |
/* Called by PLC thread on each new python command*/ |
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
223 |
void UnBlockPythonCommands(void) |
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
224 |
{ |
3334 | 225 |
/* signal python thread it can read data */ |
280
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
226 |
pthread_mutex_unlock(&python_wait_mutex); |
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
227 |
} |
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
228 |
|
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
229 |
int TryLockPython(void) |
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
230 |
{ |
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
231 |
return pthread_mutex_trylock(&python_mutex) == 0; |
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
232 |
} |
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
233 |
|
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
234 |
void UnLockPython(void) |
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
235 |
{ |
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
236 |
pthread_mutex_unlock(&python_mutex); |
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
237 |
} |
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
238 |
|
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
239 |
void LockPython(void) |
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
240 |
{ |
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
241 |
pthread_mutex_lock(&python_mutex); |
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
245
diff
changeset
|
242 |
} |
2820
d9b5303d43dc
SVGHMI : had to move the problem of wkaing up python thread from plc thread to platform specific code.
Edouard Tisserant
parents:
2173
diff
changeset
|
243 |
|
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
244 |
struct RT_to_nRT_signal_s { |
3725
0043e2b9dbec
Linux runtime: fix thread waiting on wait_RT_to_nRT_signal not being waken-up when delete_RT_to_nRT_signal is invoked.
Edouard Tisserant
parents:
3334
diff
changeset
|
245 |
int used; |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
246 |
pthread_cond_t WakeCond; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
247 |
pthread_mutex_t WakeCondLock; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
248 |
}; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
249 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
250 |
typedef struct RT_to_nRT_signal_s RT_to_nRT_signal_t; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
251 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
252 |
#define _LogAndReturnNull(text) \ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
253 |
{\ |
3726
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
254 |
char mstr[256] = text " for ";\ |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
255 |
strncat(mstr, name, 255);\ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
256 |
LogMessage(LOG_CRITICAL, mstr, strlen(mstr));\ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
257 |
return NULL;\ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
258 |
} |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
259 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
260 |
void *create_RT_to_nRT_signal(char* name){ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
261 |
RT_to_nRT_signal_t *sig = (RT_to_nRT_signal_t*)malloc(sizeof(RT_to_nRT_signal_t)); |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
262 |
|
3726
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
263 |
if(!sig) |
516779f11803
runtime: Change Linux target to use clock_nanosleep instead of timer (better rt-preempt perf).
Edouard Tisserant
parents:
3725
diff
changeset
|
264 |
_LogAndReturnNull("Failed allocating memory for RT_to_nRT signal"); |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
265 |
|
3725
0043e2b9dbec
Linux runtime: fix thread waiting on wait_RT_to_nRT_signal not being waken-up when delete_RT_to_nRT_signal is invoked.
Edouard Tisserant
parents:
3334
diff
changeset
|
266 |
sig->used = 1; |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
267 |
pthread_cond_init(&sig->WakeCond, NULL); |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
268 |
pthread_mutex_init(&sig->WakeCondLock, NULL); |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
269 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
270 |
return (void*)sig; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
271 |
} |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
272 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
273 |
void delete_RT_to_nRT_signal(void* handle){ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
274 |
RT_to_nRT_signal_t *sig = (RT_to_nRT_signal_t*)handle; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
275 |
|
3725
0043e2b9dbec
Linux runtime: fix thread waiting on wait_RT_to_nRT_signal not being waken-up when delete_RT_to_nRT_signal is invoked.
Edouard Tisserant
parents:
3334
diff
changeset
|
276 |
pthread_mutex_lock(&sig->WakeCondLock); |
0043e2b9dbec
Linux runtime: fix thread waiting on wait_RT_to_nRT_signal not being waken-up when delete_RT_to_nRT_signal is invoked.
Edouard Tisserant
parents:
3334
diff
changeset
|
277 |
sig->used = 0; |
0043e2b9dbec
Linux runtime: fix thread waiting on wait_RT_to_nRT_signal not being waken-up when delete_RT_to_nRT_signal is invoked.
Edouard Tisserant
parents:
3334
diff
changeset
|
278 |
pthread_cond_signal(&sig->WakeCond); |
0043e2b9dbec
Linux runtime: fix thread waiting on wait_RT_to_nRT_signal not being waken-up when delete_RT_to_nRT_signal is invoked.
Edouard Tisserant
parents:
3334
diff
changeset
|
279 |
pthread_mutex_unlock(&sig->WakeCondLock); |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
280 |
} |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
281 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
282 |
int wait_RT_to_nRT_signal(void* handle){ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
283 |
int ret; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
284 |
RT_to_nRT_signal_t *sig = (RT_to_nRT_signal_t*)handle; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
285 |
pthread_mutex_lock(&sig->WakeCondLock); |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
286 |
ret = pthread_cond_wait(&sig->WakeCond, &sig->WakeCondLock); |
3725
0043e2b9dbec
Linux runtime: fix thread waiting on wait_RT_to_nRT_signal not being waken-up when delete_RT_to_nRT_signal is invoked.
Edouard Tisserant
parents:
3334
diff
changeset
|
287 |
if(!sig->used) ret = -EINVAL; |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
288 |
pthread_mutex_unlock(&sig->WakeCondLock); |
3725
0043e2b9dbec
Linux runtime: fix thread waiting on wait_RT_to_nRT_signal not being waken-up when delete_RT_to_nRT_signal is invoked.
Edouard Tisserant
parents:
3334
diff
changeset
|
289 |
|
0043e2b9dbec
Linux runtime: fix thread waiting on wait_RT_to_nRT_signal not being waken-up when delete_RT_to_nRT_signal is invoked.
Edouard Tisserant
parents:
3334
diff
changeset
|
290 |
if(!sig->used){ |
0043e2b9dbec
Linux runtime: fix thread waiting on wait_RT_to_nRT_signal not being waken-up when delete_RT_to_nRT_signal is invoked.
Edouard Tisserant
parents:
3334
diff
changeset
|
291 |
pthread_cond_destroy(&sig->WakeCond); |
0043e2b9dbec
Linux runtime: fix thread waiting on wait_RT_to_nRT_signal not being waken-up when delete_RT_to_nRT_signal is invoked.
Edouard Tisserant
parents:
3334
diff
changeset
|
292 |
pthread_mutex_destroy(&sig->WakeCondLock); |
0043e2b9dbec
Linux runtime: fix thread waiting on wait_RT_to_nRT_signal not being waken-up when delete_RT_to_nRT_signal is invoked.
Edouard Tisserant
parents:
3334
diff
changeset
|
293 |
free(sig); |
0043e2b9dbec
Linux runtime: fix thread waiting on wait_RT_to_nRT_signal not being waken-up when delete_RT_to_nRT_signal is invoked.
Edouard Tisserant
parents:
3334
diff
changeset
|
294 |
} |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
295 |
return ret; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
296 |
} |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
297 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
298 |
int unblock_RT_to_nRT_signal(void* handle){ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
299 |
RT_to_nRT_signal_t *sig = (RT_to_nRT_signal_t*)handle; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
300 |
return pthread_cond_signal(&sig->WakeCond); |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
301 |
} |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2820
diff
changeset
|
302 |
|
3295
0375d801fff7
Runtime+SVGHMI: Add generic wakeup of threads from PLC thread to windows implementation of plc_main.c. Also added nRT_reschedule to abstract sched_yield.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3294
diff
changeset
|
303 |
void nRT_reschedule(void){ |
0375d801fff7
Runtime+SVGHMI: Add generic wakeup of threads from PLC thread to windows implementation of plc_main.c. Also added nRT_reschedule to abstract sched_yield.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3294
diff
changeset
|
304 |
sched_yield(); |
0375d801fff7
Runtime+SVGHMI: Add generic wakeup of threads from PLC thread to windows implementation of plc_main.c. Also added nRT_reschedule to abstract sched_yield.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3294
diff
changeset
|
305 |
} |