From b91bf996cfc632c9cf8ab6215f2839a6341dd250 Mon Sep 17 00:00:00 2001 From: James Horsley Date: Fri, 30 Jun 2023 03:37:58 +0100 Subject: [PATCH] Switch from deprecated tbb::mutex to std::mutex Signed-off-by: James Horsley --- dso/map/Image/ImageMap.cc | 4 ++-- dso/map/UsdUVTexture/UsdUVTexture.cc | 4 ++-- lib/common/mcrt_util/MutexPool2D.h | 4 +--- lib/common/mcrt_util/ProcessStats.h | 9 ++++----- lib/rendering/bvh/shading/AttributeKey.cc | 2 +- lib/rendering/bvh/shading/AttributeKey.h | 7 +++---- lib/rendering/bvh/shading/ShadingTLState.cc | 5 ++--- lib/rendering/mcrt_common/Util.cc | 4 ++-- lib/rendering/pbr/core/Cryptomatte.cc | 2 +- lib/rendering/pbr/core/Cryptomatte.h | 3 +-- lib/rendering/pbr/core/DeepBuffer.cc | 2 +- lib/rendering/pbr/core/DeepBuffer.h | 3 +-- lib/rendering/pbr/core/PbrTLState.cc | 7 +++---- lib/rendering/rndr/Film.h | 2 +- lib/rendering/rndr/RenderDriver.h | 1 + lib/rendering/shading/BasicTexture.cc | 4 ++-- lib/rendering/shading/Material.cc | 18 +++++++++--------- lib/rendering/shading/Material.h | 6 +++--- lib/rendering/shading/UdimTexture.cc | 7 +++---- .../texturing/sampler/TextureSampler.cc | 4 ++-- .../texturing/sampler/TextureSampler.h | 4 +--- .../texturing/sampler/TextureTLState.cc | 1 - 22 files changed, 46 insertions(+), 57 deletions(-) diff --git a/dso/map/Image/ImageMap.cc b/dso/map/Image/ImageMap.cc index 82a5556..4e48964 100644 --- a/dso/map/Image/ImageMap.cc +++ b/dso/map/Image/ImageMap.cc @@ -84,8 +84,8 @@ ImageMap::ImageMap(const scene_rdl2::rdl2::SceneClass &sceneClass, const std::st // to allow for the possibility that we may someday create these maps // on multiple threads, we'll protect the writes of the class statics // with a mutex. - static tbb::mutex errorMutex; - tbb::mutex::scoped_lock lock(errorMutex); + static std::mutex errorMutex; + std::scoped_lock lock(errorMutex); MOONRAY_START_THREADSAFE_STATIC_WRITE sStaticImageMapData.sErrorInvalidUdimCoord = mLogEventRegistry.createEvent(scene_rdl2::logging::ERROR_LEVEL, diff --git a/dso/map/UsdUVTexture/UsdUVTexture.cc b/dso/map/UsdUVTexture/UsdUVTexture.cc index c652bcb..dc615f3 100644 --- a/dso/map/UsdUVTexture/UsdUVTexture.cc +++ b/dso/map/UsdUVTexture/UsdUVTexture.cc @@ -53,8 +53,8 @@ UsdUVTexture::UsdUVTexture(const scene_rdl2::rdl2::SceneClass &sceneClass, const // to allow for the possibility that we may someday create these maps // on multiple threads, we'll protect the writes of the class statics // with a mutex. - static tbb::mutex errorMutex; - tbb::mutex::scoped_lock lock(errorMutex); + static std::mutex errorMutex; + std::scoped_lock lock(errorMutex); MOONRAY_START_THREADSAFE_STATIC_WRITE sStaticUsdUVTextureData.sErrorInvalidUdimCoord = mLogEventRegistry.createEvent(scene_rdl2::logging::ERROR_LEVEL, diff --git a/lib/common/mcrt_util/MutexPool2D.h b/lib/common/mcrt_util/MutexPool2D.h index 54eac61..af3a33b 100644 --- a/lib/common/mcrt_util/MutexPool2D.h +++ b/lib/common/mcrt_util/MutexPool2D.h @@ -8,8 +8,6 @@ #include #include -#include - namespace moonray { constexpr int getMutexCount(int log2MutexCount) { @@ -55,7 +53,7 @@ namespace moonray { } #endif - template + template class MutexPool2D { public: diff --git a/lib/common/mcrt_util/ProcessStats.h b/lib/common/mcrt_util/ProcessStats.h index 20202f2..d3bf528 100644 --- a/lib/common/mcrt_util/ProcessStats.h +++ b/lib/common/mcrt_util/ProcessStats.h @@ -8,12 +8,11 @@ #include #include -#include - #include #include #include #include +#include namespace moonray { namespace util { @@ -49,9 +48,9 @@ class ProcessStats // ifstream mutex to prevent corrupt reads // when we are getting log messages from // threaded sections of code - mutable tbb::mutex mMemoryReadMutex; - mutable tbb::mutex mReadIOMutex; - mutable tbb::mutex mSystemUtilMutex; + mutable std::mutex mMemoryReadMutex; + mutable std::mutex mReadIOMutex; + mutable std::mutex mSystemUtilMutex; }; diff --git a/lib/rendering/bvh/shading/AttributeKey.cc b/lib/rendering/bvh/shading/AttributeKey.cc index d86098b..a497252 100644 --- a/lib/rendering/bvh/shading/AttributeKey.cc +++ b/lib/rendering/bvh/shading/AttributeKey.cc @@ -8,7 +8,7 @@ using namespace scene_rdl2; namespace moonray { namespace shading { -tbb::mutex AttributeKey::sRegisterMutex; +std::mutex AttributeKey::sRegisterMutex; std::vector AttributeKey::sKeyNames; std::vector AttributeKey::sKeyTypes; std::vector AttributeKey::sKeySizes; diff --git a/lib/rendering/bvh/shading/AttributeKey.h b/lib/rendering/bvh/shading/AttributeKey.h index 2cbd271..6d29a0c 100644 --- a/lib/rendering/bvh/shading/AttributeKey.h +++ b/lib/rendering/bvh/shading/AttributeKey.h @@ -9,7 +9,6 @@ #pragma once #include -#include #include #include @@ -87,7 +86,7 @@ class AttributeKey static finline bool hasDerivatives(AttributeKey key); private: - static tbb::mutex sRegisterMutex; + static std::mutex sRegisterMutex; static std::vector sKeyNames; static std::vector sKeyTypes; static std::vector sKeySizes; @@ -269,7 +268,7 @@ AttributeKey::requestDerivatives() const return false; } { - tbb::mutex::scoped_lock lock(sRegisterMutex); + std::scoped_lock lock(sRegisterMutex); sHasDerivatives[mIndex] = 1; } return true; @@ -302,7 +301,7 @@ AttributeKey::insertKey(const std::string &name, bool requestDerivatives) std::pair lookup(name, type); int index = -1; { - tbb::mutex::scoped_lock lock(sRegisterMutex); + std::scoped_lock lock(sRegisterMutex); auto it = sTable.find(lookup); if (it == sTable.end()) { index = static_cast(sKeyNames.size()); diff --git a/lib/rendering/bvh/shading/ShadingTLState.cc b/lib/rendering/bvh/shading/ShadingTLState.cc index 1aaa1ad..895fdd7 100644 --- a/lib/rendering/bvh/shading/ShadingTLState.cc +++ b/lib/rendering/bvh/shading/ShadingTLState.cc @@ -3,7 +3,6 @@ #include "ShadingTLState.h" #include -#include namespace ispc { extern "C" uint32_t ShadingTLState_hudValidation(bool); @@ -33,7 +32,7 @@ struct Private }; Private gPrivate; -tbb::mutex gInitMutex; +std::mutex gInitMutex; void initPrivate(const mcrt_common::TLSInitParams &initParams) @@ -97,7 +96,7 @@ TLState::allocTls(mcrt_common::ThreadLocalState *tls, { { // Protect against races the very first time we initialize gPrivate. - tbb::mutex::scoped_lock lock(gInitMutex); + std::scoped_lock lock(gInitMutex); if (gPrivate.mRefCount == 0) { texture::TLState::initPrivate(initParams); diff --git a/lib/rendering/mcrt_common/Util.cc b/lib/rendering/mcrt_common/Util.cc index 39d43fb..917b2bd 100644 --- a/lib/rendering/mcrt_common/Util.cc +++ b/lib/rendering/mcrt_common/Util.cc @@ -4,10 +4,10 @@ // #include "Util.h" #include // backtrace -#include #include #include +#include namespace moonray { namespace mcrt_common { @@ -38,7 +38,7 @@ debugPrintThreadID(const char *contextString) void debugPrintCallstack(const char *contextString) { - static tbb::mutex mutex; + static std::mutex mutex; mutex.lock(); diff --git a/lib/rendering/pbr/core/Cryptomatte.cc b/lib/rendering/pbr/core/Cryptomatte.cc index f61a7c7..7bfd1b8 100644 --- a/lib/rendering/pbr/core/Cryptomatte.cc +++ b/lib/rendering/pbr/core/Cryptomatte.cc @@ -96,7 +96,7 @@ void CryptomatteBuffer::addSampleVector(unsigned x, unsigned y, float sampleId, bool incrementSamples) { // Lock in case multiple threads want to add samples to this pixel - tbb::mutex::scoped_lock lock(mPixelMutexes[getMutexIdx(x, y)]); + std::scoped_lock lock(mPixelMutexes[getMutexIdx(x, y)]); PixelEntry &pixelEntry = mPixelEntries[CRYPTOMATTE_TYPE_REGULAR][y * mWidth + x]; diff --git a/lib/rendering/pbr/core/Cryptomatte.h b/lib/rendering/pbr/core/Cryptomatte.h index 4cbe45c..943b9d2 100644 --- a/lib/rendering/pbr/core/Cryptomatte.h +++ b/lib/rendering/pbr/core/Cryptomatte.h @@ -9,7 +9,6 @@ #include #include -#include #include namespace moonray { @@ -202,7 +201,7 @@ class CryptomatteBuffer */ static const int mMutexTileSize = 15; // force mutex to be cache-line aligned for speed - struct CACHE_ALIGN AlignedMutex : public tbb::mutex {}; + struct CACHE_ALIGN AlignedMutex : public std::mutex {}; AlignedMutex *mPixelMutexes; int getMutexIdx(unsigned x, unsigned y) const { return (y % mMutexTileSize) * mMutexTileSize + (x % mMutexTileSize); diff --git a/lib/rendering/pbr/core/DeepBuffer.cc b/lib/rendering/pbr/core/DeepBuffer.cc index 52043d0..9ce2b85 100644 --- a/lib/rendering/pbr/core/DeepBuffer.cc +++ b/lib/rendering/pbr/core/DeepBuffer.cc @@ -351,7 +351,7 @@ DeepBuffer::addSample8x8Safe(unsigned x, unsigned y, unsigned subpixelX, unsigne float scale, float weight) { // Lock in case multiple threads want to add samples to this pixel - tbb::mutex::scoped_lock lock(mPixelMutex[getMutexIdx(x, y)]); + std::scoped_lock lock(mPixelMutex[getMutexIdx(x, y)]); addSample8x8(x, y, subpixelX, subpixelY, layer, ids, t, rayZ, normal, alpha, channels, numChannels, values, scale, weight); diff --git a/lib/rendering/pbr/core/DeepBuffer.h b/lib/rendering/pbr/core/DeepBuffer.h index b8372f8..536423f 100644 --- a/lib/rendering/pbr/core/DeepBuffer.h +++ b/lib/rendering/pbr/core/DeepBuffer.h @@ -13,7 +13,6 @@ #include #include #include -#include namespace moonray { @@ -420,7 +419,7 @@ class DeepBuffer */ static const int mMutexTileSize = 15; // force mutex to be cache-line aligned for speed - struct CACHE_ALIGN AlignedMutex : public tbb::mutex {}; + struct CACHE_ALIGN AlignedMutex : public std::mutex {}; AlignedMutex *mPixelMutex; int getMutexIdx(unsigned x, unsigned y) const { return (y % mMutexTileSize) * mMutexTileSize + (x % mMutexTileSize); diff --git a/lib/rendering/pbr/core/PbrTLState.cc b/lib/rendering/pbr/core/PbrTLState.cc index 5281335..a51c344 100644 --- a/lib/rendering/pbr/core/PbrTLState.cc +++ b/lib/rendering/pbr/core/PbrTLState.cc @@ -10,7 +10,6 @@ #include #include #include -#include // These aren't free so only turn it on if you are doing memory profiling. // This will print out the peak number of pool items used for a particular run. @@ -100,7 +99,7 @@ struct Private }; Private gPrivate; -tbb::mutex gInitMutex; +std::mutex gInitMutex; void initPool(const unsigned poolSize, const unsigned numTBBThreads, @@ -357,7 +356,7 @@ TLState::~TLState() { // Protect against races the during gPrivate clean up. - tbb::mutex::scoped_lock lock(gInitMutex); + std::scoped_lock lock(gInitMutex); MOONRAY_THREADSAFE_STATIC_WRITE(--gPrivate.mRefCount); if (gPrivate.mRefCount == 0) { @@ -883,7 +882,7 @@ TLState::allocTls(mcrt_common::ThreadLocalState *tls, { { // Protect against races the very first time we initialize gPrivate. - tbb::mutex::scoped_lock lock(gInitMutex); + std::scoped_lock lock(gInitMutex); if (gPrivate.mRefCount == 0) { initPrivate(initParams); diff --git a/lib/rendering/rndr/Film.h b/lib/rendering/rndr/Film.h index e4c5623..1f792d0 100644 --- a/lib/rendering/rndr/Film.h +++ b/lib/rendering/rndr/Film.h @@ -213,7 +213,7 @@ class CACHE_ALIGN Film // updating statistics in vector mode. void addSampleStatisticsSafe(unsigned px, unsigned py, std::size_t idx, const float* aovs) { - tbb::mutex::scoped_lock lock(mStatsMutex.getMutex(px, py)); + std::scoped_lock lock(mStatsMutex.getMutex(px, py)); addSampleStatistics(px, py, idx, aovs); } diff --git a/lib/rendering/rndr/RenderDriver.h b/lib/rendering/rndr/RenderDriver.h index be0231c..ad8515b 100644 --- a/lib/rendering/rndr/RenderDriver.h +++ b/lib/rendering/rndr/RenderDriver.h @@ -28,6 +28,7 @@ #include #include +#include //#define SINGLE_THREAD_CRAWLALLPIXELS diff --git a/lib/rendering/shading/BasicTexture.cc b/lib/rendering/shading/BasicTexture.cc index fa047f4..ceb0689 100644 --- a/lib/rendering/shading/BasicTexture.cc +++ b/lib/rendering/shading/BasicTexture.cc @@ -99,8 +99,8 @@ class BasicTexture::Impl // to allow for the possibility that we may someday create image maps // on multiple threads, we'll protect the writes of the class statics // with a mutex. - static tbb::mutex errorMutex; - tbb::mutex::scoped_lock lock(errorMutex); + static std::mutex errorMutex; + std::scoped_lock lock(errorMutex); MOONRAY_START_THREADSAFE_STATIC_WRITE mIspc.mBasicTextureStaticDataPtr = &sBasicTextureStaticData; diff --git a/lib/rendering/shading/Material.cc b/lib/rendering/shading/Material.cc index f3c52b5..61290eb 100644 --- a/lib/rendering/shading/Material.cc +++ b/lib/rendering/shading/Material.cc @@ -8,11 +8,11 @@ namespace moonray { namespace shading { -tbb::mutex Material::sMaterialListMutex; +std::mutex Material::sMaterialListMutex; MaterialPtrList Material::sAllMaterials; MaterialPtrList Material::sQueuelessMaterials; -tbb::mutex Material::sShadeQueueMutex; +std::mutex Material::sShadeQueueMutex; ShadeQueueList Material::sShadeQueues; tbb::atomic Material::sFlushCycleIdx; @@ -27,7 +27,7 @@ Material::Material(const scene_rdl2::rdl2::SceneObject & owner) : mMaterialLabelId(-1), // no material label mLpeMaterialLabelId(-1) // no lpe material label { - tbb::mutex::scoped_lock lock(sMaterialListMutex); + std::scoped_lock lock(sMaterialListMutex); sAllMaterials.push_back(this); sQueuelessMaterials.push_back(this); mMaterialId = 0; @@ -39,7 +39,7 @@ Material::~Material() if (mShadeQueue) { { - tbb::mutex::scoped_lock lock(sShadeQueueMutex); + std::scoped_lock lock(sShadeQueueMutex); // Check the shade queue size also since it may have already been destroyed // during global program destruction time. @@ -59,7 +59,7 @@ Material::~Material() } { - tbb::mutex::scoped_lock lock(sMaterialListMutex); + std::scoped_lock lock(sMaterialListMutex); // Remove ourselves from global list of Materials. for (auto it = sAllMaterials.begin(); it != sAllMaterials.end(); ++it) { @@ -99,7 +99,7 @@ Material::deferEntriesForLaterProcessing(mcrt_common::ThreadLocalState *tls, } { - tbb::mutex::scoped_lock lock(mDeferredEntryMutex); + std::scoped_lock lock(mDeferredEntryMutex); mDeferredEntries.insert(mDeferredEntries.end(), entries, entries + numEntries); } } @@ -151,8 +151,8 @@ Material::retrieveDeferredEntries(mcrt_common::ThreadLocalState *tls, void Material::allocShadeQueues(unsigned shadeQueueSize, ShadeQueue::Handler handler) { - tbb::mutex::scoped_lock lockMaterialMutex(sMaterialListMutex); - tbb::mutex::scoped_lock lockShadeQueueMutex(sShadeQueueMutex); + std::scoped_lock lockMaterialMutex(sMaterialListMutex); + std::scoped_lock lockShadeQueueMutex(sShadeQueueMutex); for (auto it = sQueuelessMaterials.begin(); it != sQueuelessMaterials.end(); ++it) { (*it)->allocShadeQueue(shadeQueueSize, handler); @@ -283,7 +283,7 @@ Material::resetDeferredEntryState() { for (auto it = sAllMaterials.begin(); it != sAllMaterials.end(); ++it) { Material *material = *it; - tbb::mutex::scoped_lock lock(material->mDeferredEntryMutex); + std::scoped_lock lock(material->mDeferredEntryMutex); material->mDeferredEntries.clear(); } diff --git a/lib/rendering/shading/Material.h b/lib/rendering/shading/Material.h index 6d9e92e..ede8636 100644 --- a/lib/rendering/shading/Material.h +++ b/lib/rendering/shading/Material.h @@ -167,14 +167,14 @@ class Material : public RootShader // We will also get warned when executing this codepath at render time via // the logger so if it becomes a common case, we need to revisit and remove // these locks and heap allocations. - tbb::mutex mDeferredEntryMutex; + std::mutex mDeferredEntryMutex; std::vector mDeferredEntries; - static tbb::mutex sMaterialListMutex; + static std::mutex sMaterialListMutex; static MaterialPtrList sAllMaterials; static MaterialPtrList sQueuelessMaterials; - static tbb::mutex sShadeQueueMutex; + static std::mutex sShadeQueueMutex; static ShadeQueueList sShadeQueues; // This is used by the flushNonEmptyShadeQueue function to iterate through all queues diff --git a/lib/rendering/shading/UdimTexture.cc b/lib/rendering/shading/UdimTexture.cc index 84eb6b9..e50167b 100644 --- a/lib/rendering/shading/UdimTexture.cc +++ b/lib/rendering/shading/UdimTexture.cc @@ -19,7 +19,6 @@ #include #include -#include #include #include @@ -121,8 +120,8 @@ class UdimTexture::Impl // to allow for the possibility that we may someday create image maps // on multiple threads, we'll protect the writes of the class statics // with a mutex. - static tbb::mutex errorMutex; - tbb::mutex::scoped_lock lock(errorMutex); + static std::mutex errorMutex; + std::scoped_lock lock(errorMutex); MOONRAY_START_THREADSAFE_STATIC_WRITE mIspc.mUdimTextureStaticDataPtr = &sUdimTextureStaticData; @@ -251,7 +250,7 @@ class UdimTexture::Impl mIspc.mIs8bit = mIs8bit; mIspc.mIsValid = true; - tbb::mutex errorMutex; + std::mutex errorMutex; tbb::blocked_range range(0, mTextureHandleIndices.size()); tbb::parallel_for(range, [&] (const tbb::blocked_range &r) { diff --git a/lib/rendering/texturing/sampler/TextureSampler.cc b/lib/rendering/texturing/sampler/TextureSampler.cc index 14ed965..520c777 100644 --- a/lib/rendering/texturing/sampler/TextureSampler.cc +++ b/lib/rendering/texturing/sampler/TextureSampler.cc @@ -466,7 +466,7 @@ TextureSampler::registerMapForInvalidation(const std::string &fileName, scene_rd { // Textures could be loaded in parallel, use mutex to avoid data race. - tbb::recursive_mutex::scoped_lock lock(mMutex); + std::scoped_lock lock(mMutex); OIIO::ustring oiioFileName(fileName); @@ -492,7 +492,7 @@ TextureSampler::registerMapForInvalidation(const std::string &fileName, scene_rd void TextureSampler::unregisterMapForInvalidation(scene_rdl2::rdl2::Shader *map) { - tbb::recursive_mutex::scoped_lock lock(mMutex); + std::scoped_lock lock(mMutex); MNRY_ASSERT(isValid()); auto mapRange = mShaderToName.equal_range(map); diff --git a/lib/rendering/texturing/sampler/TextureSampler.h b/lib/rendering/texturing/sampler/TextureSampler.h index 8b8e103..599cb8d 100644 --- a/lib/rendering/texturing/sampler/TextureSampler.h +++ b/lib/rendering/texturing/sampler/TextureSampler.h @@ -11,8 +11,6 @@ #include #include -#include - // system #include #include @@ -137,7 +135,7 @@ class TextureSampler // For the udim case, a single ImageMap may reference multiple texture files. std::multimap mShaderToName; - tbb::recursive_mutex mMutex; + std::recursive_mutex mMutex; Parser mParser; }; diff --git a/lib/rendering/texturing/sampler/TextureTLState.cc b/lib/rendering/texturing/sampler/TextureTLState.cc index 3e95ce5..2dc55ee 100644 --- a/lib/rendering/texturing/sampler/TextureTLState.cc +++ b/lib/rendering/texturing/sampler/TextureTLState.cc @@ -4,7 +4,6 @@ #include "TextureSampler.h" #include "TextureTLState.h" #include -#include namespace ispc { extern "C" uint32_t TextureTLState_hudValidation(bool);