1 #include "qmapboxgl_scheduler.hpp"
2 
3 #include <mbgl/util/util.hpp>
4 
5 #include <cassert>
6 
QMapboxGLScheduler()7 QMapboxGLScheduler::QMapboxGLScheduler()
8 {
9 }
10 
~QMapboxGLScheduler()11 QMapboxGLScheduler::~QMapboxGLScheduler()
12 {
13     MBGL_VERIFY_THREAD(tid);
14 }
15 
schedule(std::weak_ptr<mbgl::Mailbox> mailbox)16 void QMapboxGLScheduler::schedule(std::weak_ptr<mbgl::Mailbox> mailbox)
17 {
18     std::lock_guard<std::mutex> lock(m_taskQueueMutex);
19     m_taskQueue.push(mailbox);
20 
21     // Need to force the main thread to wake
22     // up this thread and process the events.
23     emit needsProcessing();
24 }
25 
processEvents()26 void QMapboxGLScheduler::processEvents()
27 {
28     std::queue<std::weak_ptr<mbgl::Mailbox>> taskQueue;
29     {
30         std::unique_lock<std::mutex> lock(m_taskQueueMutex);
31         std::swap(taskQueue, m_taskQueue);
32     }
33 
34     while (!taskQueue.empty()) {
35         mbgl::Mailbox::maybeReceive(taskQueue.front());
36         taskQueue.pop();
37     }
38 }
39