From e166d821f90ab6229229a9267ef17c60206ca86a Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 5 Apr 2018 22:40:02 +0100 Subject: [PATCH 2/2] Workaround for wxString's lack of thread safety. MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2.15.1 (Apple Git-101)" This is a multi-part message in MIME format. --------------2.15.1 (Apple Git-101) Content-Type: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding: 8bit --- pcbnew/board_items_to_polygon_shape_transform.cpp | 4 ++++ pcbnew/class_pcb_text.h | 13 +++++++++++++ 2 files changed, 17 insertions(+) --------------2.15.1 (Apple Git-101) Content-Type: text/x-patch; name="0002-Workaround-for-wxString-s-lack-of-thread-safety.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="0002-Workaround-for-wxString-s-lack-of-thread-safety.patch" diff --git a/pcbnew/board_items_to_polygon_shape_transform.cpp b/pcbnew/board_items_to_polygon_shape_transform.cpp index 8724b32f7..a1a31d81f 100644 --- a/pcbnew/board_items_to_polygon_shape_transform.cpp +++ b/pcbnew/board_items_to_polygon_shape_transform.cpp @@ -405,6 +405,10 @@ void TEXTE_PCB::TransformBoundingBoxWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer, int aClearanceValue ) const { + // Oh dear. When in UTF-8 mode, wxString puts string iterators in a linked list, and + // that linked list is not thread-safe. + std::lock_guard guard( m_mutex ); + if( GetText().Length() == 0 ) return; diff --git a/pcbnew/class_pcb_text.h b/pcbnew/class_pcb_text.h index 24bc52212..c84f7b444 100644 --- a/pcbnew/class_pcb_text.h +++ b/pcbnew/class_pcb_text.h @@ -40,6 +40,17 @@ class EDA_DRAW_PANEL; class MSG_PANEL_ITEM; +// A mutex which is unique to each instance it appears in (ie: a new std::mutex is allocated +// on copy or assignment). +class UNIQUE_MUTEX : public std::mutex +{ +public: + UNIQUE_MUTEX() : std::mutex() {} + UNIQUE_MUTEX( const UNIQUE_MUTEX& ) : std::mutex() {} + UNIQUE_MUTEX& operator= (const UNIQUE_MUTEX& ) { return *this; } +}; + + class TEXTE_PCB : public BOARD_ITEM, public EDA_TEXT { public: @@ -142,6 +153,8 @@ public: virtual void SwapData( BOARD_ITEM* aImage ) override; + mutable UNIQUE_MUTEX m_mutex; + #if defined(DEBUG) virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } #endif --------------2.15.1 (Apple Git-101)--