Take locks before signaling thread condition variables (#2636)
This commit is contained in:
@@ -53,6 +53,8 @@ void TileCache::deferredRelease(std::unique_ptr<Tile>&& tile) {
|
||||
// last one and the destruction actually occurs here on this thread.
|
||||
std::function<void()> func{[tile_{CaptureWrapper<Tile>{std::move(tile)}}, this]() mutable {
|
||||
tile_.item = {};
|
||||
|
||||
std::lock_guard<std::mutex> counterLock(deferredSignalLock);
|
||||
deferredDeletionsPending--;
|
||||
deferredSignal.notify_all();
|
||||
}};
|
||||
|
||||
@@ -50,10 +50,9 @@ private:
|
||||
std::map<OverscaledTileID, std::unique_ptr<Tile>> tiles;
|
||||
std::list<OverscaledTileID> orderedKeys;
|
||||
TaggedScheduler threadPool;
|
||||
std::atomic<size_t> deferredDeletionsPending{0};
|
||||
size_t deferredDeletionsPending{0};
|
||||
std::mutex deferredSignalLock;
|
||||
std::condition_variable deferredSignal;
|
||||
|
||||
size_t size;
|
||||
};
|
||||
|
||||
|
||||
@@ -130,6 +130,8 @@ void ThreadedSchedulerBase::schedule(const util::SimpleIdentity tag, std::functi
|
||||
taskCount++;
|
||||
}
|
||||
|
||||
// Take the worker lock before notifying to prevent threads from waiting while we try to wake them
|
||||
std::lock_guard<std::mutex> workerLock(workerMutex);
|
||||
cvAvailable.notify_one();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user