187 { |
187 { |
188 update_refresh_period(dsc, 0); |
188 update_refresh_period(dsc, 0); |
189 return 0; |
189 return 0; |
190 } |
190 } |
191 |
191 |
192 static pthread_cond_t svghmi_send_WakeCond = PTHREAD_COND_INITIALIZER; |
192 void SVGHMI_SuspendFromPythonThread(void); |
193 static pthread_mutex_t svghmi_send_WakeCondLock = PTHREAD_MUTEX_INITIALIZER; |
193 void SVGHMI_WakeupFromRTThread(void); |
194 |
194 |
195 static int continue_collect; |
195 static int continue_collect; |
196 |
196 |
197 int __init_svghmi() |
197 int __init_svghmi() |
198 { |
198 { |
199 bzero(rbuf,sizeof(rbuf)); |
199 bzero(rbuf,sizeof(rbuf)); |
200 bzero(wbuf,sizeof(wbuf)); |
200 bzero(wbuf,sizeof(wbuf)); |
201 |
201 |
202 pthread_mutex_lock(&svghmi_send_WakeCondLock); |
|
203 continue_collect = 1; |
202 continue_collect = 1; |
204 pthread_cond_signal(&svghmi_send_WakeCond); |
|
205 pthread_mutex_unlock(&svghmi_send_WakeCondLock); |
|
206 |
203 |
207 return 0; |
204 return 0; |
208 } |
205 } |
209 |
206 |
210 void __cleanup_svghmi() |
207 void __cleanup_svghmi() |
211 { |
208 { |
212 pthread_mutex_lock(&svghmi_send_WakeCondLock); |
|
213 continue_collect = 0; |
209 continue_collect = 0; |
214 pthread_cond_signal(&svghmi_send_WakeCond); |
210 SVGHMI_WakeupFromRTThread(); |
215 pthread_mutex_unlock(&svghmi_send_WakeCondLock); |
|
216 } |
211 } |
217 |
212 |
218 void __retrieve_svghmi() |
213 void __retrieve_svghmi() |
219 { |
214 { |
220 traverse_hmi_tree(read_iterator); |
215 traverse_hmi_tree(read_iterator); |
223 void __publish_svghmi() |
218 void __publish_svghmi() |
224 { |
219 { |
225 global_write_dirty = 0; |
220 global_write_dirty = 0; |
226 traverse_hmi_tree(write_iterator); |
221 traverse_hmi_tree(write_iterator); |
227 if(global_write_dirty) { |
222 if(global_write_dirty) { |
228 pthread_cond_signal(&svghmi_send_WakeCond); |
223 SVGHMI_WakeupFromRTThread(); |
229 } |
224 } |
230 } |
225 } |
231 |
226 |
232 /* PYTHON CALLS */ |
227 /* PYTHON CALLS */ |
233 int svghmi_send_collect(uint32_t *size, char **ptr){ |
228 int svghmi_send_collect(uint32_t *size, char **ptr){ |
234 |
229 |
235 int do_collect; |
230 SVGHMI_SuspendFromPythonThread(); |
236 pthread_mutex_lock(&svghmi_send_WakeCondLock); |
231 |
237 pthread_cond_wait(&svghmi_send_WakeCond, &svghmi_send_WakeCondLock); |
232 if(continue_collect) { |
238 do_collect = continue_collect; |
|
239 pthread_mutex_unlock(&svghmi_send_WakeCondLock); |
|
240 |
|
241 if(do_collect) { |
|
242 int res; |
233 int res; |
243 sbufidx = HMI_HASH_SIZE; |
234 sbufidx = HMI_HASH_SIZE; |
244 if((res = traverse_hmi_tree(send_iterator)) == 0) |
235 if((res = traverse_hmi_tree(send_iterator)) == 0) |
245 { |
236 { |
246 if(sbufidx > HMI_HASH_SIZE){ |
237 if(sbufidx > HMI_HASH_SIZE){ |