From 7bacf5696ca90dd3f3496988ad0658b357cb7ec1 Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Mon, 2 Dec 2019 10:40:59 +0200 Subject: [core] Introduce Pass<> class and use it for Scheduler Thus we enforce client to retain the returned `Scheduler` objects. --- include/mbgl/actor/scheduler.hpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'include') 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 +class Pass { +public: + Pass(T&& obj_) : obj(std::forward(obj_)) {} + Pass(Pass&&) = default; + Pass(const Pass&) = delete; + operator T() && { return std::move(obj); } + +private: + T obj; +}; + +template +using PassRefPtr = Pass>; + /* 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 GetBackground(); + static PassRefPtr 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 GetSequenced(); + static PassRefPtr GetSequenced(); protected: template -- cgit v1.2.1