@ -23,7 +23,6 @@
# include <algorithm>
# include <mutex>
# include <shared_mutex>
# include <typeinfo>
# include <core/wx_stl_compat.h> // for wxString hash
# include <settings/color_settings.h>
@ -68,11 +67,7 @@ public:
template < typename T >
T * RegisterSettings ( T * aSettings , bool aLoadNow = true )
{
/ / Throws a low chance of conflict with GetAppSettings in threads but let ' s lock anyway
std : : unique_lock < std : : shared_mutex > writeLock ( m_settings_mutex ) ;
return static_cast < T * > (
registerSettings ( aSettings , aLoadNow ) ) ;
return static_cast < T * > ( registerSettings ( aSettings , aLoadNow ) ) ;
}
void Load ( ) ;
@ -100,32 +95,17 @@ public:
* @ return a pointer to a loaded settings object
*/
template < typename T >
T * GetAppSettings ( bool aLoadNow = true )
T * GetAppSettings ( )
{
T * ret = nullptr ;
size_t typeHash = typeid ( T ) . hash_code ( ) ;
std : : shared_lock < std : : shared_mutex > readLock ( m_settings_mutex ) ;
if ( m_app_settings_cache . count ( typeHash ) )
ret = dynamic_cast < T * > ( m_app_settings_cache . at ( typeHash ) ) ;
if ( ret )
return ret ;
/ / cache lookup failed , now we shift to an exclusive lock to update the cache
readLock . unlock ( ) ;
std : : unique_lock < std : : shared_mutex > writeLock ( m_settings_mutex ) ;
/ / In case multiple threads ended up waiting to unique lock to handle the same setting object
/ / This happens with library loading for example
if ( m_app_settings_cache . count ( typeHash ) )
{
T * recheck = dynamic_cast < T * > ( m_app_settings_cache . at ( typeHash ) ) ;
if ( recheck )
return recheck ;
}
auto it = std : : find_if ( m_settings . begin ( ) , m_settings . end ( ) ,
[ ] ( const std : : unique_ptr < JSON_SETTINGS > & aSettings )
{
@ -138,13 +118,7 @@ public:
}
else
{
try
{
ret = static_cast < T * > ( registerSettings ( new T , aLoadNow ) ) ;
}
catch ( . . . )
{
}
throw std : : runtime_error ( " Tried to GetAppSettings before registering " ) ;
}
m_app_settings_cache [ typeHash ] = ret ;
@ -475,9 +449,6 @@ private:
/ / / Lock for loaded project ( expand to multiple once we support MDI )
std : : unique_ptr < wxSingleInstanceChecker > m_project_lock ;
/ / / Mutex to protect read / write access to m_settings and m_app_settings_cache
std : : shared_mutex m_settings_mutex ;
static wxString backupDateTimeFormat ;
} ;