提交 44bb6a97 编写于 作者: M Matt Pharr

Small fixes to make valgrind happy.

- Use a std::atomic for the bytesUsed statistic in the BufferCache (a legit
 bug, though harmless.)
- Hold associated mutexes when consuming futures. Strictly speaking, all of
  the worker threads should be idle when these are consumed and it's only the
  main thread that's running, so there should be no need...
上级 5c09a439
......@@ -1066,6 +1066,7 @@ void BasicScene::CreateMaterials(const NamedTextures &textures,
std::map<std::string, pbrt::Material> *namedMaterialsOut,
std::vector<pbrt::Material> *materialsOut) {
LOG_VERBOSE("Starting to consume normal map futures");
std::lock_guard<std::mutex> lock(materialMutex);
for (auto &fut : normalMapFutures) {
CHECK(normalMaps.find(fut.first) == normalMaps.end());
normalMaps[fut.first] = fut.second.Get();
......@@ -1123,10 +1124,17 @@ NamedTextures BasicScene::CreateTextures() {
// Consume futures
LOG_VERBOSE("Starting to consume texture futures");
// The lock shouldn't be necessary since only the main thread should be
// active when CreateTextures() is called, but valgrind doesn't know
// that...
textureMutex.lock();
for (auto &tex : floatTextureFutures)
textures.floatTextures[tex.first] = tex.second.Get();
floatTextureFutures.clear();
for (auto &tex : spectrumTextureFutures)
textures.albedoSpectrumTextures[tex.first] = tex.second.Get();
spectrumTextureFutures.clear();
textureMutex.unlock();
LOG_VERBOSE("Finished consuming texture futures");
LOG_VERBOSE("Starting to create remaining textures");
......@@ -1279,6 +1287,7 @@ std::vector<Light> BasicScene::CreateLights(
LOG_VERBOSE("Finished area lights");
LOG_VERBOSE("Starting to consume non-area light futures");
std::lock_guard<std::mutex> lock(lightMutex);
for (auto &fut : lightFutures)
lights.push_back(fut.Get());
LOG_VERBOSE("Finished consuming non-area light futures");
......
......@@ -14,6 +14,7 @@
#include <pbrt/util/stats.h>
#include <pbrt/util/vecmath.h>
#include <atomic>
#include <cstring>
#include <shared_mutex>
#include <string>
......@@ -98,7 +99,7 @@ class BufferCache {
static constexpr int nShards = 1 << logShards;
std::shared_mutex mutex[nShards];
std::unordered_set<Buffer, BufferHasher> cache[nShards];
size_t bytesUsed = 0;
std::atomic<size_t> bytesUsed{};
};
// BufferCache Global Declarations
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册