mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-09 08:41:14 +00:00
* Add Missing Includes Across src/libslic3r Every libslic3r source and header now directly includes the headers declaring what it uses, rather than relying on the precompiled header or transitive includes. Generated with clang-tidy misc-include-cleaner, with libslic3r headers spelled libslic3r/... so they resolve outside the library's private include paths. MultiMaterialSegmentation.hpp, Support/SupportParameters.hpp and Format/STEP.hpp are made self-contained by hand. * Make the libslic3r Headers Compile on Their Own Each now includes, or forward-declares, what it uses instead of relying on what its includers happened to include first. Left out: I18N.hpp, which errors on purpose when included from GUI code, and VoxelizeCSGMesh.hpp and SLA/bicubic.h, which nothing includes and which no longer compile at all. * Add the Includes Missing From the Hand-Fixed libslic3r Headers clang-tidy would not edit these headers while they failed to compile on their own, so the first pass skipped them. With the headers now self-contained, a second pass adds the rest. * Keep Windows Setup Ahead of the Added libslic3r Includes Print.cpp and Thread.cpp open with a _WIN32 block that has to come first; without the precompiled header, Print.cpp otherwise reaches windows.h through OCCT with NONLS defined and boost/regex fails. OpenVDBUtils.cpp and SLA/SupportTreeBuilder.cpp had includes inside #ifndef NOMINMAX, which libslic3r defines on Windows, so those were skipped there. .clang-tidy also ignores the MSVC STL and UCRT internals, Boost.Multiprecision's fwd.hpp and CPython's Windows include directory. * Re-Add libslic3r Includes After the Clipper2 2.0.1 Migration Rebasing onto main took main's version of the files the Clipper2 migration rewrote, so their added includes are restored here, along with includes for main's new code. Clipper2's individual headers are now ignored by clang-tidy: they only build the Z variant through clipper2_z.hpp, which defines USINGZ first, so including clipper.core.h and the like directly broke ClipperZUtils.cpp.
79 lines
3.4 KiB
C++
79 lines
3.4 KiB
C++
#ifndef GUI_THREAD_HPP
|
|
#define GUI_THREAD_HPP
|
|
|
|
#include <optional>
|
|
#include <utility>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <boost/thread.hpp>
|
|
|
|
namespace Slic3r {
|
|
|
|
// Set / get thread name.
|
|
// Returns false if the API is not supported.
|
|
//
|
|
// It is a good idea to name the main thread before spawning children threads, because dynamic linking is used on Windows 10
|
|
// to initialize Get/SetThreadDescription functions, which is not thread safe.
|
|
//
|
|
// pthread_setname_np supports maximum 15 character thread names! (16th character is the null terminator)
|
|
//
|
|
// Methods taking the thread as an argument are not supported by OSX.
|
|
// Naming threads is only supported on newer Windows 10.
|
|
|
|
bool set_thread_name(std::thread &thread, const char *thread_name);
|
|
inline bool set_thread_name(std::thread &thread, const std::string &thread_name) { return set_thread_name(thread, thread_name.c_str()); }
|
|
bool set_thread_name(boost::thread &thread, const char *thread_name);
|
|
inline bool set_thread_name(boost::thread &thread, const std::string &thread_name) { return set_thread_name(thread, thread_name.c_str()); }
|
|
bool set_current_thread_name(const char *thread_name);
|
|
inline bool set_current_thread_name(const std::string &thread_name) { return set_current_thread_name(thread_name.c_str()); }
|
|
|
|
// To be called at the start of the application to save the current thread ID as the main (UI) thread ID.
|
|
void save_main_thread_id();
|
|
// Retrieve the cached main (UI) thread ID.
|
|
boost::thread::id get_main_thread_id();
|
|
// Checks whether the main (UI) thread is active.
|
|
bool is_main_thread_active();
|
|
|
|
// Returns nullopt if not supported.
|
|
// Not supported by OSX.
|
|
// Naming threads is only supported on newer Windows 10.
|
|
std::optional<std::string> get_current_thread_name();
|
|
|
|
// To be called somewhere before the TBB threads are spinned for the first time, to
|
|
// give them names recognizible in the debugger.
|
|
// Also it sets locale of the worker threads to "C" for the G-code generator to produce "." as a decimal separator.
|
|
void name_tbb_thread_pool_threads_set_locale();
|
|
|
|
template<class Fn>
|
|
inline boost::thread create_thread(boost::thread::attributes &attrs, Fn &&fn)
|
|
{
|
|
// Stack size for our worker threads. Originally duplicated TBB's pool
|
|
// default (4 MB), but the Emboss text-cut path calls into CGAL's
|
|
// Polygon_mesh_processing::corefine, which falls back from filtered
|
|
// interval arithmetic to exact rational arithmetic (mpq_class) on
|
|
// near-degenerate input, and the constrained 2D triangulation walker
|
|
// (Triangulation_2::march_locate_2D) can recurse deeply enough to
|
|
// exceed 4 MB on real models -- producing a SIGBUS at the next thread's
|
|
// stack guard page on macOS / Linux.
|
|
//
|
|
// 16 MB chosen as 4x defensive headroom over the observed crash
|
|
// threshold (n=1 reproducer at exactly 4 MB on macOS arm64). All three
|
|
// platforms defer-commit reserved stack pages: macOS / Linux mmap the
|
|
// stack and only fault in pages on touch; Boost.Thread on Win32 passes
|
|
// STACK_SIZE_PARAM_IS_A_RESERVATION to _beginthreadex, so the value is
|
|
// a reserve, not the initial commit. Resident memory therefore stays
|
|
// proportional to actual stack depth on every target.
|
|
attrs.set_stack_size(16 * 1024 * 1024);
|
|
return boost::thread{attrs, std::forward<Fn>(fn)};
|
|
}
|
|
|
|
template<class Fn> inline boost::thread create_thread(Fn &&fn)
|
|
{
|
|
boost::thread::attributes attrs;
|
|
return create_thread(attrs, std::forward<Fn>(fn));
|
|
}
|
|
|
|
}
|
|
|
|
#endif // GUI_THREAD_HPP
|