From b53163fa0a5be2626944002968f048e15ab78b4b Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sun, 12 Mar 2017 15:19:26 +0100 Subject: [PATCH] src/aubio_setup.c: add lock for logging, use error() to display errors in console, hide warnings to level 3 --- src/aubio_setup.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/aubio_setup.c b/src/aubio_setup.c index 0f6e549..5b25d03 100644 --- a/src/aubio_setup.c +++ b/src/aubio_setup.c @@ -3,6 +3,11 @@ #include #include +#ifdef HAVE_PTHREAD +#include +pthread_mutex_t aubio_log_mutex; +#endif + char aubio_version[] = "aubio external for pd, version " PACKAGE_VERSION; static t_class *aubio_class; @@ -36,15 +41,29 @@ void aubio_custom_log(int level, const char *message, void *data) if ((pos=strchr(message, '\n')) != NULL) { *pos = '\0'; } - post(message); +#ifdef HAVE_PTHREAD + pthread_mutex_lock(&aubio_log_mutex); +#endif + if (level == AUBIO_LOG_ERR) { + error(message); + } else if (level == AUBIO_LOG_WRN) { + logpost(NULL, 3, message); + } else { + post(message); + } +#ifdef HAVE_PTHREAD + pthread_mutex_unlock(&aubio_log_mutex); +#endif } void aubio_setup (void) { - post(aubio_version); // register custom log function for errors and warnings - aubio_log_set_level_function(AUBIO_LOG_ERR, aubio_custom_log, NULL); - aubio_log_set_level_function(AUBIO_LOG_WRN, aubio_custom_log, NULL); +#ifdef HAVE_PTHREAD + pthread_mutex_init(&aubio_log_mutex, 0); +#endif + aubio_log_set_function(aubio_custom_log, NULL); + post(aubio_version); aubioonset_tilde_setup(); aubiotempo_tilde_setup(); aubiotss_tilde_setup(); -- 2.11.0