add a callback to stop() to allow running the current thread's event loop

This commit is contained in:
Konstantin Käfer
2014-09-17 15:29:24 +02:00
parent 89cd310cf6
commit ba18c08524
5 changed files with 26 additions and 3 deletions

View File

@@ -75,6 +75,9 @@ void Map::start() {
// updated rendering. Only in these cases, we attach the async handlers.
async = true;
// Reset the flag.
is_stopped = false;
// Setup async notifications
uv_async_init(**loop, async_terminate.get(), terminate);
async_terminate->data = this;
@@ -97,15 +100,23 @@ void Map::start() {
#ifndef NDEBUG
map->map_thread = -1;
#endif
map->is_stopped = true;
}, this);
}
void Map::stop() {
void Map::stop(stop_callback cb) {
assert(uv_thread_self() == main_thread);
assert(main_thread != map_thread);
assert(async);
uv_async_send(async_terminate.get());
if (cb) {
while (!is_stopped) {
cb();
}
}
uv_thread_join(*thread);
async = false;