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.
This commit is contained in:
Devin Matthews
2021-10-02 18:48:50 -05:00
parent c3024993c3
commit 34919de3df

View File

@@ -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 )