summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-10-09 16:23:12 +0300
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-10-09 23:46:11 +0300
commitf62e5b00c98b50e9d9a1e76f4ae5e70129e83ff4 (patch)
treed5c639664127f009ff3d720be518f6bd157d7e4b /include
parentda490c2b90125bf82fc84b1782a795e48ab5a548 (diff)
downloadqtlocation-mapboxgl-f62e5b00c98b50e9d9a1e76f4ae5e70129e83ff4.tar.gz
[core] Introduce Scheduler::makeWeakPtr()
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/actor/scheduler.hpp4
-rw-r--r--include/mbgl/util/run_loop.hpp2
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