summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2017-02-09 23:44:19 +0100
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2017-02-09 23:45:50 +0100
commit4ab16c933f829f51d202c77cfb98f552ad887159 (patch)
tree6dd868eea3d699a67810f1e18365e902d6db228c /src
parent773502eb6c8dd6fc1611a2140786e281d2af404a (diff)
downloadouroboros-4ab16c933f829f51d202c77cfb98f552ad887159.tar.gz
ouroboros-4ab16c933f829f51d202c77cfb98f552ad887159.zip
lib, ipcp: Correctly init condvars
The timerwheel and RIB use timedwaits. The condition variables are now correctly initialised to use the configuration defined clock.
Diffstat (limited to 'src')
-rw-r--r--src/ipcpd/tests/timerwheel_test.c1
-rw-r--r--src/ipcpd/timerwheel.c24
-rw-r--r--src/lib/rib.c10
3 files changed, 23 insertions, 12 deletions
diff --git a/src/ipcpd/tests/timerwheel_test.c b/src/ipcpd/tests/timerwheel_test.c
index 1ace1371..23de403a 100644
--- a/src/ipcpd/tests/timerwheel_test.c
+++ b/src/ipcpd/tests/timerwheel_test.c
@@ -24,6 +24,7 @@
#include <pthread.h>
#include <time.h>
#include <stdlib.h>
+#include <stdio.h>
#define MAX_ELEMENTS 100
#define MAX_RESOLUTION 10 /* ms */
diff --git a/src/ipcpd/timerwheel.c b/src/ipcpd/timerwheel.c
index 6e5b7da9..ef79bc14 100644
--- a/src/ipcpd/timerwheel.c
+++ b/src/ipcpd/timerwheel.c
@@ -24,10 +24,6 @@
#include <ouroboros/errno.h>
#include <ouroboros/list.h>
-#define OUROBOROS_PREFIX "timerwheel"
-
-#include <ouroboros/logs.h>
-
#include <pthread.h>
#include <stdlib.h>
#include <assert.h>
@@ -127,7 +123,7 @@ static void * worker(void * o)
struct timespec dl;
struct timespec now;
- clock_gettime(CLOCK_MONOTONIC, &now);
+ clock_gettime(PTHREAD_COND_CLOCK, &now);
ts_add(&now, &tw->intv, &dl);
@@ -207,6 +203,8 @@ struct timerwheel * timerwheel_create(unsigned int resolution,
struct timerwheel * tw;
+ pthread_condattr_t cattr;
+
assert(resolution != 0);
tw = malloc(sizeof(*tw));
@@ -235,22 +233,28 @@ struct timerwheel * timerwheel_create(unsigned int resolution,
list_head_init(&tw->wq);
if (pthread_mutex_init(&tw->lock, NULL)) {
- log_dbg("Could not init mutex.");
free(tw->wheel);
free(tw);
return NULL;
}
if (pthread_mutex_init(&tw->s_lock, NULL)) {
- log_dbg("Could not init mutex.");
pthread_mutex_destroy(&tw->lock);
free(tw->wheel);
free(tw);
return NULL;
}
- if (pthread_cond_init(&tw->work, NULL)) {
- log_dbg("Could not init cond.");
+ if (pthread_condattr_init(&cattr)) {
+ pthread_mutex_destroy(&tw->lock);
+ free(tw->wheel);
+ free(tw);
+ return NULL;
+ }
+#ifndef __APPLE__
+ pthread_condattr_setclock(&cattr, PTHREAD_COND_CLOCK);
+#endif
+ if (pthread_cond_init(&tw->work, &cattr)) {
pthread_mutex_destroy(&tw->s_lock);
pthread_mutex_destroy(&tw->lock);
free(tw->wheel);
@@ -271,7 +275,6 @@ struct timerwheel * timerwheel_create(unsigned int resolution,
}
if (pthread_create(&tw->worker, NULL, worker, (void *) tw)) {
- log_dbg("Could not create worker.");
pthread_cond_destroy(&tw->work);
pthread_mutex_destroy(&tw->s_lock);
pthread_mutex_destroy(&tw->lock);
@@ -281,7 +284,6 @@ struct timerwheel * timerwheel_create(unsigned int resolution,
}
if (pthread_create(&tw->ticker, NULL, movement, (void *) tw)) {
- log_dbg("Could not create timer.");
tw_set_state(tw, TW_DESTROY);
pthread_join(tw->worker, NULL);
pthread_cond_destroy(&tw->work);
diff --git a/src/lib/rib.c b/src/lib/rib.c
index e0456b6f..c77eab20 100644
--- a/src/lib/rib.c
+++ b/src/lib/rib.c
@@ -778,11 +778,19 @@ static struct rib_sub * rib_get_sub(uint32_t sid)
static struct rib_sub * rib_sub_create(uint32_t sid)
{
+ pthread_condattr_t cattr;
struct rib_sub * sub = malloc(sizeof(*sub));
if (sub == NULL)
return NULL;
- if (pthread_cond_init(&sub->cond, NULL)) {
+ if (pthread_condattr_init(&cattr)) {
+ free(sub);
+ return NULL;
+ }
+#ifndef __APPLE__
+ pthread_condattr_setclock(&cattr, PTHREAD_COND_CLOCK);
+#endif
+ if (pthread_cond_init(&sub->cond, &cattr)) {
free(sub);
return NULL;
}