#pragma once #include #include "Core/Statistics/Frequency_Limit.h" #include #include #include #include #include #include #include #include struct Detach_Thread { explicit Detach_Thread( std::string_view name, const std::function &running)> &func); void start(); std::string name; std::thread thread; std::atomic running = true; // 控制运行 std::atomic exit = false; }; struct Detach_Thread_Manager { Detach_Thread_Manager() = default; void test_and_start_thread( std::string_view name, const std::function &running)> &func); void test_and_stop_thread(std::string_view name); void stop_all_thread(size_t timeout_milliseconds = 10000, std::set excluded_thread = {}); Detach_Thread *get_thread(const std::thread::id thread_id); protected: Frequency_Limit fl; std::map thread_map; void exit_thread(std::string_view name); void start_thread(std::string_view name, const std::function &)> &f); std::chrono::time_point exit_time; };