From 068076a2c287ee3939266393b678beccd6775efd Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Tue, 21 Jan 2014 00:59:32 -0600 Subject: [PATCH] tugs and bugs --- CMakeLists.txt | 25 ++++++++++++++++--------- CMakeModules/download_boost.cmake | 1 + common/footprint_info.cpp | 10 ++++++++++ include/common.h | 18 +++++++++++++++--- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a38d84220..e04eb7b4b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,9 @@ set( CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules ) # reports. # +option( USE_KIWAY_DLLS + "Build the major modules as DLLs or DSOs, will soon be the norm." OFF ) + #for those who bored with uppercase option( KICAD_KEEPCASE "turn-off automatic component name conversion to uppercase if selected" ) @@ -146,22 +149,26 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) endif() else() - # We build DLL/DSOs from static libraries, so create position independent code - # for all cases, since we do not have DLL/DSO specific static libraries. - # Subdirectories via add_subdirectores() reference this variable, and it is either set or empty, - # empty for Windows. + # We build DLL/DSOs from static libraries, so create position independent + # code for all cases, since we do not have DLL/DSO specific static + # libraries. Subdirectories via add_subdirectores() reference this + # variable, and it is either set or empty, empty for Windows. set( PIC_FLAG -fPIC ) - set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PIC_FLAG}" ) + set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PIC_FLAG}" ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PIC_FLAG}" ) + if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) + set( TO_LINKER -XLinker ) + else() + set( TO_LINKER -Wl ) + endif() + # Thou shalt not link vaporware and tell us it's a valid DSO: - set( CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined" ) - set( CMAKE_MODULE_LINKER_FLAGS "-Wl,--no-undefined" ) # needed by SWIG macros on linux + set( CMAKE_SHARED_LINKER_FLAGS "${TO_LINKER},--no-undefined" ) + set( CMAKE_MODULE_LINKER_FLAGS "${TO_LINKER},--no-undefined" ) - # Set default flags for Release build. set( CMAKE_EXE_LINKER_FLAGS_RELEASE "-s" ) - endif() # quiet GCC 4.8.1 while in boost diff --git a/CMakeModules/download_boost.cmake b/CMakeModules/download_boost.cmake index dd72e7c565..b9c1d39d3f 100644 --- a/CMakeModules/download_boost.cmake +++ b/CMakeModules/download_boost.cmake @@ -170,6 +170,7 @@ endif() ExternalProject_Add( boost PREFIX "${PREFIX}" + TIMEOUT 60 DOWNLOAD_DIR "${DOWNLOAD_DIR}" INSTALL_DIR "${BOOST_ROOT}" URL http://downloads.sourceforge.net/project/boost/boost/${BOOST_RELEASE}/boost_${BOOST_VERS}.tar.bz2 diff --git a/common/footprint_info.cpp b/common/footprint_info.cpp index 4396ec66c1..99d9cd4a9b 100644 --- a/common/footprint_info.cpp +++ b/common/footprint_info.cpp @@ -205,6 +205,16 @@ bool FOOTPRINT_LIST::ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxString* a #if USE_WORKER_THREADS + // Even though the PLUGIN API implementation is the place for the + // locale toggling, in order to keep LOCAL_IO::C_count at 1 or greater + // for the duration of all helper threads, we increment by one here via instantiation. + // Only done here because of the multi-threaded nature of this code. + // Without this C_count skips in and out of "equal to zero" and causes + // needless locale toggling among the threads, based on which of them + // are in a PLUGIN::FootprintLoad() function. And that is occasionally + // none of them. + LOCALE_IO top_most_nesting; + // Something which will not invoke a thread copy constructor, one of many ways obviously: typedef boost::ptr_vector< boost::thread > MYTHREADS; diff --git a/include/common.h b/include/common.h index 004cfbe1c9..ca40fca2b5 100644 --- a/include/common.h +++ b/include/common.h @@ -433,18 +433,30 @@ class LOCALE_IO public: LOCALE_IO() { - if( C_count++ == 0 ) + wxASSERT_MSG( C_count >= 0, wxT( "LOCALE_IO::C_count mismanaged." ) ); + + // use thread safe, atomic operation + if( __sync_fetch_and_add( &C_count, 1 ) == 0 ) + { + // printf( "setting C locale.\n" ); SetLocaleTo_C_standard(); + } } ~LOCALE_IO() { - if( --C_count == 0 ) + // use thread safe, atomic operation + if( __sync_sub_and_fetch( &C_count, 1 ) == 0 ) + { + // printf( "restoring default locale.\n" ); SetLocaleTo_Default(); + } + + wxASSERT_MSG( C_count >= 0, wxT( "LOCALE_IO::C_count mismanaged." ) ); } private: - static int C_count; // allow for nesting of LOCALE_IO instantiations + static int C_count; // allow for nesting of LOCALE_IO instantiations };