summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-12-02 10:40:59 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-12-02 14:12:18 +0200
commit7bacf5696ca90dd3f3496988ad0658b357cb7ec1 (patch)
tree55c0988f8ea6a5c2f32c1f9df7d4e3f0bc26481c /include
parente373d8a5924e4f4cf3904ecacbf1d1cf86a5d60f (diff)
downloadqtlocation-mapboxgl-7bacf5696ca90dd3f3496988ad0658b357cb7ec1.tar.gz
[core] Introduce Pass<> class and use it for Scheduler
Thus we enforce client to retain the returned `Scheduler` objects.
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/actor/scheduler.hpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/include/mbgl/actor/scheduler.hpp b/include/mbgl/actor/scheduler.hpp
index 04cbc389e5..d7fec41ea6 100644
--- a/include/mbgl/actor/scheduler.hpp
+++ b/include/mbgl/actor/scheduler.hpp
@@ -9,6 +9,23 @@ namespace mbgl {
class Mailbox;
+// Using this type as a return type enforces the client to retain the returned object.
+// TODO: Move to a separate file if/when other clients for this aux API turn up.
+template <typename T>
+class Pass {
+public:
+ Pass(T&& obj_) : obj(std::forward<T>(obj_)) {}
+ Pass(Pass&&) = default;
+ Pass(const Pass&) = delete;
+ operator T() && { return std::move(obj); }
+
+private:
+ T obj;
+};
+
+template <typename T>
+using PassRefPtr = Pass<std::shared_ptr<T>>;
+
/*
A `Scheduler` is responsible for coordinating the processing of messages by
one or more actors via their mailboxes. It's an abstract interface. Currently,
@@ -72,7 +89,7 @@ public:
// The scheduled tasks might run in parallel on different
// threads.
// TODO : Rename to GetPool()
- static std::shared_ptr<Scheduler> GetBackground();
+ static PassRefPtr<Scheduler> GetBackground();
// Get the *sequenced* scheduler for asynchronous tasks.
// Unlike the method above, the returned scheduler
@@ -82,7 +99,7 @@ public:
//
// Sequenced scheduler can be used for running tasks
// on the same thread-unsafe object.
- static std::shared_ptr<Scheduler> GetSequenced();
+ static PassRefPtr<Scheduler> GetSequenced();
protected:
template <typename TaskFn, typename ReplyFn>