From 69520035d8893339bffc354febf5da5c4f7dabbe Mon Sep 17 00:00:00 2001 From: "Costa Tsaousis (ktsaou)" Date: Sat, 25 Feb 2017 13:49:33 +0200 Subject: [PATCH] avoid code duplication --- src/rrdhost.c | 5 +---- src/rrdpush.c | 17 ++++++++++++----- src/rrdpush.h | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/rrdhost.c b/src/rrdhost.c index 658fba00..0b507315 100644 --- a/src/rrdhost.c +++ b/src/rrdhost.c @@ -396,10 +396,7 @@ void rrdhost_free(RRDHOST *host) { // ------------------------------------------------------------------------ // free it - if(host->rrdpush_spawn) { - pthread_cancel(host->rrdpush_thread); - rrdpush_sender_thread_cleanup(host); - } + rrdpush_sender_thread_stop(host); freez(host->os); freez(host->cache_dir); diff --git a/src/rrdpush.c b/src/rrdpush.c index 729544b5..a2834955 100644 --- a/src/rrdpush.c +++ b/src/rrdpush.c @@ -206,7 +206,7 @@ static inline void rrdpush_sender_thread_unlock(RRDHOST *host) { rrdpush_unlock(host); } -void rrdpush_sender_thread_cleanup(RRDHOST *host) { +static void rrdpush_sender_thread_cleanup(RRDHOST *host) { rrdpush_lock(host); host->rrdpush_connected = 0; @@ -235,6 +235,16 @@ void rrdpush_sender_thread_cleanup(RRDHOST *host) { rrdpush_unlock(host); } +void rrdpush_sender_thread_stop(RRDHOST *host) { + rrdhost_check_wrlock(host); + + if(host->rrdpush_spawn) { + info("STREAM %s [send]: stopping sending thread...", host->hostname); + pthread_cancel(host->rrdpush_thread); + rrdpush_sender_thread_cleanup(host); + } +} + void *rrdpush_sender_thread(void *ptr) { RRDHOST *host = (RRDHOST *)ptr; @@ -554,10 +564,7 @@ int rrdpush_receive(int fd, const char *key, const char *hostname, const char *m if(health_enabled == CONFIG_BOOLEAN_AUTO) host->health_enabled = 0; - if(host->rrdpush_spawn) { - pthread_cancel(host->rrdpush_thread); - rrdpush_sender_thread_cleanup(host); - } + rrdpush_sender_thread_stop(host); } rrdhost_unlock(host); diff --git a/src/rrdpush.h b/src/rrdpush.h index ef3545f8..dddbe758 100644 --- a/src/rrdpush.h +++ b/src/rrdpush.h @@ -10,6 +10,6 @@ extern void rrdset_done_push(RRDSET *st); extern void *rrdpush_sender_thread(void *ptr); extern int rrdpush_receiver_thread_spawn(RRDHOST *host, struct web_client *w, char *url); -extern void rrdpush_sender_thread_cleanup(RRDHOST *host); +extern void rrdpush_sender_thread_stop(RRDHOST *host); #endif //NETDATA_RRDPUSH_H -- 2.39.2