From c3300620c68486619fd9c8e47a2552f6a913e09b Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Thu, 9 Feb 2017 22:31:55 +0100 Subject: lib, tools, ipcpd: Fix compilation on FreeBSD FreeBSD defines its own bswap64 in the header, which is now included correctly. POSIX requires XSI or RTS extensions to be enabled for the sa_sigaction field to be visible. Linux doesn't do the check correctly, but FreeBSD does. Removes the LOG_MISSING call which was deprecated with the last revision of the logging system. --- src/lib/byte_order.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/byte_order.h b/src/lib/byte_order.h index 9ee082af..364b06cc 100644 --- a/src/lib/byte_order.h +++ b/src/lib/byte_order.h @@ -49,7 +49,9 @@ #include #ifdef __GLIBC__ -# include +#include +#elif defined(__FreeBSD__) +#include #endif /* if x86 compatible cpu */ @@ -131,7 +133,8 @@ static inline uint32_t bswap_32(uint32_t x) { #if defined(__GNUC__) && (__GNUC__ >= 4) && \ (__GNUC__ > 4 || __GNUC_MINOR__ >= 3) #define bswap_64(x) __builtin_bswap64(x) -#elif !defined(__STRICT_ANSI__) +#elif !defined (bswap64) +#if !defined(__STRICT_ANSI__) static inline uint64_t bswap_64(uint64_t x) { union { uint64_t ll; @@ -145,6 +148,7 @@ static inline uint64_t bswap_64(uint64_t x) { #else #error "bswap_64 unsupported" #endif +#endif #ifdef CPU_BIG_ENDIAN #define be2me_32(x) (x) -- cgit v1.2.3 From d3a8f3e1b2db0894568f5002abf35599324afe9e Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Thu, 9 Feb 2017 23:13:13 +0100 Subject: lib: Fix bug in rib_test --- src/lib/tests/rib_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/tests/rib_test.c b/src/lib/tests/rib_test.c index efc35d63..a7ae7311 100644 --- a/src/lib/tests/rib_test.c +++ b/src/lib/tests/rib_test.c @@ -52,7 +52,7 @@ int rib_test(int argc, uint8_t * buf; ssize_t buf_len; - struct timespec t = {0, 100 * BILLION}; + struct timespec t = {0, 100 * MILLION}; (void) argc; (void) argv; -- cgit v1.2.3 From 4ab16c933f829f51d202c77cfb98f552ad887159 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Thu, 9 Feb 2017 23:44:19 +0100 Subject: lib, ipcp: Correctly init condvars The timerwheel and RIB use timedwaits. The condition variables are now correctly initialised to use the configuration defined clock. --- src/ipcpd/tests/timerwheel_test.c | 1 + src/ipcpd/timerwheel.c | 24 +++++++++++++----------- src/lib/rib.c | 10 +++++++++- 3 files changed, 23 insertions(+), 12 deletions(-) (limited to 'src/lib') 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 #include #include +#include #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 #include -#define OUROBOROS_PREFIX "timerwheel" - -#include - #include #include #include @@ -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; } -- cgit v1.2.3 From aa1643ae393d9460bea8e2922c9cc0a3e6caf63d Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Fri, 10 Feb 2017 00:42:13 +0100 Subject: lib: Fix bad lock in rib --- src/lib/rib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/rib.c b/src/lib/rib.c index c77eab20..af4abccf 100644 --- a/src/lib/rib.c +++ b/src/lib/rib.c @@ -1144,7 +1144,7 @@ int rib_event_wait(ro_set_t * set, if (ret != -ETIMEDOUT) list_move(&rq->events, &sub->events); - pthread_rwlock_wrlock(&rib.lock); + pthread_rwlock_unlock(&rib.lock); return ret; } -- cgit v1.2.3