diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2019-05-24 12:03:25 +0200 |
---|---|---|
committer | Łukasz Paczos <lukasz.paczos@mapbox.com> | 2019-05-24 13:52:50 +0200 |
commit | 5e00a2a764efcab85db63f20d1d97a87f79a6ece (patch) | |
tree | 9f6c907ecc3b96b931e13525b440bb76c5fc82c2 | |
parent | bc74a8ee0b409f3c7ab9882b74519b4564ab119b (diff) | |
download | qtlocation-mapboxgl-5e00a2a764efcab85db63f20d1d97a87f79a6ece.tar.gz |
[core] limit thread's scope to release the Object before detaching the thread
-rw-r--r-- | include/mbgl/util/thread.hpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/include/mbgl/util/thread.hpp b/include/mbgl/util/thread.hpp index 0e9bd8f759..ab0403e44e 100644 --- a/include/mbgl/util/thread.hpp +++ b/include/mbgl/util/thread.hpp @@ -58,17 +58,21 @@ public: platform::makeThreadLowPriority(); platform::attachThread(); - util::RunLoop loop_(util::RunLoop::Type::New); - loop = &loop_; - EstablishedActor<Object> establishedActor(loop_, object, std::move(capturedArgs)); - - runningPromise.set_value(); - - loop->run(); - - (void) establishedActor; - - loop = nullptr; + // narrowing the scope to release the Object before we detach the thread + { + util::RunLoop loop_(util::RunLoop::Type::New); + loop = &loop_; + EstablishedActor<Object> establishedActor(loop_, object, std::move(capturedArgs)); + + runningPromise.set_value(); + + loop->run(); + + (void) establishedActor; + + loop = nullptr; + } + platform::detachThread(); }); } |