#pragma once #include #include #include #include #include #include #ifdef main #undef main #endif namespace NXKit { struct DispatchQueueTask { std::function func; Timer delay; }; class DispatchQueue { public: explicit DispatchQueue(const std::string& tag); ~DispatchQueue(); static std::shared_ptr main(); static std::shared_ptr global(); [[nodiscard]] std::string tag() const { return _tag; } void async(const std::function& task); void asyncAfter(double seconds, const std::function& task); [[nodiscard]] bool isActive() const { return _task_loop_active; } private: static std::shared_ptr _main; static std::shared_ptr _global; std::queue _queue; std::string _tag; pthread_t _task_loop_thread = nullptr; std::mutex _m_async_mutex; volatile bool _task_loop_active = true; static void* task_loop(void* a); void performAll(); friend bool applicationRunLoop(); }; }