summaryrefslogtreecommitdiff
path: root/include/mbgl
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-07-21 15:51:34 +0300
committerIvo van Dongen <info@ivovandongen.nl>2017-08-14 23:10:09 +0300
commit034551f1519491110b83f74662af7d4c0c509104 (patch)
tree62caaf5cd42d0189a26af298a474919108142eff /include/mbgl
parent50bd7a112663d247bc453c205f6fcdb6759e7dde (diff)
downloadqtlocation-mapboxgl-034551f1519491110b83f74662af7d4c0c509104.tar.gz
[core] make thread pause/resume thread safe
Diffstat (limited to 'include/mbgl')
-rw-r--r--include/mbgl/util/thread.hpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/include/mbgl/util/thread.hpp b/include/mbgl/util/thread.hpp
index 572f46080e..06254569a9 100644
--- a/include/mbgl/util/thread.hpp
+++ b/include/mbgl/util/thread.hpp
@@ -96,9 +96,11 @@ public:
// sent to a paused `Object` will be queued and only processed after
// `resume()` is called.
void pause() {
- MBGL_VERIFY_THREAD(tid);
+ std::unique_lock<std::mutex> lock(pauseMutex);
- assert(!paused);
+ if (paused) {
+ return;
+ }
paused = std::make_unique<std::promise<void>>();
resumed = std::make_unique<std::promise<void>>();
@@ -116,9 +118,11 @@ public:
// Resumes the `Object` thread previously paused by `pause()`.
void resume() {
- MBGL_VERIFY_THREAD(tid);
+ std::unique_lock<std::mutex> lock(pauseMutex);
- assert(paused);
+ if (!paused) {
+ return;
+ }
resumed->set_value();