diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2019-05-21 12:45:01 +0200 |
---|---|---|
committer | Łukasz Paczos <lukas.paczos@gmail.com> | 2019-05-21 14:26:42 +0200 |
commit | 03a2ff595bd466186e79d8e9274cf2d7362c7ae8 (patch) | |
tree | 032acd7090725b3573eed7ad6a9b084d45d3da2f | |
parent | f210bbbb6c9532c5bdcf176e191bef9a0a9858c7 (diff) | |
download | qtlocation-mapboxgl-03a2ff595bd466186e79d8e9274cf2d7362c7ae8.tar.gz |
[core] option to perform platform specific operations when creating/destroying thread pool's threads
-rw-r--r-- | include/mbgl/platform/thread.hpp | 21 | ||||
-rw-r--r-- | src/core-files.json | 1 | ||||
-rw-r--r-- | src/mbgl/util/thread_pool.cpp | 3 |
3 files changed, 25 insertions, 0 deletions
diff --git a/include/mbgl/platform/thread.hpp b/include/mbgl/platform/thread.hpp new file mode 100644 index 0000000000..d00abc64ef --- /dev/null +++ b/include/mbgl/platform/thread.hpp @@ -0,0 +1,21 @@ +#pragma once + +namespace mbgl { +namespace platform { + +// Called when a thread is created +#if defined(__ANDROID__) +void attachThread(); +#else +void attachThread() {} +#endif + +// Called when a thread is destroyed +#if defined(__ANDROID__) +void detachThread(); +#else +void detachThread() {} +#endif + +} // namespace platform +} // namespace mbgl diff --git a/src/core-files.json b/src/core-files.json index cf87e410f9..6b1d142511 100644 --- a/src/core-files.json +++ b/src/core-files.json @@ -352,6 +352,7 @@ "mbgl/math/minmax.hpp": "include/mbgl/math/minmax.hpp", "mbgl/math/wrap.hpp": "include/mbgl/math/wrap.hpp", "mbgl/platform/gl_functions.hpp": "include/mbgl/platform/gl_functions.hpp", + "mbgl/platform/thread.hpp": "include/mbgl/platform/thread.hpp", "mbgl/renderer/query.hpp": "include/mbgl/renderer/query.hpp", "mbgl/renderer/renderer.hpp": "include/mbgl/renderer/renderer.hpp", "mbgl/renderer/renderer_frontend.hpp": "include/mbgl/renderer/renderer_frontend.hpp", diff --git a/src/mbgl/util/thread_pool.cpp b/src/mbgl/util/thread_pool.cpp index 79c2f75012..e839d1b4be 100644 --- a/src/mbgl/util/thread_pool.cpp +++ b/src/mbgl/util/thread_pool.cpp @@ -2,6 +2,7 @@ #include <mbgl/util/platform.hpp> #include <mbgl/util/string.hpp> +#include <mbgl/platform/thread.hpp> namespace mbgl { @@ -11,6 +12,7 @@ ThreadPool::ThreadPool(std::size_t count) { for (std::size_t i = 0; i < count; ++i) { threads.emplace_back([this, i]() { platform::setCurrentThreadName(std::string{ "Worker " } + util::toString(i + 1)); + platform::attachThread(); while (true) { std::unique_lock<std::mutex> lock(mutex); @@ -20,6 +22,7 @@ ThreadPool::ThreadPool(std::size_t count) { }); if (terminate) { + platform::detachThread(); return; } |