Browse Source
Move thread pool to singleton class
Move thread pool to singleton class
Having thread pool as its own singleton in the library meant that each kiface had its own threadpool, leading to many multiples of the threads being started. Placing a singleton class in PGM_BASE ensures that all kifaces use the same thread pool. The singleton class can be extended to provide single instance guarantee for any element across kifacespcb_db
36 changed files with 133 additions and 179 deletions
-
43d-viewer/3d_rendering/raytracing/render_3d_raytrace_base.cpp
-
1CMakeLists.txt
-
6common/design_block_info_impl.cpp
-
1common/gal/opengl/opengl_gal.cpp
-
5common/pgm_base.cpp
-
8eeschema/connection_graph.cpp
-
4eeschema/sim/spice_library_parser.cpp
-
27include/pgm_base.h
-
48include/singleton.h
-
1kicad/pcm/CMakeLists.txt
-
6kicad/update_manager.cpp
-
2libs/core/CMakeLists.txt
-
42libs/core/include/core/thread_pool.h
-
41libs/core/thread_pool.cpp
-
3pcbnew/board.cpp
-
6pcbnew/connectivity/connectivity_algo.cpp
-
6pcbnew/connectivity/connectivity_data.cpp
-
3pcbnew/dialogs/dialog_export_odbpp.cpp
-
12pcbnew/drc/drc_cache_generator.cpp
-
1pcbnew/drc/drc_engine.cpp
-
4pcbnew/drc/drc_test_provider_connection_width.cpp
-
10pcbnew/drc/drc_test_provider_copper_clearance.cpp
-
4pcbnew/drc/drc_test_provider_disallow.cpp
-
17pcbnew/drc/drc_test_provider_sliver_checker.cpp
-
11pcbnew/drc/drc_test_provider_track_angle.cpp
-
6pcbnew/drc/drc_test_provider_track_segment_length.cpp
-
8pcbnew/drc/drc_test_provider_zone_connections.cpp
-
3pcbnew/files.cpp
-
6pcbnew/footprint_info_impl.cpp
-
4pcbnew/tracks_cleaner.cpp
-
4pcbnew/zone_filler.cpp
-
1qa/qa_utils/CMakeLists.txt
-
2qa/tests/CMakeLists.txt
-
2qa/tests/gerbview/CMakeLists.txt
-
2qa/tests/libs/kimath/CMakeLists.txt
-
1scripting/CMakeLists.txt
@ -0,0 +1,48 @@ |
|||
/* |
|||
* 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 |
@ -1,42 +0,0 @@ |
|||
/* |
|||
* 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_ */ |
@ -1,41 +0,0 @@ |
|||
/*
|
|||
* 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; |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue