49
50
netdata_mutex_t *stdout_mutex;
51
bool *plugin_should_exit;
52
+ int *status;
53
bool workers_exit; // all workers are waiting on the same condition - this makes them all exit, when any is cancelled
54
55
ND_THREAD *reader_thread;
290
nd_log(NDLS_COLLECTORS, NDLP_NOTICE, "Received PROGRESS for transaction '%s', but it not available here", transaction);
291
}
292
else if(keyword && strcmp(keyword, PLUGINSD_CALL_QUIT) == 0) {
292
- *wg->plugin_should_exit = true;
293
+ __atomic_store_n(wg->plugin_should_exit, true, __ATOMIC_RELEASE);
294
return true;
295
}
296
else
307
buffered_reader_init(&wg->reader);
308
wg->buffer = buffer_create(sizeof(wg->reader.read_buffer) + 2, NULL);
309
309
- while(!(*wg->plugin_should_exit)) {
310
+ while(!__atomic_load_n(wg->plugin_should_exit, __ATOMIC_ACQUIRE)) {
311
if(unlikely(!buffered_reader_next_line(&wg->reader, wg->buffer))) {
312
buffered_reader_ret_t ret = buffered_reader_read_timeout(
313
&wg->reader,
327
}
328
329
int status = 0;
329
- if(!(*wg->plugin_should_exit)) {
330
+ if(!__atomic_load_n(wg->plugin_should_exit, __ATOMIC_ACQUIRE)) {
331
nd_log(NDLS_COLLECTORS, NDLP_ERR, "Read error on stdin");
332
status = 1;
333
}
334
334
- *wg->plugin_should_exit = true;
335
buffer_free(wg->buffer);
336
- exit(status);
336
+
337
+ if (wg->status)
338
+ __atomic_store_n(wg->status, status, __ATOMIC_RELEASE);
339
+ __atomic_store_n(wg->plugin_should_exit, true, __ATOMIC_RELEASE);
340
}
341
342
void worker_queue_delete_cb(const DICTIONARY_ITEM *item __maybe_unused, void *value, void *data __maybe_unused) {
344
worker_job_cleanup(j);
345
}
346
344
-struct functions_evloop_globals *functions_evloop_init(size_t worker_threads, const char *tag, netdata_mutex_t *stdout_mutex, bool *plugin_should_exit) {
347
+struct functions_evloop_globals *functions_evloop_init(size_t worker_threads, const char *tag,
348
+ netdata_mutex_t *stdout_mutex, bool *plugin_should_exit,
349
+ int *status)
350
+{
351
struct functions_evloop_globals *wg = callocz(1, sizeof(struct functions_evloop_globals));
352
353
wg->worker_queue = dictionary_create(DICT_OPTION_DONT_OVERWRITE_VALUE);
363
wg->workers = worker_threads;
364
wg->worker_threads = callocz(wg->workers, sizeof(ND_THREAD *));
365
wg->tag = tag;
366
+ wg->status = status;
367
368
char tag_buffer[NETDATA_THREAD_TAG_MAX + 1];
369
snprintfz(tag_buffer, NETDATA_THREAD_TAG_MAX, "%s_READER", wg->tag);