avoid code duplication
Costa Tsaousis (ktsaou) committed
Feb 25, 2017 at 13:49 UTC
69520035d8893339bffc354febf5da5c4f7dabbe
3 files changed
+14
-10
src/rrdhost.c
+1
-4
@@ -396,10 +396,7 @@ void rrdhost_free(RRDHOST *host) {
396
// ------------------------------------------------------------------------
397
// free it
398
399
- if(host->rrdpush_spawn) {
400
- pthread_cancel(host->rrdpush_thread);
401
- rrdpush_sender_thread_cleanup(host);
402
- }
399
+ rrdpush_sender_thread_stop(host);
400
401
freez(host->os);
402
freez(host->cache_dir);
src/rrdpush.c
+12
-5
@@ -206,7 +206,7 @@ static inline void rrdpush_sender_thread_unlock(RRDHOST *host) {
206
rrdpush_unlock(host);
207
}
208
209
-void rrdpush_sender_thread_cleanup(RRDHOST *host) {
209
+static void rrdpush_sender_thread_cleanup(RRDHOST *host) {
210
rrdpush_lock(host);
211
212
host->rrdpush_connected = 0;
@@ -235,6 +235,16 @@ void rrdpush_sender_thread_cleanup(RRDHOST *host) {
235
rrdpush_unlock(host);
236
}
237
238
+void rrdpush_sender_thread_stop(RRDHOST *host) {
239
+ rrdhost_check_wrlock(host);
240
+
241
+ if(host->rrdpush_spawn) {
242
+ info("STREAM %s [send]: stopping sending thread...", host->hostname);
243
+ pthread_cancel(host->rrdpush_thread);
244
+ rrdpush_sender_thread_cleanup(host);
245
+ }
246
+}
247
+
248
void *rrdpush_sender_thread(void *ptr) {
249
RRDHOST *host = (RRDHOST *)ptr;
250
@@ -554,10 +564,7 @@ int rrdpush_receive(int fd, const char *key, const char *hostname, const char *m
564
if(health_enabled == CONFIG_BOOLEAN_AUTO)
565
host->health_enabled = 0;
566
557
- if(host->rrdpush_spawn) {
558
- pthread_cancel(host->rrdpush_thread);
559
- rrdpush_sender_thread_cleanup(host);
560
- }
567
+ rrdpush_sender_thread_stop(host);
568
}
569
rrdhost_unlock(host);
570
src/rrdpush.h
+1
-1
@@ -10,6 +10,6 @@ extern void rrdset_done_push(RRDSET *st);
10
extern void *rrdpush_sender_thread(void *ptr);
11
12
extern int rrdpush_receiver_thread_spawn(RRDHOST *host, struct web_client *w, char *url);
13
-extern void rrdpush_sender_thread_cleanup(RRDHOST *host);
13
+extern void rrdpush_sender_thread_stop(RRDHOST *host);
14
15
#endif //NETDATA_RRDPUSH_H