Take locks before signaling thread condition variables (#2636)

This commit is contained in:
mwilsnd
2024-07-19 16:11:13 -04:00
committed by GitHub
parent fcc57b6088
commit d15de92158
3 changed files with 5 additions and 2 deletions

View File

@@ -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();
}};

View File

@@ -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;
};

View File

@@ -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();
}