summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mbgl/util/thread.hpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/include/mbgl/util/thread.hpp b/include/mbgl/util/thread.hpp
index 8230d8778f..b5f79aa28d 100644
--- a/include/mbgl/util/thread.hpp
+++ b/include/mbgl/util/thread.hpp
@@ -58,16 +58,27 @@ public:
// up and running.
std::shared_ptr<Mailbox> mailbox_ = std::make_shared<Mailbox>(noopScheduler);
mailbox = mailbox_;
-
- thread = std::thread([&, sharedMailbox = std::move(mailbox_), runningPromise = std::move(running_)] {
+
+ auto tuple = std::make_tuple(std::forward<Args>(args)...);
+
+ thread = std::thread([
+ this,
+ name,
+ tuple,
+ sharedMailbox = std::move(mailbox_),
+ runningPromise = std::move(running_)
+ ] {
platform::setCurrentThreadName(name);
platform::makeThreadLowPriority();
util::RunLoop loop_(util::RunLoop::Type::New);
loop = &loop_;
- Actor<Object>* actor = new (&actorStorage) Actor<Object>(std::move(sharedMailbox), std::forward<Args>(args)...);
-
+ Actor<Object>* actor = emplaceActor(
+ std::move(sharedMailbox),
+ std::move(tuple),
+ std::make_index_sequence<std::tuple_size<decltype(tuple)>::value>{});
+
// Replace the NoopScheduler on the mailbox with the RunLoop to
// begin actually processing messages.
actor->mailbox->setScheduler(this);
@@ -161,6 +172,11 @@ private:
assert(loop);
loop->schedule(mailbox_);
}
+
+ template <typename ArgsTuple, std::size_t... I>
+ Actor<Object>* emplaceActor(std::shared_ptr<Mailbox> sharedMailbox, ArgsTuple args, std::index_sequence<I...>) {
+ return new (&actorStorage) Actor<Object>(std::move(sharedMailbox), std::move(std::get<I>(std::forward<ArgsTuple>(args)))...);
+ }
NoopScheduler noopScheduler;
std::weak_ptr<Mailbox> mailbox;