Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from deprecated tbb::mutex to std::mutex #6

Open
wants to merge 1 commit into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dso/map/Image/ImageMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions dso/map/UsdUVTexture/UsdUVTexture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions lib/common/mcrt_util/MutexPool2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include <scene_rdl2/common/platform/Platform.h>
#include <scene_rdl2/render/util/BitUtils.h>

#include <tbb/mutex.h>

namespace moonray {
constexpr int getMutexCount(int log2MutexCount)
{
Expand Down Expand Up @@ -55,7 +53,7 @@ namespace moonray {
}
#endif

template <int sLog2MutexCount, typename MutexType = tbb::mutex>
template <int sLog2MutexCount, typename MutexType = std::mutex>
class MutexPool2D
{
public:
Expand Down
9 changes: 4 additions & 5 deletions lib/common/mcrt_util/ProcessStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
#include <scene_rdl2/common/platform/Platform.h>
#include <scene_rdl2/render/logging/logging.h>

#include <tbb/mutex.h>

#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include <mutex>

namespace moonray {
namespace util {
Expand Down Expand Up @@ -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;

};

Expand Down
2 changes: 1 addition & 1 deletion lib/rendering/bvh/shading/AttributeKey.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using namespace scene_rdl2;
namespace moonray {
namespace shading {

tbb::mutex AttributeKey::sRegisterMutex;
std::mutex AttributeKey::sRegisterMutex;
std::vector<std::string> AttributeKey::sKeyNames;
std::vector<AttributeType> AttributeKey::sKeyTypes;
std::vector<size_t> AttributeKey::sKeySizes;
Expand Down
7 changes: 3 additions & 4 deletions lib/rendering/bvh/shading/AttributeKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#pragma once

#include <scene_rdl2/scene/rdl2/Types.h>
#include <tbb/mutex.h>
#include <unordered_set>
#include <map>

Expand Down Expand Up @@ -87,7 +86,7 @@ class AttributeKey
static finline bool hasDerivatives(AttributeKey key);

private:
static tbb::mutex sRegisterMutex;
static std::mutex sRegisterMutex;
static std::vector<std::string> sKeyNames;
static std::vector<AttributeType> sKeyTypes;
static std::vector<size_t> sKeySizes;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -302,7 +301,7 @@ AttributeKey::insertKey(const std::string &name, bool requestDerivatives)
std::pair<std::string, AttributeType> 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<int>(sKeyNames.size());
Expand Down
5 changes: 2 additions & 3 deletions lib/rendering/bvh/shading/ShadingTLState.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "ShadingTLState.h"
#include <moonray/common/mcrt_macros/moonray_static_check.h>
#include <tbb/mutex.h>

namespace ispc {
extern "C" uint32_t ShadingTLState_hudValidation(bool);
Expand Down Expand Up @@ -33,7 +32,7 @@ struct Private
};

Private gPrivate;
tbb::mutex gInitMutex;
std::mutex gInitMutex;

void
initPrivate(const mcrt_common::TLSInitParams &initParams)
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions lib/rendering/mcrt_common/Util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
//
#include "Util.h"
#include <execinfo.h> // backtrace
#include <tbb/mutex.h>
#include <sys/syscall.h>

#include <cstring>
#include <mutex>

namespace moonray {
namespace mcrt_common {
Expand Down Expand Up @@ -38,7 +38,7 @@ debugPrintThreadID(const char *contextString)
void
debugPrintCallstack(const char *contextString)
{
static tbb::mutex mutex;
static std::mutex mutex;

mutex.lock();

Expand Down
2 changes: 1 addition & 1 deletion lib/rendering/pbr/core/Cryptomatte.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
3 changes: 1 addition & 2 deletions lib/rendering/pbr/core/Cryptomatte.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <scene_rdl2/scene/rdl2/RenderOutput.h>

#include <list>
#include <tbb/mutex.h>
#include <vector>

namespace moonray {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/rendering/pbr/core/DeepBuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions lib/rendering/pbr/core/DeepBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <moonray/deepfile/DcxChannelSet.h>
#include <moonray/deepfile/DcxDeepImageTile.h>
#include <OpenEXR/ImfHeader.h>
#include <tbb/mutex.h>

namespace moonray {

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions lib/rendering/pbr/core/PbrTLState.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <moonray/rendering/pbr/handlers/RayHandlers.h>
#include <moonray/rendering/shading/Types.h>
#include <moonray/common/mcrt_macros/moonray_static_check.h>
#include <tbb/mutex.h>

// 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.
Expand Down Expand Up @@ -100,7 +99,7 @@ struct Private
};

Private gPrivate;
tbb::mutex gInitMutex;
std::mutex gInitMutex;

void
initPool(const unsigned poolSize, const unsigned numTBBThreads,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/rendering/rndr/Film.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions lib/rendering/rndr/RenderDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <scene_rdl2/render/util/AtomicFloat.h>

#include <tbb/task_scheduler_init.h>
#include <tbb/spin_mutex.h>

//#define SINGLE_THREAD_CRAWLALLPIXELS

Expand Down
4 changes: 2 additions & 2 deletions lib/rendering/shading/BasicTexture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions lib/rendering/shading/Material.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t> Material::sFlushCycleIdx;
Expand All @@ -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;
Expand All @@ -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.
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}

Expand Down
6 changes: 3 additions & 3 deletions lib/rendering/shading/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<SortedRayState> 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
Expand Down
7 changes: 3 additions & 4 deletions lib/rendering/shading/UdimTexture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include <tbb/blocked_range.h>
#include <tbb/parallel_for.h>
#include <tbb/mutex.h>

#include <dirent.h>
#include <unordered_set>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -251,7 +250,7 @@ class UdimTexture::Impl
mIspc.mIs8bit = mIs8bit;

mIspc.mIsValid = true;
tbb::mutex errorMutex;
std::mutex errorMutex;

tbb::blocked_range<int> range(0, mTextureHandleIndices.size());
tbb::parallel_for(range, [&] (const tbb::blocked_range<int> &r) {
Expand Down
Loading