7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-03-30 05:36:55 +00:00

Revert "Move thread pool to singleton class"

This reverts commit 361f61a023.
This commit is contained in:
Seth Hillbrand 2025-01-03 21:22:44 -08:00
parent d4d0189157
commit 074e6df3bc
36 changed files with 181 additions and 135 deletions

View File

@ -32,7 +32,7 @@
#include "../color_rgba.h"
#include "3d_fastmath.h"
#include "3d_math.h"
#include <pgm_base.h>
#include <core/thread_pool.h>
#include <core/profile.h> // To use GetRunningMicroSecs or another profiling utility
#include <wx/log.h>
@ -190,7 +190,7 @@ void RENDER_3D_RAYTRACE_BASE::renderTracing( uint8_t* ptrPBO, REPORTER* aStatusR
std::atomic<size_t> numBlocksRendered( 0 );
std::atomic<size_t> currentBlock( 0 );
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
const int timeLimit = m_blockPositions.size() > 40000 ? 750 : 400;
auto processBlocks = [&]()

View File

@ -918,7 +918,6 @@ set( INC_BEFORE
set( INC_AFTER
${CMAKE_BINARY_DIR}
$<TARGET_PROPERTY:thread-pool,INTERFACE_INCLUDE_DIRECTORIES>
)
#

View File

@ -28,7 +28,7 @@
#include <lib_id.h>
#include <progress_reporter.h>
#include <string_utils.h>
#include <pgm_base.h>
#include <core/thread_pool.h>
#include <wildcards_and_files_ext.h>
#include <kiplatform/io.h>
@ -164,7 +164,7 @@ bool DESIGN_BLOCK_LIST_IMPL::ReadDesignBlockFiles( DESIGN_BLOCK_LIB_TABLE* aTabl
void DESIGN_BLOCK_LIST_IMPL::loadLibs()
{
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
size_t num_returns = m_queue_in.size();
std::vector<std::future<size_t>> returns( num_returns );
@ -221,7 +221,7 @@ void DESIGN_BLOCK_LIST_IMPL::loadDesignBlocks()
// TODO: blast LOCALE_IO into the sun
SYNC_QUEUE<std::unique_ptr<DESIGN_BLOCK_INFO>> queue_parsed;
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
size_t num_elements = m_queue_out.size();
std::vector<std::future<size_t>> returns( num_elements );

View File

@ -49,6 +49,7 @@
#include <macros.h>
#include <geometry/geometry_utils.h>
#include <core/thread_pool.h>
#include <core/profile.h>
#include <trace_helpers.h>

View File

@ -63,6 +63,7 @@
#include <settings/settings_manager.h>
#include <string_utils.h>
#include <systemdirsappend.h>
#include <core/thread_pool.h>
#include <trace_helpers.h>
#include <widgets/wx_splash.h>
@ -471,10 +472,6 @@ bool PGM_BASE::InitPgm( bool aHeadless, bool aSkipPyInit, bool aIsUnitTest )
#ifdef KICAD_USE_SENTRY
sentryInit();
#endif
// Initialize the singleton instance
m_singleton.Init();
wxString pgm_name;
/// Should never happen but boost unit_test isn't playing nicely in some cases

View File

@ -30,7 +30,6 @@
#include <core/kicad_algo.h>
#include <erc/erc.h>
#include <pin_type.h>
#include <pgm_base.h>
#include <sch_bus_entry.h>
#include <sch_symbol.h>
#include <sch_edit_frame.h>
@ -48,6 +47,7 @@
#include <project/net_settings.h>
#include <widgets/ui_common.h>
#include <string_utils.h>
#include <core/thread_pool.h>
#include <wx/log.h>
#include <advanced_config.h> // for realtime connectivity switch in release builds
@ -1344,7 +1344,7 @@ void CONNECTION_GRAPH::updateItemConnectivity( const SCH_SHEET_PATH& aSheet,
return 1;
};
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
tp.push_loop( connection_vec.size(),
[&]( const int a, const int b)
@ -1500,7 +1500,7 @@ void CONNECTION_GRAPH::resolveAllDrivers()
return 1;
};
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
tp.push_loop( dirty_graphs.size(),
[&]( const int a, const int b)
@ -2136,7 +2136,7 @@ void CONNECTION_GRAPH::buildConnectionGraph( std::function<void( SCH_ITEM* )>* a
for( CONNECTION_SUBGRAPH* subgraph : m_driver_subgraphs )
m_sheet_to_subgraphs_map[ subgraph->m_sheet ].emplace_back( subgraph );
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
tp.push_loop( m_driver_subgraphs.size(),
[&]( const int a, const int b)

View File

@ -26,7 +26,7 @@
#include <utility>
#include <pgm_base.h>
#include <core/thread_pool.h>
#include <ki_exception.h>
#include <sim/sim_library_spice.h>
#include <sim/spice_grammar.h>
@ -138,7 +138,7 @@ void SPICE_LIBRARY_PARSER::ReadFile( const wxString& aFilePath, REPORTER& aRepor
};
// Read all self-contained models in parallel
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
tp.push_loop( modelQueue.size(),
[&]( const int a, const int b )

View File

@ -32,7 +32,6 @@
#define PGM_BASE_H_
#include <kicommon.h>
#include <singleton.h>
#include <exception>
#include <map>
#include <vector>
@ -105,13 +104,33 @@ public:
PGM_BASE();
virtual ~PGM_BASE();
#if 0
/*
Derived classes must implement these two functions: OnPgmInit() and
OnPgmExit(), and since they are only called from same source file as their
implementation, these need not be virtual here. In fact, in the case of
python project manager's class PGM_PYTHON, these functions are actually
written in python. In total there are three implementations, corresponding
to the three defines given by kiface.h's KFCTL_* #defines.
*/
/**
* This is the first executed function (like main() ).
*
* @return true if the application can be started.
*/
virtual bool OnPgmInit() = 0; // call this from wxApp::OnInit()
virtual void OnPgmExit() = 0; // call this from wxApp::OnExit()
#endif
/**
* Builds the UTF8 based argv variable
*/
void BuildArgvUtf8();
BS::thread_pool& GetThreadPool() { return *m_singleton.m_ThreadPool; }
/**
* Specific to MacOSX (not used under Linux or Windows).
*
@ -410,8 +429,6 @@ protected:
wxString m_text_editor;
KICAD_SINGLETON m_singleton;
#ifdef KICAD_USE_SENTRY
wxFileName m_sentry_optin_fn;
wxFileName m_sentry_uid_fn;

View File

@ -1,48 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KICAD_SINGLETON_H
#define KICAD_SINGLETON_H
#include <bs_thread_pool.hpp>
class KICAD_SINGLETON
{
public:
KICAD_SINGLETON(){};
~KICAD_SINGLETON()
{
// This will wait for all threads to finish and then join them to the main thread
delete m_ThreadPool;
m_ThreadPool = nullptr;
};
void Init()
{
m_ThreadPool = new BS::thread_pool();
}
BS::thread_pool* m_ThreadPool;
};
#endif // KICAD_SINGLETON_H

View File

@ -5,7 +5,6 @@ if( COMPILER_SUPPORTS_WARNINGS )
endif()
include_directories( BEFORE ${INC_BEFORE} )
include_directories( AFTER ${INC_AFTER} )
add_compile_definitions( PCM )

View File

@ -48,8 +48,10 @@
#include <wx/notifmsg.h>
#include <background_jobs_monitor.h>
#include <core/thread_pool.h>
#include <build_version.h>
#include <pgm_base.h>
struct UPDATE_REQUEST
@ -259,6 +261,6 @@ void UPDATE_MANAGER::CheckForUpdate( wxWindow* aNoticeParent )
m_working = false;
};
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
tp.push_task( update_check );
}

View File

@ -10,6 +10,7 @@ add_library( core STATIC
observable.cpp
profile.cpp
utf8.cpp
thread_pool.cpp
version_compare.cpp
wx_stl_compat.cpp
)
@ -20,6 +21,7 @@ target_link_libraries( core PUBLIC
target_include_directories( core PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
$<TARGET_PROPERTY:thread-pool,INTERFACE_INCLUDE_DIRECTORIES>
PRIVATE
${CMAKE_BINARY_DIR} # to get config.h
)

View File

@ -0,0 +1,42 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright The KiCad Developers, see CHANGELOG.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/gpl-3.0.html
* or you may search the http://www.gnu.org website for the version 3 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#pragma once
#ifndef INCLUDE_THREAD_POOL_H_
#define INCLUDE_THREAD_POOL_H_
#include <bs_thread_pool.hpp>
using thread_pool = BS::thread_pool;
/**
* Get a reference to the current thread pool. N.B., you cannot copy the thread pool
* so if you accidentally write thread_pool tp = GetKiCadThreadPool(), you will break
* your compilation
*
* @return Reference to the current (potentially newly constructed) thread pool
*/
thread_pool& GetKiCadThreadPool();
#endif /* INCLUDE_THREAD_POOL_H_ */

41
libs/core/thread_pool.cpp Normal file
View File

@ -0,0 +1,41 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright The KiCad Developers, see CHANGELOG.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/gpl-3.0.html
* or you may search the http://www.gnu.org website for the version 3 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <core/thread_pool.h>
// Under mingw, there is a problem with the destructor when creating a static instance
// of a thread_pool: probably the DTOR is called too late, and the application hangs.
// so we create it on the heap.
static thread_pool* tp = nullptr;
thread_pool& GetKiCadThreadPool()
{
#if 0 // Turn this on to disable multi-threading for debugging
if( !tp ) tp = new thread_pool( 1 );
#else
if( !tp ) tp = new thread_pool;
#endif
return *tp;
}

View File

@ -63,6 +63,7 @@
#include <tool/tool_manager.h>
#include <tool/selection_conditions.h>
#include <string_utils.h>
#include <core/thread_pool.h>
#include <zone.h>
#include <mutex>
@ -981,7 +982,7 @@ void BOARD::CacheTriangulation( PROGRESS_REPORTER* aReporter, const std::vector<
if( aReporter )
aReporter->Report( _( "Tessellating copper zones..." ) );
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
std::vector<std::future<size_t>> returns;
returns.reserve( zones.size() );

View File

@ -33,8 +33,8 @@
#include <progress_reporter.h>
#include <geometry/geometry_utils.h>
#include <board_commit.h>
#include <core/thread_pool.h>
#include <pcb_shape.h>
#include <pgm_base.h>
#include <wx/log.h>
@ -249,7 +249,7 @@ void CN_CONNECTIVITY_ALGO::searchConnections()
PROF_TIMER search_basic( "search-basic" );
#endif
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
std::vector<CN_ITEM*> dirtyItems;
std::copy_if( m_itemList.begin(), m_itemList.end(), std::back_inserter( dirtyItems ),
[] ( CN_ITEM* aItem )
@ -495,7 +495,7 @@ void CN_CONNECTIVITY_ALGO::Build( BOARD* aBoard, PROGRESS_REPORTER* aReporter )
// Generate RTrees for CN_ZONE_LAYER items (in parallel)
//
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
std::vector<std::future<size_t>> returns( zitems.size() );
auto cache_zones =

View File

@ -39,8 +39,8 @@
#include <geometry/shape_segment.h>
#include <geometry/shape_circle.h>
#include <ratsnest/ratsnest_data.h>
#include <pgm_base.h>
#include <progress_reporter.h>
#include <core/thread_pool.h>
#include <trigo.h>
#include <drc/drc_rtree.h>
@ -190,7 +190,7 @@ void CONNECTIVITY_DATA::updateRatsnest()
return aNet->IsDirty() && aNet->GetNodeCount() > 0;
} );
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
tp.push_loop( dirty_nets.size(),
[&]( const int a, const int b )
@ -371,7 +371,7 @@ void CONNECTIVITY_DATA::ComputeLocalRatsnest( const std::vector<BOARD_ITEM*>& aI
}
};
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
size_t num_nets = std::min( m_nets.size(), aDynamicData->m_nets.size() );
tp.push_loop( 1, num_nets,

View File

@ -37,6 +37,7 @@
#include <set>
#include <vector>
#include <core/thread_pool.h>
#include <io/io_mgr.h>
#include <jobs/job_export_pcb_odb.h>
#include <pcb_io/pcb_io_mgr.h>
@ -466,7 +467,7 @@ void DIALOG_EXPORT_ODBPP::GenerateODBPPFiles( const JOB_EXPORT_PCB_ODB& aJob, BO
}
};
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
auto ret = tp.submit( saveFile );
std::future_status status = ret.wait_for( std::chrono::milliseconds( 250 ) );

View File

@ -24,7 +24,7 @@
#include <common.h>
#include <board_design_settings.h>
#include <footprint.h>
#include <pgm_base.h>
#include <core/thread_pool.h>
#include <zone.h>
#include <connectivity/connectivity_data.h>
#include <drc/drc_engine.h>
@ -36,11 +36,11 @@ bool DRC_CACHE_GENERATOR::Run()
{
m_board = m_drcEngine->GetBoard();
int& largestClearance = m_board->m_DRCMaxClearance;
int& largestPhysicalClearance = m_board->m_DRCMaxPhysicalClearance;
DRC_CONSTRAINT worstConstraint;
LSET boardCopperLayers = LSET::AllCuMask( m_board->GetCopperLayerCount() );
BS::thread_pool& tp = Pgm().GetThreadPool();
int& largestClearance = m_board->m_DRCMaxClearance;
int& largestPhysicalClearance = m_board->m_DRCMaxPhysicalClearance;
DRC_CONSTRAINT worstConstraint;
LSET boardCopperLayers = LSET::AllCuMask( m_board->GetCopperLayerCount() );
thread_pool& tp = GetKiCadThreadPool();
largestClearance = std::max( largestClearance, m_board->GetMaxClearanceValue() );

View File

@ -41,6 +41,7 @@
#include <pad.h>
#include <pcb_track.h>
#include <core/profile.h>
#include <core/thread_pool.h>
#include <zone.h>

View File

@ -45,9 +45,9 @@
#include <math/vector2d.h>
#include <pcb_shape.h>
#include <progress_reporter.h>
#include <core/thread_pool.h>
#include <pcb_track.h>
#include <pad.h>
#include <pgm_base.h>
#include <zone.h>
/*
@ -520,7 +520,7 @@ bool DRC_TEST_PROVIDER_CONNECTION_WIDTH::Run()
}
}
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
std::vector<std::future<size_t>> returns;
size_t total_effort = 0;

View File

@ -29,7 +29,7 @@
#include <pcb_shape.h>
#include <pad.h>
#include <pcb_track.h>
#include <pgm_base.h>
#include <core/thread_pool.h>
#include <zone.h>
#include <geometry/seg.h>
@ -724,7 +724,7 @@ void DRC_TEST_PROVIDER_COPPER_CLEARANCE::testTrackClearances()
}
};
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
tp.push_loop( m_board->Tracks().size(), testTrack );
@ -978,7 +978,7 @@ void DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadAgainstItem( PAD* pad, SHAPE* pa
void DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadClearances( )
{
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
size_t count = 0;
std::atomic<size_t> done( 1 );
@ -1062,7 +1062,7 @@ void DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadClearances( )
void DRC_TEST_PROVIDER_COPPER_CLEARANCE::testGraphicClearances( )
{
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
size_t count = m_board->Drawings().size();
std::atomic<size_t> done( 1 );
@ -1226,7 +1226,7 @@ void DRC_TEST_PROVIDER_COPPER_CLEARANCE::testZonesToZones()
using report_data = std::tuple<int, int, VECTOR2I, int, int, PCB_LAYER_ID>;
std::vector<std::future<report_data>> futures;
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
std::atomic<size_t> done( 1 );
auto checkZones =

View File

@ -31,7 +31,7 @@
#include <drc/drc_test_provider.h>
#include <pad.h>
#include <progress_reporter.h>
#include <pgm_base.h>
#include <core/thread_pool.h>
#include <zone.h>
#include <mutex>
@ -173,7 +173,7 @@ bool DRC_TEST_PROVIDER_DISALLOW::Run()
return 1;
};
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
std::vector<std::future<size_t>> returns;
returns.reserve( toCache.size() );

View File

@ -22,19 +22,18 @@
*/
#include <atomic>
#include <advanced_config.h>
#include <board.h>
#include <board_design_settings.h>
#include <drc/drc_item.h>
#include <drc/drc_rule.h>
#include <drc/drc_test_provider.h>
#include <footprint.h>
#include <geometry/shape_poly_set.h>
#include <pcb_shape.h>
#include <pgm_base.h>
#include <progress_reporter.h>
#include <zone.h>
#include <footprint.h>
#include <pcb_shape.h>
#include <geometry/shape_poly_set.h>
#include <drc/drc_rule.h>
#include <drc/drc_item.h>
#include <drc/drc_test_provider.h>
#include <advanced_config.h>
#include <progress_reporter.h>
#include <core/thread_pool.h>
/*
Checks for slivers in copper layers
@ -161,7 +160,7 @@ bool DRC_TEST_PROVIDER_SLIVER_CHECKER::Run()
return 1;
};
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
std::vector<std::future<size_t>> returns;
returns.reserve( copperLayers.size() );

View File

@ -21,16 +21,15 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <core/thread_pool.h>
#include "geometry/eda_angle.h"
#include <numbers>
#include <connectivity/connectivity_data.h>
#include <pcb_track.h>
#include <drc/drc_engine.h>
#include <drc/drc_item.h>
#include <drc/drc_rule.h>
#include <drc/drc_test_provider.h>
#include <geometry/eda_angle.h>
#include <pcb_track.h>
#include <pgm_base.h>
#include <connectivity/connectivity_data.h>
/*
@ -205,7 +204,7 @@ bool DRC_TEST_PROVIDER_TRACK_ANGLE::Run()
const int progressDelta = 250;
int ii = 0;
BS::thread_pool& tp = Pgm().GetThreadPool();
thread_pool& tp = GetKiCadThreadPool();
std::vector<std::future<bool>> returns;
returns.reserve( m_drcEngine->GetBoard()->Tracks().size() );

Some files were not shown because too many files have changed in this diff Show More