[core] option to perform platform specific operations when creating/destroying core threads
This commit is contained in:
committed by
Łukasz Paczos
parent
e79080771b
commit
7d6255c860
13
include/mbgl/platform/thread.hpp
Normal file
13
include/mbgl/platform/thread.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
namespace mbgl {
|
||||
namespace platform {
|
||||
|
||||
// Called when a thread is created
|
||||
void attachThread();
|
||||
|
||||
// Called when a thread is destroyed
|
||||
void detachThread();
|
||||
|
||||
} // namespace platform
|
||||
} // namespace mbgl
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <mbgl/util/platform.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
#include <mbgl/util/util.hpp>
|
||||
#include <mbgl/platform/thread.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <future>
|
||||
@@ -55,6 +56,7 @@ public:
|
||||
] () mutable {
|
||||
platform::setCurrentThreadName(name);
|
||||
platform::makeThreadLowPriority();
|
||||
platform::attachThread();
|
||||
|
||||
util::RunLoop loop_(util::RunLoop::Type::New);
|
||||
loop = &loop_;
|
||||
@@ -67,6 +69,7 @@ public:
|
||||
(void) establishedActor;
|
||||
|
||||
loop = nullptr;
|
||||
platform::detachThread();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <mbgl/util/logging.hpp>
|
||||
#include <mbgl/util/platform.hpp>
|
||||
#include <mbgl/platform/thread.hpp>
|
||||
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/resource.h>
|
||||
@@ -33,5 +34,11 @@ void makeThreadLowPriority() {
|
||||
setpriority(PRIO_PROCESS, 0, 19);
|
||||
}
|
||||
|
||||
void attachThread() {
|
||||
}
|
||||
|
||||
void detachThread() {
|
||||
}
|
||||
|
||||
} // namespace platform
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#include <mbgl/util/platform.hpp>
|
||||
#include <mbgl/platform/thread.hpp>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
@@ -23,5 +24,11 @@ void makeThreadLowPriority() {
|
||||
[[NSThread currentThread] setThreadPriority:0.0];
|
||||
}
|
||||
|
||||
void attachThread() {
|
||||
}
|
||||
|
||||
void detachThread() {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <mbgl/util/platform.hpp>
|
||||
#include <mbgl/platform/thread.hpp>
|
||||
#include <mbgl/util/logging.hpp>
|
||||
|
||||
#include <string>
|
||||
@@ -33,5 +34,11 @@ void makeThreadLowPriority() {
|
||||
}
|
||||
}
|
||||
|
||||
void attachThread() {
|
||||
}
|
||||
|
||||
void detachThread() {
|
||||
}
|
||||
|
||||
} // namespace platform
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <mbgl/util/platform.hpp>
|
||||
#include <mbgl/platform/thread.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -15,5 +16,11 @@ void setCurrentThreadName(const std::string&) {
|
||||
void makeThreadLowPriority() {
|
||||
}
|
||||
|
||||
void attachThread() {
|
||||
}
|
||||
|
||||
void detachThread() {
|
||||
}
|
||||
|
||||
} // namespace platform
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -351,6 +351,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",
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user