From bef635765a1bbec14d7732856c38c037ea8add6a Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Fri, 4 Oct 2019 12:30:41 +0300 Subject: [core] Decouple Scheduler interface from actor model So that it is possible to schedule normal `std::function` and use `mapbox::base::WeakPtr`. --- platform/qt/src/qmapboxgl_scheduler.cpp | 10 +++++----- platform/qt/src/qmapboxgl_scheduler.hpp | 5 ++--- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'platform/qt') diff --git a/platform/qt/src/qmapboxgl_scheduler.cpp b/platform/qt/src/qmapboxgl_scheduler.cpp index e2d39703ee..5fc3ab13de 100644 --- a/platform/qt/src/qmapboxgl_scheduler.cpp +++ b/platform/qt/src/qmapboxgl_scheduler.cpp @@ -13,10 +13,9 @@ QMapboxGLScheduler::~QMapboxGLScheduler() MBGL_VERIFY_THREAD(tid); } -void QMapboxGLScheduler::schedule(std::weak_ptr mailbox) -{ +void QMapboxGLScheduler::schedule(std::function function) { std::lock_guard lock(m_taskQueueMutex); - m_taskQueue.push(mailbox); + m_taskQueue.push(std::move(function)); // Need to force the main thread to wake // up this thread and process the events. @@ -25,14 +24,15 @@ void QMapboxGLScheduler::schedule(std::weak_ptr mailbox) void QMapboxGLScheduler::processEvents() { - std::queue> taskQueue; + std::queue> taskQueue; { std::unique_lock lock(m_taskQueueMutex); std::swap(taskQueue, m_taskQueue); } while (!taskQueue.empty()) { - mbgl::Mailbox::maybeReceive(taskQueue.front()); + auto& function = taskQueue.front(); + if (function) function(); taskQueue.pop(); } } diff --git a/platform/qt/src/qmapboxgl_scheduler.hpp b/platform/qt/src/qmapboxgl_scheduler.hpp index 68636d0d11..b34dd3d5b8 100644 --- a/platform/qt/src/qmapboxgl_scheduler.hpp +++ b/platform/qt/src/qmapboxgl_scheduler.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include @@ -19,7 +18,7 @@ public: virtual ~QMapboxGLScheduler(); // mbgl::Scheduler implementation. - void schedule(std::weak_ptr scheduled) final; + void schedule(std::function scheduled) final; void processEvents(); @@ -30,5 +29,5 @@ private: MBGL_STORE_THREAD(tid); std::mutex m_taskQueueMutex; - std::queue> m_taskQueue; + std::queue> m_taskQueue; }; -- cgit v1.2.1