Code

src/plugin.c: Don't regularly check for read plugins.
authorFlorian Forster <octo@collectd.org>
Tue, 13 Nov 2012 18:14:56 +0000 (19:14 +0100)
committerFlorian Forster <octo@collectd.org>
Wed, 14 Nov 2012 12:02:24 +0000 (13:02 +0100)
Rather, let plugin_insert_read() wake up all the read threads.
This removes another usage of interval_g.

src/plugin.c

index eedbc15af3461906e0d12dbc242d779f1c8d08c3..9d10631df22faec6939292fdec0fcba0cc6945c8 100644 (file)
@@ -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 */