From 34919de3df5dda7a06fc09dcec12ca46dc8b26f4 Mon Sep 17 00:00:00 2001 From: Devin Matthews Date: Sat, 2 Oct 2021 18:48:50 -0500 Subject: [PATCH] Make error checking level a thread-local variable. Previously, this was a global variable. Setting the value was synchronized via a mutex but reading the value was not. Of course, these accesses are almost certainly atomic, but there is still the possibility of one thread attempting to set the value and then reading the value set by another thread. For correct operation under user threading (e.g. pthreads), this should probably be thread-local with no mutex. --- frame/base/bli_error.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/frame/base/bli_error.c b/frame/base/bli_error.c index a33876690..37add3b67 100644 --- a/frame/base/bli_error.c +++ b/frame/base/bli_error.c @@ -133,11 +133,8 @@ void bli_abort( void ) // ----------------------------------------------------------------------------- -// A mutex to allow synchronous access to bli_err_chk_level. -static bli_pthread_mutex_t err_mutex = BLIS_PTHREAD_MUTEX_INITIALIZER; - // Current error checking level. -static errlev_t bli_err_chk_level = BLIS_FULL_ERROR_CHECKING; +static BLIS_THREAD_LOCAL errlev_t bli_err_chk_level = BLIS_FULL_ERROR_CHECKING; errlev_t bli_error_checking_level( void ) { @@ -151,17 +148,7 @@ void bli_error_checking_level_set( errlev_t new_level ) e_val = bli_check_valid_error_level( new_level ); bli_check_error_code( e_val ); - // Acquire the mutex protecting bli_err_chk_level. - bli_pthread_mutex_lock( &err_mutex ); - - // BEGIN CRITICAL SECTION - { - bli_err_chk_level = new_level; - } - // END CRITICAL SECTION - - // Release the mutex protecting bli_err_chk_level. - bli_pthread_mutex_unlock( &err_mutex ); + bli_err_chk_level = new_level; } bool bli_error_checking_is_enabled( void )