#include #include #include #include namespace mbgl { namespace util { static ThreadLocal& current = *new ThreadLocal; static RunLoop mainRunLoop; class RunLoop::Impl { public: std::unique_ptr async; }; RunLoop* RunLoop::Get() { assert(current.get()); return current.get(); } RunLoop::RunLoop(Type) : impl(std::make_unique()) { current.set(this); impl->async = std::make_unique(std::bind(&RunLoop::process, this)); } RunLoop::~RunLoop() { current.set(nullptr); } void RunLoop::push(std::shared_ptr task) { withMutex([&] { queue.push(std::move(task)); }); impl->async->send(); } void RunLoop::run() { CFRunLoopRun(); } void RunLoop::runOnce() { CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false); } void RunLoop::stop() { invoke([&] { CFRunLoopStop(CFRunLoopGetCurrent()); }); } } // namespace util } // namespace mbgl