diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-10-09 16:23:12 +0300 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-10-09 23:46:11 +0300 |
commit | f62e5b00c98b50e9d9a1e76f4ae5e70129e83ff4 (patch) | |
tree | d5c639664127f009ff3d720be518f6bd157d7e4b /include | |
parent | da490c2b90125bf82fc84b1782a795e48ab5a548 (diff) | |
download | qtlocation-mapboxgl-f62e5b00c98b50e9d9a1e76f4ae5e70129e83ff4.tar.gz |
[core] Introduce Scheduler::makeWeakPtr()
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/actor/scheduler.hpp | 4 | ||||
-rw-r--r-- | include/mbgl/util/run_loop.hpp | 2 |
2 files changed, 6 insertions, 0 deletions
diff --git a/include/mbgl/actor/scheduler.hpp b/include/mbgl/actor/scheduler.hpp index ca34901cfd..7338c3ab3a 100644 --- a/include/mbgl/actor/scheduler.hpp +++ b/include/mbgl/actor/scheduler.hpp @@ -1,5 +1,7 @@ #pragma once +#include <mapbox/weak.hpp> + #include <functional> #include <memory> @@ -35,6 +37,8 @@ public: // Enqueues a function for execution. virtual void schedule(std::function<void()>) = 0; + // Makes a weak pointer to this Scheduler. + virtual mapbox::base::WeakPtr<Scheduler> makeWeakPtr() = 0; // Set/Get the current Scheduler for this thread static Scheduler* GetCurrent(); diff --git a/include/mbgl/util/run_loop.hpp b/include/mbgl/util/run_loop.hpp index 961573fd87..5cde95a531 100644 --- a/include/mbgl/util/run_loop.hpp +++ b/include/mbgl/util/run_loop.hpp @@ -74,6 +74,7 @@ public: } void schedule(std::function<void()> fn) override { invoke(std::move(fn)); } + ::mapbox::base::WeakPtr<Scheduler> makeWeakPtr() override { return weakFactory.makeWeakPtr(); } class Impl; @@ -121,6 +122,7 @@ private: std::mutex mutex; std::unique_ptr<Impl> impl; + ::mapbox::base::WeakPtrFactory<Scheduler> weakFactory{this}; }; } // namespace util |