lower thread priority of worker threads
This commit is contained in:
@@ -11,7 +11,7 @@ namespace mbgl {
|
||||
|
||||
Map::Map(View& view, FileSource& fileSource, MapMode mode, bool startPaused)
|
||||
: data(util::make_unique<MapData>(view, mode)),
|
||||
context(util::make_unique<util::Thread<MapContext>>("Map", view, fileSource, *data, startPaused))
|
||||
context(util::make_unique<util::Thread<MapContext>>("Map", util::ThreadPriority::Regular, view, fileSource, *data, startPaused))
|
||||
{
|
||||
view.initialize(this);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace algo = boost::algorithm;
|
||||
namespace mbgl {
|
||||
|
||||
DefaultFileSource::DefaultFileSource(FileCache* cache, const std::string& root)
|
||||
: thread(util::make_unique<util::Thread<Impl>>("FileSource", cache, root)) {
|
||||
: thread(util::make_unique<util::Thread<Impl>>("FileSource", util::ThreadPriority::Low, cache, root)) {
|
||||
}
|
||||
|
||||
DefaultFileSource::~DefaultFileSource() {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <functional>
|
||||
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
#include <mbgl/platform/platform.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -34,11 +35,16 @@ namespace util {
|
||||
// Thread<> constructor blocks until the thread and the Object are fully created, so after the
|
||||
// object creation, it's safe to obtain the Object stored in this thread.
|
||||
|
||||
enum class ThreadPriority : bool {
|
||||
Regular,
|
||||
Low,
|
||||
};
|
||||
|
||||
template <class Object>
|
||||
class Thread {
|
||||
public:
|
||||
template <class... Args>
|
||||
Thread(const std::string& name, Args&&... args);
|
||||
Thread(const std::string& name, ThreadPriority priority, Args&&... args);
|
||||
~Thread();
|
||||
|
||||
// Invoke object->fn(args...) in the runloop thread.
|
||||
@@ -97,7 +103,7 @@ private:
|
||||
|
||||
template <class Object>
|
||||
template <class... Args>
|
||||
Thread<Object>::Thread(const std::string& name, Args&&... args) {
|
||||
Thread<Object>::Thread(const std::string& name, ThreadPriority priority, Args&&... args) {
|
||||
// Note: We're using std::tuple<> to store the arguments because GCC 4.9 has a bug
|
||||
// when expanding parameters packs captured in lambdas.
|
||||
std::tuple<Args...> params = std::forward_as_tuple(::std::forward<Args>(args)...);
|
||||
@@ -109,6 +115,10 @@ Thread<Object>::Thread(const std::string& name, Args&&... args) {
|
||||
(void(name));
|
||||
#endif
|
||||
|
||||
if (priority == ThreadPriority::Low) {
|
||||
platform::makeThreadLowPriority();
|
||||
}
|
||||
|
||||
constexpr auto seq = typename integer_sequence<sizeof...(Args)>::type();
|
||||
run(std::move(params), seq);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <mbgl/util/worker.hpp>
|
||||
#include <mbgl/platform/platform.hpp>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
@@ -15,7 +16,7 @@ public:
|
||||
|
||||
Worker::Worker(std::size_t count) {
|
||||
for (std::size_t i = 0; i < count; i++) {
|
||||
threads.emplace_back(util::make_unique<util::Thread<Impl>>("Worker"));
|
||||
threads.emplace_back(util::make_unique<util::Thread<Impl>>("Worker", util::ThreadPriority::Low));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user