-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Pass thread pool impl to Map constructor #6687
Conversation
@mikemorris, thanks for your PR! By analyzing the history of the files in this pull request, we identified @jfirebaugh, @brunoabinader and @kkaefer to be potential reviewers. |
There's no requirement that |
Thanks @jfirebaugh, got that cleaned up and implemented |
It appears that in some (but not all) instances, @jfirebaugh do you think implementing this Node.js thread pool will require a custom |
So |
@jfirebaugh Got this ALMOST working, but tests are hanging on |
Try |
namespace node_mbgl { | ||
|
||
NodeThreadPool::NodeThreadPool() | ||
: queue(new util::AsyncQueue<std::weak_ptr<mbgl::Mailbox>>(uv_default_loop(), [this](std::weak_ptr<mbgl::Mailbox> mailbox) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This leaks the queue. NodeThreadPool::queue
should be a value, not a pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, needed to fix this in mapbox-gl-native/platform/node/src/node_log.cpp
too.
I'm not quite sure what the issue I'm hitting now is, but it may be related to an implicit instantiation or something? Only thinking that because I had to move
from
|
@jfirebaugh Pushed up 755623baa863f12ed3f967fef0daae0d4b279558 which should likely be reverted, but "fixes" the issue I described in #6687 (comment) and |
Ugh, |
88f0eee
to
76de29c
Compare
Not seeing ^ anymore, hitting #6705 instead. |
e700f69
to
9fa3c04
Compare
CI tests are all green now - what needs to happen before we can merge this @jfirebaugh? The public API of the Node.js bindings (and other platforms) didn't change, but is the ABI break with the change to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting close!
@@ -37,7 +38,8 @@ class QueryBenchmark { | |||
std::shared_ptr<HeadlessDisplay> display{ std::make_shared<HeadlessDisplay>() }; | |||
HeadlessView view{ display, 1 }; | |||
DefaultFileSource fileSource{ "benchmark/fixtures/api/cache.db", "." }; | |||
Map map{ view, fileSource, MapMode::Still }; | |||
ThreadPool workerThreadPool{ 4 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename workerThreadPool
⇢ threadPool
in each of the places in this PR that are gaining a ThreadPool
member. The fact that it's used for "workers" is an implementation detail.
@@ -397,7 +398,8 @@ - (void)commonInit | |||
|
|||
// setup mbgl map | |||
mbgl::DefaultFileSource *mbglFileSource = [MGLOfflineStorage sharedOfflineStorage].mbglFileSource; | |||
_mbglMap = new mbgl::Map(*_mbglView, *mbglFileSource, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default); | |||
mbgl::ThreadPool workerThreadPool(4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not live long enough. It's on the stack here, but it needs to outlive _mbglMap
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed this - is the stack allocation okay in bin/render.cpp
, bin/glfw.cpp
and the tests?
@@ -261,7 +262,8 @@ - (void)commonInit { | |||
[[NSFileManager defaultManager] removeItemAtURL:legacyCacheURL error:NULL]; | |||
|
|||
mbgl::DefaultFileSource *mbglFileSource = [MGLOfflineStorage sharedOfflineStorage].mbglFileSource; | |||
_mbglMap = new mbgl::Map(*_mbglView, *mbglFileSource, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default); | |||
mbgl::ThreadPool workerThreadPool(4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
private: | ||
util::AsyncQueue<std::weak_ptr<mbgl::Mailbox>>* queue; | ||
|
||
class NodeThread : public Nan::AsyncWorker { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename NodeThread
⇢ Worker
. It's not a thread.
@@ -51,6 +51,7 @@ class Map::Impl : public style::Observer { | |||
|
|||
View& view; | |||
FileSource& fileSource; | |||
Scheduler& workerThreadPool; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename workerThreadPool
⇢ scheduler
.
So long as all the SDKs are updated in this PR, which they are, we're good. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In those cases, the Map
and ThreadPool
are in the same stack frame, so it's ok.
Updates mbgl::Map constructor usage everywhere Adds NodeThreadPool implementation using AsyncQueue to call Nan::AsyncQueueWorker from main thread
Fixes #3982
Put together an initial draft of subclassing
Scheduler
to supply a custom thread pool implementation toMap
. Currently, only theNodeMap
implementation has been updated to pass in a thread pool based onNanAsyncWorker
- all other platforms will need to be updated to pass in the default thread pool implementation.I think the
NodeThread
->NodeThreadPool
reference is quite unsafe currently. Should I be using astd::weak_ptr
or something here?I'm hitting a segfault when running
npm test
, backtrace follows:/cc @jfirebaugh @miccolis