diff options
author | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2018-06-06 14:15:15 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2018-06-15 19:33:27 +0300 |
commit | a5ef72a0516495ebc1663e015ca93d4178e9d091 (patch) | |
tree | b807518f624b659a7dc681657815ce047e508b36 /platform/qt/src/qmapboxgl_scheduler.cpp | |
parent | 144c167274f629523d265b9a54326ff544133413 (diff) | |
download | qtlocation-mapboxgl-a5ef72a0516495ebc1663e015ca93d4178e9d091.tar.gz |
Use a shared scheduler on threads without a default scheduler
Render threads won't have a scheduler, so we create one that is
shared by all the maps rendering at this thread. The bad side
effect of this is that we need to wake up the render thread
to process events.
Mapbox GL should get rid of processing events on the render
thread. This solution is a workaround.
Diffstat (limited to 'platform/qt/src/qmapboxgl_scheduler.cpp')
-rw-r--r-- | platform/qt/src/qmapboxgl_scheduler.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/platform/qt/src/qmapboxgl_scheduler.cpp b/platform/qt/src/qmapboxgl_scheduler.cpp new file mode 100644 index 0000000000..e2d39703ee --- /dev/null +++ b/platform/qt/src/qmapboxgl_scheduler.cpp @@ -0,0 +1,38 @@ +#include "qmapboxgl_scheduler.hpp" + +#include <mbgl/util/util.hpp> + +#include <cassert> + +QMapboxGLScheduler::QMapboxGLScheduler() +{ +} + +QMapboxGLScheduler::~QMapboxGLScheduler() +{ + MBGL_VERIFY_THREAD(tid); +} + +void QMapboxGLScheduler::schedule(std::weak_ptr<mbgl::Mailbox> mailbox) +{ + std::lock_guard<std::mutex> lock(m_taskQueueMutex); + m_taskQueue.push(mailbox); + + // Need to force the main thread to wake + // up this thread and process the events. + emit needsProcessing(); +} + +void QMapboxGLScheduler::processEvents() +{ + std::queue<std::weak_ptr<mbgl::Mailbox>> taskQueue; + { + std::unique_lock<std::mutex> lock(m_taskQueueMutex); + std::swap(taskQueue, m_taskQueue); + } + + while (!taskQueue.empty()) { + mbgl::Mailbox::maybeReceive(taskQueue.front()); + taskQueue.pop(); + } +} |