[core] Clean up ThreadContext vestiges
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace mbgl {
|
||||
|
||||
class PlainShader;
|
||||
|
||||
namespace util {
|
||||
namespace gl {
|
||||
class GLObjectStore;
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -341,7 +341,6 @@ void Style::onLowMemory() {
|
||||
}
|
||||
|
||||
void Style::setObserver(Observer* observer_) {
|
||||
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
|
||||
observer = observer_;
|
||||
}
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user