#include "qmapboxgl_scheduler.hpp" #include #include QMapboxGLScheduler::QMapboxGLScheduler() { } QMapboxGLScheduler::~QMapboxGLScheduler() { MBGL_VERIFY_THREAD(tid); } void QMapboxGLScheduler::schedule(std::function function) { std::lock_guard lock(m_taskQueueMutex); m_taskQueue.push(std::move(function)); // Need to force the main thread to wake // up this thread and process the events. emit needsProcessing(); } void QMapboxGLScheduler::processEvents() { std::queue> taskQueue; { std::unique_lock lock(m_taskQueueMutex); std::swap(taskQueue, m_taskQueue); } while (!taskQueue.empty()) { auto& function = taskQueue.front(); if (function) function(); taskQueue.pop(); } }