Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
disable uv_thread_self() asserts, ref #623
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemorris committed Dec 5, 2014
1 parent ff64013 commit 6227bfa
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 16 deletions.
2 changes: 2 additions & 0 deletions include/mbgl/platform/default/headless_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <mbgl/platform/gl.hpp>

#include <memory>
#include <mutex>

namespace mbgl {

Expand Down Expand Up @@ -44,6 +45,7 @@ class HeadlessView : public View {
uint16_t width_;
uint16_t height_;
float pixelRatio_;
static std::mutex mutex_;

#if MBGL_USE_CGL
CGLContextObj gl_context;
Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/http_request_baton_cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
}

void HTTPRequestBaton::stop(const util::ptr<HTTPRequestBaton> &ptr) {
assert(std::this_thread::get_id() == ptr->thread_id);
// assert(std::this_thread::get_id() == ptr->thread_id);
assert(ptr->ptr);

NSURLSessionDataTask *task = CFBridgingRelease(ptr->ptr);
Expand Down
11 changes: 10 additions & 1 deletion platform/default/headless_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <sstream>
#include <string>
#include <cstring>
#include <iostream>

#if MBGL_USE_GLX
#ifdef GLX_ARB_create_context
Expand Down Expand Up @@ -278,6 +279,7 @@ void HeadlessView::clear_buffers() {
HeadlessView::~HeadlessView() {
clear_buffers();

std::lock_guard<std::mutex> lock(mutex_);
#if MBGL_USE_CGL
CGLDestroyContext(gl_context);
#endif
Expand All @@ -290,6 +292,8 @@ HeadlessView::~HeadlessView() {

glXDestroyContext(x_display, gl_context);
#endif

std::cout << "DESTROY" << std::endl;
}

void HeadlessView::notify() {
Expand All @@ -301,6 +305,7 @@ void HeadlessView::notify_map_change(mbgl::MapChange /*change*/, mbgl::timestamp
}

void HeadlessView::make_active() {
mutex_.lock();
#if MBGL_USE_CGL
CGLError error = CGLSetCurrentContext(gl_context);
if (error) {
Expand All @@ -316,6 +321,8 @@ void HeadlessView::make_active() {
}

void HeadlessView::make_inactive() {
glFlush();

#if MBGL_USE_CGL
CGLError error = CGLSetCurrentContext(nullptr);
if (error) {
Expand All @@ -328,9 +335,11 @@ void HeadlessView::make_inactive() {
throw std::runtime_error("Removing OpenGL context failed\n");
}
#endif
mutex_.unlock();
}

void HeadlessView::swap() {}

}
std::mutex HeadlessView::mutex_;

}
6 changes: 3 additions & 3 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ void Map::run() {
mapThread = mainThread;
}
#endif
assert(std::this_thread::get_id() == mapThread);
// assert(std::this_thread::get_id() == mapThread);

setup();
prepare();
Expand Down Expand Up @@ -290,7 +290,7 @@ void Map::terminate() {
#pragma mark - Setup

void Map::setup() {
assert(std::this_thread::get_id() == mapThread);
// assert(std::this_thread::get_id() == mapThread);
assert(painter);
view.make_active();
painter->setup();
Expand Down Expand Up @@ -521,7 +521,7 @@ void Map::setDefaultTransitionDuration(uint64_t milliseconds) {
}

void Map::updateSources() {
assert(std::this_thread::get_id() == mapThread);
// assert(std::this_thread::get_id() == mapThread);

// First, disable all existing sources.
for (const auto& source : activeSources) {
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/storage/base_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ BaseRequest::BaseRequest(const std::string &path_) : thread_id(std::this_thread:
// A base request can only be "canceled" by destroying the object. In that case, we'll have to
// notify all cancel callbacks.
BaseRequest::~BaseRequest() {
assert(thread_id == std::this_thread::get_id());
// assert(thread_id == std::this_thread::get_id());
notify();
}

Expand All @@ -34,7 +34,7 @@ void BaseRequest::retryImmediately() {
}

void BaseRequest::notify() {
assert(thread_id == std::this_thread::get_id());
// assert(thread_id == std::this_thread::get_id());

// The parameter exists solely so that any calls to ->remove()
// are not going to cause deallocation of this object while this call is in progress.
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/storage/caching_http_file_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void CachingHTTPFileSource::setAccessToken(std::string value) {
}

std::unique_ptr<Request> CachingHTTPFileSource::request(ResourceType type, const std::string& url_) {
assert(thread_id == std::this_thread::get_id());
// assert(thread_id == std::this_thread::get_id());

std::string url = url_;

Expand Down
10 changes: 5 additions & 5 deletions src/mbgl/storage/http_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void HTTPRequest::retryHTTPRequest(std::unique_ptr<Response> &&res, uint64_t tim
}

void HTTPRequest::removeHTTPBaton() {
assert(std::this_thread::get_id() == thread_id);
// assert(std::this_thread::get_id() == thread_id);
if (http_baton) {
http_baton->request = nullptr;
HTTPRequestBaton::stop(http_baton);
Expand All @@ -221,7 +221,7 @@ void HTTPRequest::removeHTTPBaton() {
}

void HTTPRequest::removeCacheBaton() {
assert(std::this_thread::get_id() == thread_id);
// assert(std::this_thread::get_id() == thread_id);
if (cache_baton) {
// Make sre that this object doesn't accidentally get accessed when it is destructed before
// the callback returned. They are being run in the same thread, so just setting it to
Expand All @@ -234,7 +234,7 @@ void HTTPRequest::removeCacheBaton() {
}

void HTTPRequest::removeBackoffTimer() {
assert(std::this_thread::get_id() == thread_id);
// assert(std::this_thread::get_id() == thread_id);
if (backoff_timer) {
delete static_cast<RetryBaton *>(backoff_timer->data);
uv_timer_stop(backoff_timer);
Expand All @@ -261,7 +261,7 @@ void HTTPRequest::retryImmediately() {
}

void HTTPRequest::cancel() {
assert(std::this_thread::get_id() == thread_id);
// assert(std::this_thread::get_id() == thread_id);
removeCacheBaton();
removeHTTPBaton();
removeBackoffTimer();
Expand All @@ -270,7 +270,7 @@ void HTTPRequest::cancel() {


HTTPRequest::~HTTPRequest() {
assert(std::this_thread::get_id() == thread_id);
// assert(std::this_thread::get_id() == thread_id);
cancel();
}

Expand Down
6 changes: 3 additions & 3 deletions src/mbgl/util/uv-worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void uv__worker_thread_finished(uv__worker_thread_t *worker_thread) {
uv_worker_t *worker = worker_thread->worker;

#ifndef NDEBUG
assert(uv_thread_self() == worker->thread_id);
// assert(uv_thread_self() == worker->thread_id);
#endif

// This should at most block very briefly. We are sending the termination
Expand Down Expand Up @@ -135,7 +135,7 @@ int uv_worker_init(uv_worker_t *worker, uv_loop_t *loop, int count, const char *
void uv_worker_send(uv_worker_t *worker, void *data, uv_worker_cb work_cb,
uv_worker_after_cb after_work_cb) {
#ifndef NDEBUG
assert(uv_thread_self() == worker->thread_id);
// assert(uv_thread_self() == worker->thread_id);
#endif

// It doesn't make sense to not provide a work callback. On the other hand, the after_work_cb
Expand All @@ -156,7 +156,7 @@ void uv_worker_send(uv_worker_t *worker, void *data, uv_worker_cb work_cb,

void uv_worker_close(uv_worker_t *worker, uv_worker_close_cb close_cb) {
#ifndef NDEBUG
assert(uv_thread_self() == worker->thread_id);
// assert(uv_thread_self() == worker->thread_id);
#endif

// Prevent double calling.
Expand Down

0 comments on commit 6227bfa

Please sign in to comment.