From 368aa5df2165c3c3ec3b12f7ad9fe66236571122 Mon Sep 17 00:00:00 2001 From: Johannes Demel Date: Thu, 4 Mar 2021 22:35:54 +0100 Subject: [PATCH] prefs: Use threads if available Signed-off-by: Johannes Demel --- lib/volk_prefs.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/volk_prefs.c b/lib/volk_prefs.c index a6898069a..0b792d5cd 100644 --- a/lib/volk_prefs.c +++ b/lib/volk_prefs.c @@ -18,7 +18,9 @@ #else #include #endif +#ifndef __STDC_NO_THREADS__ #include +#endif #include void volk_get_config_path(char* path, bool read) @@ -78,10 +80,12 @@ static struct volk_preferences { volk_arch_pref_t* volk_arch_prefs; size_t n_arch_prefs; int initialized; +#ifndef __STDC_NO_THREADS__ mtx_t mutex; - +#endif } volk_preferences; +#ifndef __STDC_NO_THREADS__ void init_struct_mutex(void) { if (mtx_init(&volk_preferences.mutex, mtx_plain) != thrd_success) { @@ -91,30 +95,39 @@ void init_struct_mutex(void) static once_flag mutex_init_once_flag = ONCE_FLAG_INIT; void initialize_mutex() { call_once(&mutex_init_once_flag, init_struct_mutex); } +#endif void volk_initialize_preferences() { +#ifndef __STDC_NO_THREADS__ initialize_mutex(); mtx_lock(&volk_preferences.mutex); +#endif if (!volk_preferences.initialized) { volk_preferences.n_arch_prefs = volk_load_preferences(&volk_preferences.volk_arch_prefs); volk_preferences.initialized = 1; } +#ifndef __STDC_NO_THREADS__ mtx_unlock(&volk_preferences.mutex); +#endif } void volk_free_preferences() { +#ifndef __STDC_NO_THREADS__ initialize_mutex(); mtx_lock(&volk_preferences.mutex); +#endif if (volk_preferences.initialized) { free(volk_preferences.volk_arch_prefs); volk_preferences.n_arch_prefs = 0; volk_preferences.initialized = 0; } +#ifndef __STDC_NO_THREADS__ mtx_unlock(&volk_preferences.mutex); +#endif }