-static void *plugin_read_thread (void __attribute__((unused)) *args)
-{
- while (read_loop != 0)
- {
- read_func_t *rf;
- plugin_ctx_t old_ctx;
- cdtime_t start;
- cdtime_t now;
- cdtime_t elapsed;
- int status;
- int rf_type;
- int rc;
-
- /* 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)
- {
- pthread_cond_wait (&read_cond, &read_lock);
- pthread_mutex_unlock (&read_lock);
- continue;
- }
- pthread_mutex_unlock (&read_lock);
-
- if (rf->rf_interval == 0)
- {
- /* this should not happen, because the interval is set
- * for each plugin when loading it
- * XXX: issue a warning? */
- rf->rf_interval = plugin_get_interval ();
- rf->rf_effective_interval = rf->rf_interval;
-
- rf->rf_next_read = cdtime ();
- }
-
- /* sleep until this entry is due,
- * using pthread_cond_timedwait */
- pthread_mutex_lock (&read_lock);
- /* In pthread_cond_timedwait, spurious wakeups are possible
- * (and really happen, at least on NetBSD with > 1 CPU), thus
- * we need to re-evaluate the condition every time
- * pthread_cond_timedwait returns. */
- rc = 0;
- while ((read_loop != 0)
- && (cdtime () < rf->rf_next_read)
- && rc == 0)
- {
- struct timespec ts = { 0 };
-
- CDTIME_T_TO_TIMESPEC (rf->rf_next_read, &ts);
-
- rc = pthread_cond_timedwait (&read_cond, &read_lock,
- &ts);
- }
-
- /* Must hold `read_lock' when accessing `rf->rf_type'. */
- rf_type = rf->rf_type;
- pthread_mutex_unlock (&read_lock);
-
- /* Check if we're supposed to stop.. This may have interrupted
- * the sleep, too. */
- if (read_loop == 0)
- {
- /* Insert `rf' again, so it can be free'd correctly */
- c_heap_insert (read_heap, rf);
- break;
- }
-
- /* The entry has been marked for deletion. The linked list
- * entry has already been removed by `plugin_unregister_read'.
- * All we have to do here is free the `read_func_t' and
- * continue. */
- if (rf_type == RF_REMOVE)
- {
- DEBUG ("plugin_read_thread: Destroying the `%s' "
- "callback.", rf->rf_name);
- sfree (rf->rf_name);
- destroy_callback ((callback_func_t *) rf);
- rf = NULL;
- continue;
- }
-
- DEBUG ("plugin_read_thread: Handling `%s'.", rf->rf_name);
-
- start = cdtime ();
-
- old_ctx = plugin_set_ctx (rf->rf_ctx);
-
- if (rf_type == RF_SIMPLE)
- {
- int (*callback) (void);
-
- callback = rf->rf_callback;
- status = (*callback) ();
- }
- else
- {
- plugin_read_cb callback;
-
- assert (rf_type == RF_COMPLEX);
-
- callback = rf->rf_callback;
- status = (*callback) (&rf->rf_udata);
- }
-
- plugin_set_ctx (old_ctx);
-
- /* If the function signals failure, we will increase the
- * intervals in which it will be called. */
- if (status != 0)
- {
- rf->rf_effective_interval *= 2;
- if (rf->rf_effective_interval > max_read_interval)
- rf->rf_effective_interval = max_read_interval;
-
- NOTICE ("read-function of plugin `%s' failed. "
- "Will suspend it for %.3f seconds.",
- rf->rf_name,
- CDTIME_T_TO_DOUBLE (rf->rf_effective_interval));
- }
- else
- {
- /* Success: Restore the interval, if it was changed. */
- rf->rf_effective_interval = rf->rf_interval;
- }
-
- /* update the ``next read due'' field */
- now = cdtime ();
-
- /* calculate the time spent in the read function */
- elapsed = (now - start);
-
- if (elapsed > rf->rf_effective_interval)
- WARNING ("plugin_read_thread: read-function of the `%s' plugin took %.3f "
- "seconds, which is above its read interval (%.3f seconds). You might "
- "want to adjust the `Interval' or `ReadThreads' settings.",
- rf->rf_name, CDTIME_T_TO_DOUBLE(elapsed),
- CDTIME_T_TO_DOUBLE(rf->rf_effective_interval));
-
- DEBUG ("plugin_read_thread: read-function of the `%s' plugin took "
- "%.6f seconds.",
- rf->rf_name, CDTIME_T_TO_DOUBLE(elapsed));
-
- DEBUG ("plugin_read_thread: Effective interval of the "
- "`%s' plugin is %.3f seconds.",
- rf->rf_name,
- CDTIME_T_TO_DOUBLE (rf->rf_effective_interval));
-
- /* Calculate the next (absolute) time at which this function
- * should be called. */
- rf->rf_next_read += rf->rf_effective_interval;
-
- /* Check, if `rf_next_read' is in the past. */
- if (rf->rf_next_read < now)
- {
- /* `rf_next_read' is in the past. Insert `now'
- * so this value doesn't trail off into the
- * past too much. */
- rf->rf_next_read = now;
- }
-
- DEBUG ("plugin_read_thread: Next read of the `%s' plugin at %.3f.",
- rf->rf_name,
- CDTIME_T_TO_DOUBLE (rf->rf_next_read));
-
- /* Re-insert this read function into the heap again. */
- c_heap_insert (read_heap, rf);
- } /* while (read_loop) */
-
- pthread_exit (NULL);
- return ((void *) 0);
+static void *plugin_read_thread(void __attribute__((unused)) * args) {
+ while (read_loop != 0) {
+ read_func_t *rf;
+ plugin_ctx_t old_ctx;
+ cdtime_t start;
+ cdtime_t now;
+ cdtime_t elapsed;
+ int status;
+ int rf_type;
+ int rc;
+
+ /* 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) {
+ pthread_cond_wait(&read_cond, &read_lock);
+ pthread_mutex_unlock(&read_lock);
+ continue;
+ }
+ pthread_mutex_unlock(&read_lock);
+
+ if (rf->rf_interval == 0) {
+ /* this should not happen, because the interval is set
+ * for each plugin when loading it
+ * XXX: issue a warning? */
+ rf->rf_interval = plugin_get_interval();
+ rf->rf_effective_interval = rf->rf_interval;
+
+ rf->rf_next_read = cdtime();
+ }
+
+ /* sleep until this entry is due,
+ * using pthread_cond_timedwait */
+ pthread_mutex_lock(&read_lock);
+ /* In pthread_cond_timedwait, spurious wakeups are possible
+ * (and really happen, at least on NetBSD with > 1 CPU), thus
+ * we need to re-evaluate the condition every time
+ * pthread_cond_timedwait returns. */
+ rc = 0;
+ while ((read_loop != 0) && (cdtime() < rf->rf_next_read) && rc == 0) {
+ rc = pthread_cond_timedwait(&read_cond, &read_lock,
+ &CDTIME_T_TO_TIMESPEC(rf->rf_next_read));
+ }
+
+ /* Must hold `read_lock' when accessing `rf->rf_type'. */
+ rf_type = rf->rf_type;
+ pthread_mutex_unlock(&read_lock);
+
+ /* Check if we're supposed to stop.. This may have interrupted
+ * the sleep, too. */
+ if (read_loop == 0) {
+ /* Insert `rf' again, so it can be free'd correctly */
+ c_heap_insert(read_heap, rf);
+ break;
+ }
+
+ /* The entry has been marked for deletion. The linked list
+ * entry has already been removed by `plugin_unregister_read'.
+ * All we have to do here is free the `read_func_t' and
+ * continue. */
+ if (rf_type == RF_REMOVE) {
+ DEBUG("plugin_read_thread: Destroying the `%s' "
+ "callback.",
+ rf->rf_name);
+ sfree(rf->rf_name);
+ destroy_callback((callback_func_t *)rf);
+ rf = NULL;
+ continue;
+ }
+
+ DEBUG("plugin_read_thread: Handling `%s'.", rf->rf_name);
+
+ start = cdtime();
+
+ old_ctx = plugin_set_ctx(rf->rf_ctx);
+
+ if (rf_type == RF_SIMPLE) {
+ int (*callback)(void);
+
+ callback = rf->rf_callback;
+ status = (*callback)();
+ } else {
+ plugin_read_cb callback;
+
+ assert(rf_type == RF_COMPLEX);
+
+ callback = rf->rf_callback;
+ status = (*callback)(&rf->rf_udata);
+ }
+
+ plugin_set_ctx(old_ctx);
+
+ /* If the function signals failure, we will increase the
+ * intervals in which it will be called. */
+ if (status != 0) {
+ rf->rf_effective_interval *= 2;
+ if (rf->rf_effective_interval > max_read_interval)
+ rf->rf_effective_interval = max_read_interval;
+
+ NOTICE("read-function of plugin `%s' failed. "
+ "Will suspend it for %.3f seconds.",
+ rf->rf_name, CDTIME_T_TO_DOUBLE(rf->rf_effective_interval));
+ } else {
+ /* Success: Restore the interval, if it was changed. */
+ rf->rf_effective_interval = rf->rf_interval;
+ }
+
+ /* update the ``next read due'' field */
+ now = cdtime();
+
+ /* calculate the time spent in the read function */
+ elapsed = (now - start);
+
+ if (elapsed > rf->rf_effective_interval)
+ WARNING(
+ "plugin_read_thread: read-function of the `%s' plugin took %.3f "
+ "seconds, which is above its read interval (%.3f seconds). You might "
+ "want to adjust the `Interval' or `ReadThreads' settings.",
+ rf->rf_name, CDTIME_T_TO_DOUBLE(elapsed),
+ CDTIME_T_TO_DOUBLE(rf->rf_effective_interval));
+
+ DEBUG("plugin_read_thread: read-function of the `%s' plugin took "
+ "%.6f seconds.",
+ rf->rf_name, CDTIME_T_TO_DOUBLE(elapsed));
+
+ DEBUG("plugin_read_thread: Effective interval of the "
+ "`%s' plugin is %.3f seconds.",
+ rf->rf_name, CDTIME_T_TO_DOUBLE(rf->rf_effective_interval));
+
+ /* Calculate the next (absolute) time at which this function
+ * should be called. */
+ rf->rf_next_read += rf->rf_effective_interval;
+
+ /* Check, if `rf_next_read' is in the past. */
+ if (rf->rf_next_read < now) {
+ /* `rf_next_read' is in the past. Insert `now'
+ * so this value doesn't trail off into the
+ * past too much. */
+ rf->rf_next_read = now;
+ }
+
+ DEBUG("plugin_read_thread: Next read of the `%s' plugin at %.3f.",
+ rf->rf_name, CDTIME_T_TO_DOUBLE(rf->rf_next_read));
+
+ /* Re-insert this read function into the heap again. */
+ c_heap_insert(read_heap, rf);
+ } /* while (read_loop) */
+
+ pthread_exit(NULL);
+ return ((void *)0);