summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gyp/platform-android.gypi1
-rw-r--r--gyp/platform-ios.gypi1
-rw-r--r--gyp/platform-linux.gypi1
-rw-r--r--gyp/platform-osx.gypi1
-rw-r--r--include/mbgl/platform/platform.hpp3
-rw-r--r--platform/darwin/nsthread.mm13
-rw-r--r--platform/default/sqlite_cache.cpp2
-rw-r--r--platform/default/thread.cpp11
-rw-r--r--src/mbgl/map/map.cpp2
-rw-r--r--src/mbgl/storage/default_file_source.cpp2
-rw-r--r--src/mbgl/util/thread.hpp14
-rw-r--r--src/mbgl/util/worker.cpp3
12 files changed, 48 insertions, 6 deletions
diff --git a/gyp/platform-android.gypi b/gyp/platform-android.gypi
index bfaac7d4f6..7701393bb9 100644
--- a/gyp/platform-android.gypi
+++ b/gyp/platform-android.gypi
@@ -12,6 +12,7 @@
'sources': [
'../platform/android/log_android.cpp',
'../platform/android/asset_root.cpp',
+ '../platform/default/thread.cpp',
'../platform/default/string_stdlib.cpp',
'../platform/default/image.cpp',
'../platform/default/image_reader.cpp',
diff --git a/gyp/platform-ios.gypi b/gyp/platform-ios.gypi
index f1f95d908e..d23192c8c6 100644
--- a/gyp/platform-ios.gypi
+++ b/gyp/platform-ios.gypi
@@ -15,6 +15,7 @@
'../platform/darwin/application_root.mm',
'../platform/darwin/asset_root.mm',
'../platform/darwin/image.mm',
+ '../platform/darwin/nsthread.mm',
'../platform/darwin/reachability.m',
'../include/mbgl/ios/MapboxGL.h',
'../include/mbgl/ios/MGLMapboxEvents.h',
diff --git a/gyp/platform-linux.gypi b/gyp/platform-linux.gypi
index 30715f8289..394433870d 100644
--- a/gyp/platform-linux.gypi
+++ b/gyp/platform-linux.gypi
@@ -14,6 +14,7 @@
'../platform/default/string_stdlib.cpp',
'../platform/default/application_root.cpp',
'../platform/default/asset_root.cpp',
+ '../platform/default/thread.cpp',
'../platform/default/image.cpp',
'../platform/default/image_reader.cpp',
'../platform/default/png_reader.cpp',
diff --git a/gyp/platform-osx.gypi b/gyp/platform-osx.gypi
index 6d6c35b294..ae5194761c 100644
--- a/gyp/platform-osx.gypi
+++ b/gyp/platform-osx.gypi
@@ -15,6 +15,7 @@
'../platform/darwin/application_root.mm',
'../platform/darwin/asset_root.mm',
'../platform/darwin/image.mm',
+ '../platform/darwin/nsthread.mm',
],
'variables': {
diff --git a/include/mbgl/platform/platform.hpp b/include/mbgl/platform/platform.hpp
index cd87e2256d..f828af37f4 100644
--- a/include/mbgl/platform/platform.hpp
+++ b/include/mbgl/platform/platform.hpp
@@ -21,6 +21,9 @@ const std::string &applicationRoot();
// Returns the path to the asset location.
const std::string &assetRoot();
+// Makes the current thread low priority.
+void makeThreadLowPriority();
+
// Shows an alpha image with the specified dimensions in a named window.
void showDebugImage(std::string name, const char *data, size_t width, size_t height);
diff --git a/platform/darwin/nsthread.mm b/platform/darwin/nsthread.mm
new file mode 100644
index 0000000000..9ac1d2caa0
--- /dev/null
+++ b/platform/darwin/nsthread.mm
@@ -0,0 +1,13 @@
+#import <Foundation/Foundation.h>
+
+#include <mbgl/platform/platform.hpp>
+
+namespace mbgl {
+namespace platform {
+
+void makeThreadLowPriority() {
+ [[NSThread currentThread] setThreadPriority:0.0];
+}
+
+}
+}
diff --git a/platform/default/sqlite_cache.cpp b/platform/default/sqlite_cache.cpp
index 83d42d5a5c..fb4cdf74e7 100644
--- a/platform/default/sqlite_cache.cpp
+++ b/platform/default/sqlite_cache.cpp
@@ -62,7 +62,7 @@ std::string unifyMapboxURLs(const std::string &url) {
using namespace mapbox::sqlite;
SQLiteCache::SQLiteCache(const std::string& path_)
- : thread(util::make_unique<util::Thread<Impl>>("SQLite Cache", path_)) {
+ : thread(util::make_unique<util::Thread<Impl>>("SQLite Cache", util::ThreadPriority::Low, path_)) {
}
SQLiteCache::~SQLiteCache() = default;
diff --git a/platform/default/thread.cpp b/platform/default/thread.cpp
new file mode 100644
index 0000000000..c0a1069b9c
--- /dev/null
+++ b/platform/default/thread.cpp
@@ -0,0 +1,11 @@
+#include <mbgl/platform/platform.hpp>
+
+namespace mbgl {
+namespace platform {
+
+void makeThreadLowPriority() {
+ // no-op
+}
+
+}
+}
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index be2355206c..0464ed3f1e 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -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);
}
diff --git a/src/mbgl/storage/default_file_source.cpp b/src/mbgl/storage/default_file_source.cpp
index 1063b22ecc..ddfcc89845 100644
--- a/src/mbgl/storage/default_file_source.cpp
+++ b/src/mbgl/storage/default_file_source.cpp
@@ -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() {
diff --git a/src/mbgl/util/thread.hpp b/src/mbgl/util/thread.hpp
index 55c3d4d281..e97872a502 100644
--- a/src/mbgl/util/thread.hpp
+++ b/src/mbgl/util/thread.hpp
@@ -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);
});
diff --git a/src/mbgl/util/worker.cpp b/src/mbgl/util/worker.cpp
index 1a6eaf4d96..9792f1a099 100644
--- a/src/mbgl/util/worker.cpp
+++ b/src/mbgl/util/worker.cpp
@@ -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));
}
}