Use a shared_mutex to read/write lock the nickIndex

Fixes sentry kicad-ax
This commit is contained in:
Marek Roszko 2023-02-18 10:14:52 -05:00
parent c7bb6f5778
commit e053fbefd7
2 changed files with 7 additions and 5 deletions

View File

@ -193,6 +193,8 @@ LIB_TABLE_ROW* LIB_TABLE::findRow( const wxString& aNickName, bool aCheckIfEnabl
{
cur->ensureIndex();
std::shared_lock<std::shared_mutex> lock( m_nickIndexMutex );
for( const std::pair<const wxString, int>& entry : cur->m_nickIndex )
{
if( entry.first == aNickName )
@ -303,7 +305,7 @@ bool LIB_TABLE::InsertRow( LIB_TABLE_ROW* aRow, bool doReplace )
{
ensureIndex();
std::lock_guard<std::mutex> lock( m_nickIndexMutex );
std::lock_guard<std::shared_mutex> lock( m_nickIndexMutex );
INDEX_CITER it = m_nickIndex.find( aRow->GetNickName() );

View File

@ -30,7 +30,7 @@
#include <boost/noncopyable.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
#include <memory>
#include <mutex>
#include <shared_mutex>
#include <project.h>
#include <string_utf8_map.h>
#include <richio.h>
@ -329,7 +329,7 @@ public:
/// Delete all rows.
void Clear()
{
std::lock_guard<std::mutex> lock( m_nickIndexMutex );
std::lock_guard<std::shared_mutex> lock( m_nickIndexMutex );
m_rows.clear();
m_nickIndex.clear();
@ -541,7 +541,7 @@ protected:
void reindex()
{
std::lock_guard<std::mutex> lock( m_nickIndexMutex );
std::lock_guard<std::shared_mutex> lock( m_nickIndexMutex );
m_nickIndex.clear();
@ -580,7 +580,7 @@ protected:
mutable int m_version;
/// Mutex to protect access to the nickIndex variable
mutable std::mutex m_nickIndexMutex;
mutable std::shared_mutex m_nickIndexMutex;
};
#endif // _LIB_TABLE_BASE_H_