#include #include #include namespace mbgl { namespace util { WorkQueue::WorkQueue() : runLoop(RunLoop::Get()) { } WorkQueue::~WorkQueue() { assert(runLoop == RunLoop::Get()); // Cancel all pending AsyncRequests. while (!queue.empty()) { queue.pop(); } } void WorkQueue::push(std::function&& fn) { std::lock_guard lock(queueMutex); auto workRequest = runLoop->invokeCancellable(std::bind(&WorkQueue::pop, this, std::move(fn))); queue.push(std::move(workRequest)); } void WorkQueue::pop(const std::function& fn) { assert(runLoop == RunLoop::Get()); fn(); std::lock_guard lock(queueMutex); queue.pop(); } } // namespace util } // namespace mbgl