summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-02-16 13:48:33 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-04-15 09:56:18 -0700
commit6e78eabfff75579286ab23cbde8a36fba061ca1d (patch)
tree2437392712213f97c0326cce8691a6944fb72734 /src
parent253a007d99c2079b95d5c6d11715e16815067e16 (diff)
downloadqtlocation-mapboxgl-6e78eabfff75579286ab23cbde8a36fba061ca1d.tar.gz
[core] Clean up ThreadContext vestiges
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/geometry/buffer.hpp1
-rw-r--r--src/mbgl/geometry/glyph_atlas.cpp2
-rw-r--r--src/mbgl/geometry/line_atlas.cpp6
-rw-r--r--src/mbgl/map/map_context.cpp11
-rw-r--r--src/mbgl/platform/log.cpp10
-rw-r--r--src/mbgl/renderer/debug_bucket.hpp2
-rw-r--r--src/mbgl/sprite/sprite_atlas.cpp1
-rw-r--r--src/mbgl/style/style.cpp1
-rw-r--r--src/mbgl/text/glyph_store.cpp4
-rw-r--r--src/mbgl/util/thread.hpp10
-rw-r--r--src/mbgl/util/thread_context.cpp57
-rw-r--r--src/mbgl/util/thread_context.hpp18
-rw-r--r--src/mbgl/util/worker.cpp2
13 files changed, 14 insertions, 111 deletions
diff --git a/src/mbgl/geometry/buffer.hpp b/src/mbgl/geometry/buffer.hpp
index 143597ed0a..e205113267 100644
--- a/src/mbgl/geometry/buffer.hpp
+++ b/src/mbgl/geometry/buffer.hpp
@@ -5,7 +5,6 @@
#include <mbgl/gl/gl_object_store.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/util/noncopyable.hpp>
-#include <mbgl/util/thread_context.hpp>
#include <memory>
#include <cstdlib>
diff --git a/src/mbgl/geometry/glyph_atlas.cpp b/src/mbgl/geometry/glyph_atlas.cpp
index 24c1b8c8db..046ba46520 100644
--- a/src/mbgl/geometry/glyph_atlas.cpp
+++ b/src/mbgl/geometry/glyph_atlas.cpp
@@ -6,7 +6,6 @@
#include <mbgl/gl/gl_object_store.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/platform/platform.hpp>
-#include <mbgl/util/thread_context.hpp>
#include <cassert>
#include <algorithm>
@@ -23,7 +22,6 @@ GlyphAtlas::GlyphAtlas(uint16_t width_, uint16_t height_)
}
GlyphAtlas::~GlyphAtlas() {
- assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
}
void GlyphAtlas::addGlyphs(uintptr_t tileUID,
diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp
index 9b133319dc..1213b8d778 100644
--- a/src/mbgl/geometry/line_atlas.cpp
+++ b/src/mbgl/geometry/line_atlas.cpp
@@ -3,7 +3,6 @@
#include <mbgl/gl/gl_object_store.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/platform/platform.hpp>
-#include <mbgl/util/thread_context.hpp>
#include <boost/functional/hash.hpp>
@@ -20,12 +19,9 @@ LineAtlas::LineAtlas(GLsizei w, GLsizei h)
}
LineAtlas::~LineAtlas() {
- assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
}
LinePatternPos LineAtlas::getDashPosition(const std::vector<float> &dasharray, bool round, gl::GLObjectStore& glObjectStore) {
- assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
-
size_t key = round ? std::numeric_limits<size_t>::min() : std::numeric_limits<size_t>::max();
for (const float part : dasharray) {
boost::hash_combine<float>(key, part);
@@ -132,8 +128,6 @@ void LineAtlas::upload(gl::GLObjectStore& glObjectStore) {
}
void LineAtlas::bind(gl::GLObjectStore& glObjectStore) {
- assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
-
bool first = false;
if (!texture) {
texture.create(glObjectStore);
diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp
index 2ff93d2338..5b6cd2af74 100644
--- a/src/mbgl/map/map_context.cpp
+++ b/src/mbgl/map/map_context.cpp
@@ -117,8 +117,6 @@ void MapContext::setStyleJSON(const std::string& json, const std::string& base)
}
void MapContext::loadStyleJSON(const std::string& json, const std::string& base) {
- assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
-
style->setJSON(json, base);
style->setObserver(this);
styleJSON = json;
@@ -130,8 +128,6 @@ void MapContext::loadStyleJSON(const std::string& json, const std::string& base)
}
void MapContext::update() {
- assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
-
if (!style) {
updateFlags = Update::Nothing;
}
@@ -205,8 +201,6 @@ void MapContext::renderStill(const TransformState& state, const FrameData& frame
}
bool MapContext::renderSync(const TransformState& state, const FrameData& frame) {
- assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
-
// Style was not loaded yet.
if (!style) {
return false;
@@ -240,17 +234,14 @@ bool MapContext::isLoaded() const {
}
void MapContext::addAnnotationIcon(const std::string& name, std::shared_ptr<const SpriteImage> sprite) {
- assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
data.getAnnotationManager()->addIcon(name, sprite);
}
void MapContext::removeAnnotationIcon(const std::string& name) {
- assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
data.getAnnotationManager()->removeIcon(name);
}
double MapContext::getTopOffsetPixelsForAnnotationIcon(const std::string& name) {
- assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
return data.getAnnotationManager()->getTopOffsetPixelsForIcon(name);
}
@@ -286,7 +277,6 @@ void MapContext::setClasses(const std::vector<std::string>& classNames, const Pr
}
void MapContext::setSourceTileCacheSize(size_t size) {
- assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
if (size != sourceCacheSize) {
sourceCacheSize = size;
if (!style) return;
@@ -296,7 +286,6 @@ void MapContext::setSourceTileCacheSize(size_t size) {
}
void MapContext::onLowMemory() {
- assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
if (!style) return;
style->onLowMemory();
view.invalidate();
diff --git a/src/mbgl/platform/log.cpp b/src/mbgl/platform/log.cpp
index 580c698699..2118511592 100644
--- a/src/mbgl/platform/log.cpp
+++ b/src/mbgl/platform/log.cpp
@@ -1,7 +1,5 @@
#include <mbgl/platform/log.hpp>
-#include <mbgl/util/thread_context.hpp>
-
#include <cstdio>
#include <cstdarg>
#include <sstream>
@@ -49,7 +47,13 @@ void Log::record(EventSeverity severity, Event event, int64_t code, const std::s
}
std::stringstream logStream;
- logStream << "{" << util::ThreadContext::getName() << "}";
+
+ #if !defined(__ANDROID__) && (defined( __APPLE__) || defined(__linux__))
+ char name[32];
+ pthread_getname_np(pthread_self(), name, sizeof(name));
+ logStream << "{" << name << "}";
+ #endif
+
logStream << "[" << event << "]";
if (code >= 0) {
diff --git a/src/mbgl/renderer/debug_bucket.hpp b/src/mbgl/renderer/debug_bucket.hpp
index f12452751c..2ec7318f9a 100644
--- a/src/mbgl/renderer/debug_bucket.hpp
+++ b/src/mbgl/renderer/debug_bucket.hpp
@@ -11,7 +11,7 @@ namespace mbgl {
class PlainShader;
-namespace util {
+namespace gl {
class GLObjectStore;
}
diff --git a/src/mbgl/sprite/sprite_atlas.cpp b/src/mbgl/sprite/sprite_atlas.cpp
index 12d12a53cb..26777abc82 100644
--- a/src/mbgl/sprite/sprite_atlas.cpp
+++ b/src/mbgl/sprite/sprite_atlas.cpp
@@ -6,7 +6,6 @@
#include <mbgl/util/math.hpp>
#include <mbgl/util/std.hpp>
#include <mbgl/util/constants.hpp>
-#include <mbgl/util/thread_context.hpp>
#include <cassert>
#include <cmath>
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index 926276a304..e2f8e74845 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -341,7 +341,6 @@ void Style::onLowMemory() {
}
void Style::setObserver(Observer* observer_) {
- assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
observer = observer_;
}
diff --git a/src/mbgl/text/glyph_store.cpp b/src/mbgl/text/glyph_store.cpp
index 1c75f7191e..cd960dd8e2 100644
--- a/src/mbgl/text/glyph_store.cpp
+++ b/src/mbgl/text/glyph_store.cpp
@@ -1,7 +1,5 @@
#include <mbgl/text/glyph_store.hpp>
-
#include <mbgl/text/glyph_pbf.hpp>
-#include <mbgl/util/thread_context.hpp>
#include <cassert>
@@ -14,8 +12,6 @@ GlyphStore::GlyphStore(FileSource& fileSource_)
GlyphStore::~GlyphStore() = default;
void GlyphStore::requestGlyphRange(const std::string& fontStackName, const GlyphRange& range) {
- assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
-
std::lock_guard<std::mutex> lock(rangesMutex);
auto& rangeSets = ranges[fontStackName];
diff --git a/src/mbgl/util/thread.hpp b/src/mbgl/util/thread.hpp
index dc388c922c..d54d998ab4 100644
--- a/src/mbgl/util/thread.hpp
+++ b/src/mbgl/util/thread.hpp
@@ -76,7 +76,7 @@ private:
}
template <typename P, std::size_t... I>
- void run(ThreadContext, P&& params, std::index_sequence<I...>);
+ void run(P&& params, std::index_sequence<I...>);
std::promise<void> running;
std::promise<void> joinable;
@@ -107,7 +107,7 @@ Thread<Object>::Thread(const ThreadContext& context, Args&&... args) {
platform::makeThreadLowPriority();
}
- run(context, std::move(params), std::index_sequence_for<Args...>{});
+ run(std::move(params), std::index_sequence_for<Args...>{});
});
running.get_future().get();
@@ -115,9 +115,7 @@ Thread<Object>::Thread(const ThreadContext& context, Args&&... args) {
template <class Object>
template <typename P, std::size_t... I>
-void Thread<Object>::run(ThreadContext context, P&& params, std::index_sequence<I...>) {
- ThreadContext::Set(&context);
-
+void Thread<Object>::run(P&& params, std::index_sequence<I...>) {
RunLoop loop_(RunLoop::Type::New);
loop = &loop_;
@@ -130,8 +128,6 @@ void Thread<Object>::run(ThreadContext context, P&& params, std::index_sequence<
loop = nullptr;
object = nullptr;
- ThreadContext::Set(nullptr);
-
joinable.get_future().get();
}
diff --git a/src/mbgl/util/thread_context.cpp b/src/mbgl/util/thread_context.cpp
index d6ddda2e8e..f728e32df7 100644
--- a/src/mbgl/util/thread_context.cpp
+++ b/src/mbgl/util/thread_context.cpp
@@ -1,67 +1,12 @@
#include <mbgl/util/thread_context.hpp>
-#include <mbgl/util/thread_local.hpp>
-
-#include <cassert>
-
-namespace {
-
-using namespace mbgl::util;
-static ThreadLocal<ThreadContext>& current = *new ThreadLocal<ThreadContext>;
-
-} // namespace
-
namespace mbgl {
namespace util {
-ThreadContext::ThreadContext(const std::string& name_, ThreadType type_, ThreadPriority priority_)
+ThreadContext::ThreadContext(const std::string& name_, ThreadPriority priority_)
: name(name_),
- type(type_),
priority(priority_) {
}
-void ThreadContext::Set(ThreadContext* context) {
- current.set(context);
-}
-
-bool ThreadContext::currentlyOn(ThreadType type) {
- return current.get()->type == type;
-}
-
-std::string ThreadContext::getName() {
- if (current.get() != nullptr) {
- return current.get()->name;
- } else {
- return "Unknown";
- }
-}
-
-ThreadPriority ThreadContext::getPriority() {
- if (current.get() != nullptr) {
- return current.get()->priority;
- } else {
- return ThreadPriority::Regular;
- }
-}
-
-class MainThreadContextRegistrar {
-public:
- MainThreadContextRegistrar() : context("Main", ThreadType::Main, ThreadPriority::Regular) {
- ThreadContext::Set(&context);
- }
-
- ~MainThreadContextRegistrar() {
- ThreadContext::Set(nullptr);
- }
-
-private:
- ThreadContext context;
-};
-
-// Will auto register the main thread context
-// at startup. Must be instantiated after the
-// ThreadContext::current object.
-MainThreadContextRegistrar registrar;
-
} // namespace util
} // namespace mbgl
diff --git a/src/mbgl/util/thread_context.hpp b/src/mbgl/util/thread_context.hpp
index bd591e88a5..9c00ef25cf 100644
--- a/src/mbgl/util/thread_context.hpp
+++ b/src/mbgl/util/thread_context.hpp
@@ -1,9 +1,7 @@
#ifndef MBGL_UTIL_THREAD_CONTEXT
#define MBGL_UTIL_THREAD_CONTEXT
-#include <cstdint>
#include <string>
-#include <thread>
namespace mbgl {
namespace util {
@@ -13,25 +11,11 @@ enum class ThreadPriority : bool {
Low,
};
-enum class ThreadType : uint8_t {
- Main,
- Map = Main,
- Worker,
- Unknown,
-};
-
struct ThreadContext {
public:
- ThreadContext(const std::string& name, ThreadType type, ThreadPriority priority);
-
- static void Set(ThreadContext* context);
-
- static bool currentlyOn(ThreadType type);
- static std::string getName();
- static ThreadPriority getPriority();
+ ThreadContext(const std::string& name, ThreadPriority priority = ThreadPriority::Regular);
std::string name;
- ThreadType type;
ThreadPriority priority;
};
diff --git a/src/mbgl/util/worker.cpp b/src/mbgl/util/worker.cpp
index ec9d02573d..b84b0c43ef 100644
--- a/src/mbgl/util/worker.cpp
+++ b/src/mbgl/util/worker.cpp
@@ -60,7 +60,7 @@ public:
};
Worker::Worker(std::size_t count) {
- util::ThreadContext context = { "Worker", util::ThreadType::Worker, util::ThreadPriority::Low };
+ util::ThreadContext context = { "Worker", util::ThreadPriority::Low };
for (std::size_t i = 0; i < count; i++) {
threads.emplace_back(std::make_unique<util::Thread<Impl>>(context));
}