//SPDX-License-Identifier: LGPL-3.0-only //SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® export module Crafter.Thread:ThreadPool; import std; namespace Crafter { struct ThreadStorage { std::vector> tasks; std::vector> buffer; std::condition_variable cv; std::mutex mutex; std::atomic taskCount; std::thread thread; }; export class ThreadPool { public: static inline std::atomic stopped; static void Start(int maxThreads = -1); static void Stop(); static void Enqueue(std::function task); static void Enqueue(std::vector> tasks); static void JoinPool(); static inline unsigned int threadCount; static inline std::atomic activeThreads; private: static inline std::unordered_map threadIdMap; static inline ThreadStorage* threadStorage; static void WaitAndExecuteTask(ThreadStorage* threadStorage); }; }