From: Florian Forster Date: Tue, 13 Nov 2012 18:14:56 +0000 (+0100) Subject: src/plugin.c: Don't regularly check for read plugins. X-Git-Tag: collectd-5.2.0~20^2~10 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=86db5dd0f868540a8d5a11d32115b22d378b39cd;p=collectd.git src/plugin.c: Don't regularly check for read plugins. Rather, let plugin_insert_read() wake up all the read threads. This removes another usage of interval_g. --- diff --git a/src/plugin.c b/src/plugin.c index eedbc15a..9d10631d 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -359,22 +359,19 @@ static void *plugin_read_thread (void __attribute__((unused)) *args) int rf_type; int rc; - /* Get the read function that needs to be read next. */ + /* Get the read function that needs to be read next. + * We don't need to hold "read_lock" for the heap, but we need + * to call c_heap_get_root() and pthread_cond_wait() in the + * same protected block. */ + pthread_mutex_lock (&read_lock); rf = c_heap_get_root (read_heap); if (rf == NULL) { - struct timespec abstime; - - now = cdtime (); - - CDTIME_T_TO_TIMESPEC (now + interval_g, &abstime); - - pthread_mutex_lock (&read_lock); - pthread_cond_timedwait (&read_cond, &read_lock, - &abstime); - pthread_mutex_unlock (&read_lock); + pthread_cond_wait (&read_cond, &read_lock); + pthread_mutex_unlock (&read_lock); continue; } + pthread_mutex_unlock (&read_lock); if ((rf->rf_interval.tv_sec == 0) && (rf->rf_interval.tv_nsec == 0)) { @@ -784,6 +781,8 @@ static int plugin_insert_read (read_func_t *rf) /* This does not fail. */ llist_append (read_list, le); + /* Wake up all the read threads. */ + pthread_cond_broadcast (&read_cond); pthread_mutex_unlock (&read_lock); return (0); } /* int plugin_insert_read */