summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5233d6b)
raw | patch | inline | side by side (parent: 5233d6b)
author | Michael Stapelberg <michael@stapelberg.de> | |
Sat, 6 Feb 2010 15:10:33 +0000 (16:10 +0100) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Wed, 10 Feb 2010 11:06:34 +0000 (12:06 +0100) |
This fixes problems storing data in rrd files on NetBSD 5.0 with more
than one CPU.
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
than one CPU.
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
src/plugin.c | patch | blob | history |
diff --git a/src/plugin.c b/src/plugin.c
index 11a0ef6eadbada45aad092f7116c879aeef9dfdd..c163ca7df81c178fec29f97a595e54180ee75090 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
return (0);
}
+static _Bool timeout_reached(struct timespec timeout)
+{
+ struct timeval now;
+ gettimeofday(&now, NULL);
+ return (now.tv_sec >= timeout.tv_sec && now.tv_usec >= (timeout.tv_nsec / 1000));
+}
+
static void *plugin_read_thread (void __attribute__((unused)) *args)
{
while (read_loop != 0)
struct timeval now;
int status;
int rf_type;
+ int rc;
/* Get the read function that needs to be read next. */
rf = c_head_get_root (read_heap);
/* sleep until this entry is due,
* using pthread_cond_timedwait */
pthread_mutex_lock (&read_lock);
- pthread_cond_timedwait (&read_cond, &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 (!timeout_reached(rf->rf_next_read) && rc == 0) {
+ rc = pthread_cond_timedwait (&read_cond, &read_lock,
&rf->rf_next_read);
+ }
+
/* Must hold `real_lock' when accessing `rf->rf_type'. */
rf_type = rf->rf_type;
pthread_mutex_unlock (&read_lock);