Use a shared_mutex to read/write lock the nickIndex
Fixes sentry kicad-ax
This commit is contained in:
parent
c7bb6f5778
commit
e053fbefd7
|
@ -193,6 +193,8 @@ LIB_TABLE_ROW* LIB_TABLE::findRow( const wxString& aNickName, bool aCheckIfEnabl
|
||||||
{
|
{
|
||||||
cur->ensureIndex();
|
cur->ensureIndex();
|
||||||
|
|
||||||
|
std::shared_lock<std::shared_mutex> lock( m_nickIndexMutex );
|
||||||
|
|
||||||
for( const std::pair<const wxString, int>& entry : cur->m_nickIndex )
|
for( const std::pair<const wxString, int>& entry : cur->m_nickIndex )
|
||||||
{
|
{
|
||||||
if( entry.first == aNickName )
|
if( entry.first == aNickName )
|
||||||
|
@ -303,7 +305,7 @@ bool LIB_TABLE::InsertRow( LIB_TABLE_ROW* aRow, bool doReplace )
|
||||||
{
|
{
|
||||||
ensureIndex();
|
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() );
|
INDEX_CITER it = m_nickIndex.find( aRow->GetNickName() );
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include <boost/noncopyable.hpp>
|
#include <boost/noncopyable.hpp>
|
||||||
#include <boost/ptr_container/ptr_vector.hpp>
|
#include <boost/ptr_container/ptr_vector.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <shared_mutex>
|
||||||
#include <project.h>
|
#include <project.h>
|
||||||
#include <string_utf8_map.h>
|
#include <string_utf8_map.h>
|
||||||
#include <richio.h>
|
#include <richio.h>
|
||||||
|
@ -329,7 +329,7 @@ public:
|
||||||
/// Delete all rows.
|
/// Delete all rows.
|
||||||
void Clear()
|
void Clear()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock( m_nickIndexMutex );
|
std::lock_guard<std::shared_mutex> lock( m_nickIndexMutex );
|
||||||
|
|
||||||
m_rows.clear();
|
m_rows.clear();
|
||||||
m_nickIndex.clear();
|
m_nickIndex.clear();
|
||||||
|
@ -541,7 +541,7 @@ protected:
|
||||||
|
|
||||||
void reindex()
|
void reindex()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock( m_nickIndexMutex );
|
std::lock_guard<std::shared_mutex> lock( m_nickIndexMutex );
|
||||||
|
|
||||||
m_nickIndex.clear();
|
m_nickIndex.clear();
|
||||||
|
|
||||||
|
@ -580,7 +580,7 @@ protected:
|
||||||
mutable int m_version;
|
mutable int m_version;
|
||||||
|
|
||||||
/// Mutex to protect access to the nickIndex variable
|
/// Mutex to protect access to the nickIndex variable
|
||||||
mutable std::mutex m_nickIndexMutex;
|
mutable std::shared_mutex m_nickIndexMutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _LIB_TABLE_BASE_H_
|
#endif // _LIB_TABLE_BASE_H_
|
||||||
|
|
Loading…
Reference in New Issue