Prevent multiple kiway from loading simultaneously

Each KIWAY_PLAYER has some initialization elements that may take time
before the frame is raised.  If handling is returned to the UI during
that load, we can cause reentrant issues for players.

Fixes https://gitlab.com/kicad/code/kicad/issues/4284

Fixes https://gitlab.com/kicad/code/kicad/issues/3743
This commit is contained in:
Seth Hillbrand 2020-06-04 16:35:20 -07:00
parent a844c3043c
commit 5b47d1a910
2 changed files with 16 additions and 0 deletions

View File

@ -36,6 +36,7 @@
#include <id.h>
#include <eda_base_frame.h>
#include <kiway_player.h>
#include <mutex>
#define KICAD_MANAGER_FRAME_NAME wxT( "KicadFrame" )
@ -304,6 +305,9 @@ private:
void language_change( wxCommandEvent& event );
bool m_active_project;
// Mutex to allow only a single KiFace to load at one time (released when loaded)
std::mutex m_loading;
};

View File

@ -316,6 +316,9 @@ void KICAD_MANAGER_FRAME::RunEeschema( const wxString& aProjectSchematicFileName
{
KIWAY_PLAYER* frame;
// Prevent multiple KiFace loading at one time
const std::lock_guard<std::mutex> lock( m_loading );
try
{
frame = Kiway().Player( FRAME_SCH, true );
@ -361,6 +364,9 @@ void KICAD_MANAGER_FRAME::OnRunSchLibEditor( wxCommandEvent& event )
{
KIWAY_PLAYER* frame;
// Prevent multiple KiFace loading at one time
const std::lock_guard<std::mutex> lock( m_loading );
try
{
frame = Kiway().Player( FRAME_SCH_LIB_EDITOR, true );
@ -387,6 +393,9 @@ void KICAD_MANAGER_FRAME::RunPcbNew( const wxString& aProjectBoardFileName )
{
KIWAY_PLAYER* frame;
// Prevent multiple KiFace loading at one time
const std::lock_guard<std::mutex> lock( m_loading );
try
{
frame = Kiway().Player( FRAME_PCB, true );
@ -430,6 +439,9 @@ void KICAD_MANAGER_FRAME::OnRunPcbFpEditor( wxCommandEvent& event )
{
KIWAY_PLAYER* frame;
// Prevent multiple KiFace loading at one time
const std::lock_guard<std::mutex> lock( m_loading );
try
{
frame = Kiway().Player( FRAME_PCB_MODULE_EDITOR, true );