Browse Source

Bugfix: Cleaning up a variety of invalid calls to RAII mutex lock

BearishSun 8 years ago
parent
commit
483b24b0d1

+ 4 - 4
Source/BansheeOpenAudio/BsOAAudio.cpp

@@ -173,7 +173,7 @@ namespace bs
 
 	void OAAudio::startStreaming(OAAudioSource* source)
 	{
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		mStreamingCommandQueue.push_back({ StreamingCommandType::Start, source });
 		mDestroyedSources.erase(source);
@@ -181,7 +181,7 @@ namespace bs
 
 	void OAAudio::stopStreaming(OAAudioSource* source)
 	{
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		mStreamingCommandQueue.push_back({ StreamingCommandType::Stop, source });
 		mDestroyedSources.insert(source);
@@ -266,7 +266,7 @@ namespace bs
 	void OAAudio::updateStreaming()
 	{
 		{
-			Lock(mMutex);
+			Lock lock(mMutex);
 
 			for(auto& command : mStreamingCommandQueue)
 			{
@@ -291,7 +291,7 @@ namespace bs
 		{
 			// Check if the source got destroyed while streaming
 			{
-				Lock(mMutex);
+				Lock lock(mMutex);
 
 				auto iterFind = mDestroyedSources.find(source);
 				if (iterFind != mDestroyedSources.end())

+ 10 - 10
Source/BansheeOpenAudio/BsOAAudioSource.cpp

@@ -26,7 +26,7 @@ namespace bs
 	{
 		stop();
 
-		Lock(mMutex);
+		Lock lock(mMutex);
 		AudioSource::setClip(clip);
 
 		applyClip();
@@ -166,7 +166,7 @@ namespace bs
 
 		if(requiresStreaming())
 		{
-			Lock(mMutex);
+			Lock lock(mMutex);
 			
 			if (!mIsStreaming)
 			{
@@ -224,7 +224,7 @@ namespace bs
 		}
 
 		{
-			Lock(mMutex);
+			Lock lock(mMutex);
 
 			mStreamProcessedPosition = 0;
 			mStreamQueuedPosition = 0;
@@ -273,7 +273,7 @@ namespace bs
 		bool needsStreaming = requiresStreaming();
 		float clipTime;
 		{
-			Lock(mMutex);
+			Lock lock(mMutex);
 
 			if (!needsStreaming)
 				clipTime = time;
@@ -308,7 +308,7 @@ namespace bs
 
 	float OAAudioSource::getTime() const
 	{
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		auto& contexts = gOAAudio()._getContexts();
 
@@ -343,7 +343,7 @@ namespace bs
 		auto& contexts = gOAAudio()._getContexts();
 		UINT32 numContexts = (UINT32)contexts.size();
 		
-		Lock(mMutex);
+		Lock lock(mMutex);
 		for (UINT32 i = 0; i < numContexts; i++)
 		{
 			if (contexts.size() > 1)
@@ -362,7 +362,7 @@ namespace bs
 		UINT32 numContexts = (UINT32)contexts.size();
 
 		{
-			Lock(mMutex);
+			Lock lock(mMutex);
 
 			for (UINT32 i = 0; i < numContexts; i++)
 			{
@@ -406,7 +406,7 @@ namespace bs
 			}
 
 			{
-				Lock(mMutex);
+				Lock lock(mMutex);
 
 				if (!mIsStreaming)
 				{
@@ -469,7 +469,7 @@ namespace bs
 
 	void OAAudioSource::stream()
 	{
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		AudioDataInfo info;
 		info.bitDepth = mAudioClip->getBitDepth();
@@ -632,7 +632,7 @@ namespace bs
 		stop();
 
 		{
-			Lock(mMutex);
+			Lock lock(mMutex);
 			applyClip();
 		}
 

+ 2 - 2
Source/BansheeUtility/Win32/BsWin32CrashHandler.cpp

@@ -460,7 +460,7 @@ namespace bs
 		const String& file, UINT32 line) const
 	{
 		// Win32 debug methods are not thread safe
-		Lock(m->mutex);
+		Lock lock(m->mutex);
 
 		logErrorAndStackTrace(type, description, function, file, line);
 		saveCrashLog();
@@ -478,7 +478,7 @@ namespace bs
 		EXCEPTION_POINTERS* exceptionData = (EXCEPTION_POINTERS*)exceptionDataPtr;
 
 		// Win32 debug methods are not thread safe
-		Lock(m->mutex);
+		Lock lock(m->mutex);
 
 		win32_initPSAPI();
 		win32_loadSymbols();

+ 8 - 8
Source/BansheeVulkanRenderAPI/BsVulkanGpuParams.cpp

@@ -27,7 +27,7 @@ namespace bs { namespace ct
 
 	VulkanGpuParams::~VulkanGpuParams()
 	{
-		Lock lock(mMutex);
+		Lock Lock lock(mMutex);
 
 		UINT32 numSets = mParamInfo->getNumSets();
 		for (UINT32 i = 0; i < BS_MAX_DEVICES; i++)
@@ -85,7 +85,7 @@ namespace bs { namespace ct
 			.reserve<VkSampler>(numSamplers * numDevices)
 			.init();
 
-		Lock lock(mMutex); // Set write operations need to be thread safe
+		Lock Lock lock(mMutex); // Set write operations need to be thread safe
 
 		mSetsDirty = mAlloc.alloc<bool>(numSets);
 		bs_zero_out(mSetsDirty, numSets);
@@ -235,7 +235,7 @@ namespace bs { namespace ct
 
 		UINT32 sequentialIdx = vkParamInfo.getSequentialSlot(GpuPipelineParamInfo::ParamType::ParamBlock, set, slot);
 
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		VulkanGpuParamBlockBuffer* vulkanParamBlockBuffer =
 			static_cast<VulkanGpuParamBlockBuffer*>(paramBlockBuffer.get());
@@ -286,7 +286,7 @@ namespace bs { namespace ct
 
 		UINT32 sequentialIdx = vkParamInfo.getSequentialSlot(GpuPipelineParamInfo::ParamType::Texture, set, slot);
 
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		VulkanTexture* vulkanTexture = static_cast<VulkanTexture*>(texture.get());
 		for (UINT32 i = 0; i < BS_MAX_DEVICES; i++)
@@ -347,7 +347,7 @@ namespace bs { namespace ct
 
 		UINT32 sequentialIdx = vkParamInfo.getSequentialSlot(GpuPipelineParamInfo::ParamType::LoadStoreTexture, set, slot);
 
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		VulkanTexture* vulkanTexture = static_cast<VulkanTexture*>(texture.get());
 		for (UINT32 i = 0; i < BS_MAX_DEVICES; i++)
@@ -398,7 +398,7 @@ namespace bs { namespace ct
 
 		UINT32 sequentialIdx = vkParamInfo.getSequentialSlot(GpuPipelineParamInfo::ParamType::Buffer, set, slot);
 
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		VulkanGpuBuffer* vulkanBuffer = static_cast<VulkanGpuBuffer*>(buffer.get());
 		for (UINT32 i = 0; i < BS_MAX_DEVICES; i++)
@@ -482,7 +482,7 @@ namespace bs { namespace ct
 
 		UINT32 sequentialIdx = vkParamInfo.getSequentialSlot(GpuPipelineParamInfo::ParamType::SamplerState, set, slot);
 
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		VulkanSamplerState* vulkanSampler = static_cast<VulkanSamplerState*>(sampler.get());
 		for(UINT32 i = 0; i < BS_MAX_DEVICES; i++)
@@ -542,7 +542,7 @@ namespace bs { namespace ct
 		UINT32 numSamplers = vkParamInfo.getNumElements(GpuPipelineParamInfo::ParamType::SamplerState);
 		UINT32 numSets = vkParamInfo.getNumSets();
 
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		// Registers resources with the command buffer, and check if internal resource handled changed (in which case set
 		// needs updating - this can happen due to resource writes, as internally system might find it more performant

+ 2 - 2
Source/BansheeVulkanRenderAPI/BsVulkanGpuPipelineState.cpp

@@ -94,7 +94,7 @@ namespace bs { namespace ct
 
 	void VulkanGraphicsPipelineState::initialize()
 	{
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		GraphicsPipelineState::initialize();
 
@@ -321,7 +321,7 @@ namespace bs { namespace ct
 		UINT32 deviceIdx, VulkanFramebuffer* framebuffer, UINT32 readOnlyFlags, DrawOperationType drawOp, 
 			const SPtr<VulkanVertexInput>& vertexInput)
 	{
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		if (mPerDeviceData[deviceIdx].device == nullptr)
 			return nullptr;

+ 5 - 5
Source/BansheeVulkanRenderAPI/BsVulkanResource.h

@@ -85,7 +85,7 @@ namespace bs { namespace ct
 		 *			done on the device but this method may still report true. If you need to know the latest state
 		 *			call VulkanCommandBufferManager::refreshStates() before checking for usage.
 		 */
-		bool isUsed() const { Lock(mMutex); return mNumUsedHandles > 0; }
+		bool isUsed() const { Lock lock(mMutex); return mNumUsedHandles > 0; }
 
 		/** 
 		 * Checks is the resource currently bound to any command buffer.
@@ -94,7 +94,7 @@ namespace bs { namespace ct
 		 *			done on the device but this method may still report true. If you need to know the latest state
 		 *			call VulkanCommandBufferManager::refreshStates() before checking for usage.
 		 */
-		bool isBound() const { Lock(mMutex); return mNumBoundHandles > 0; }
+		bool isBound() const { Lock lock(mMutex); return mNumBoundHandles > 0; }
 
 		/** 
 		 * Returns the queue family the resource is currently owned by. Returns -1 if owned by no queue.
@@ -102,7 +102,7 @@ namespace bs { namespace ct
 		 * @note	If resource concurrency is enabled, then this value has no meaning as the resource can be used on
 		 *			multiple queue families at once.
 		 */
-		UINT32 getQueueFamily() const { Lock(mMutex); return mQueueFamily; }
+		UINT32 getQueueFamily() const { Lock lock(mMutex); return mQueueFamily; }
 
 		/** 
 		 * Returns a mask that has bits set for every queue that the resource is currently used (read or written) by.
@@ -120,7 +120,7 @@ namespace bs { namespace ct
 		UINT32 getBoundCount() const { return mNumBoundHandles; }
 
 		/** Returns true if the resource is only allowed to be used by a single queue family at once. */
-		bool isExclusive() const { Lock(mMutex); return mState != State::Shared; }
+		bool isExclusive() const { Lock lock(mMutex); return mState != State::Shared; }
 
 		/** 
 		 * Destroys the resource and frees its memory. If the resource is currently being used on a device, the
@@ -149,7 +149,7 @@ namespace bs { namespace ct
 		UINT32 mNumUsedHandles;
 		UINT32 mNumBoundHandles;
 
-		Mutex mMutex;
+		mutable Mutex mMutex;
 	};
 
 	/** 

+ 6 - 6
Source/BansheeVulkanRenderAPI/Managers/BsVulkanQueryManager.cpp

@@ -13,7 +13,7 @@ namespace bs { namespace ct
 	VulkanQueryPool::VulkanQueryPool(VulkanDevice& device)
 		:mDevice(device)
 	{
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		allocatePool(VK_QUERY_TYPE_TIMESTAMP);
 		allocatePool(VK_QUERY_TYPE_OCCLUSION);
@@ -21,7 +21,7 @@ namespace bs { namespace ct
 
 	VulkanQueryPool::~VulkanQueryPool()
 	{
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		for (auto& entry : mTimerQueries)
 		{
@@ -102,7 +102,7 @@ namespace bs { namespace ct
 
 	VulkanQuery* VulkanQueryPool::beginTimerQuery(VulkanCmdBuffer* cb)
 	{
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		VulkanQuery* query = getQuery(VK_QUERY_TYPE_TIMESTAMP);
 		query->mFree = false;
@@ -119,7 +119,7 @@ namespace bs { namespace ct
 
 	VulkanQuery* VulkanQueryPool::beginOcclusionQuery(VulkanCmdBuffer* cb, bool precise)
 	{
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		VulkanQuery* query = getQuery(VK_QUERY_TYPE_TIMESTAMP);
 		query->mFree = false;
@@ -136,7 +136,7 @@ namespace bs { namespace ct
 
 	void VulkanQueryPool::endOcclusionQuery(VulkanQuery* query, VulkanCmdBuffer* cb)
 	{
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		VkCommandBuffer vkCmdBuf = cb->getHandle();
 		vkCmdEndQuery(vkCmdBuf, query->mPool, query->mQueryIdx);
@@ -144,7 +144,7 @@ namespace bs { namespace ct
 
 	void VulkanQueryPool::releaseQuery(VulkanQuery* query)
 	{
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		query->mFree = true;
 		query->mNeedsReset = true;

+ 5 - 5
Source/BansheeVulkanRenderAPI/Managers/BsVulkanVertexInputManager.cpp

@@ -33,7 +33,7 @@ namespace bs { namespace ct
 
 	VulkanVertexInputManager::VulkanVertexInputManager()
 	{
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		mNextId = 1;
 		mWarningShown = false;
@@ -42,7 +42,7 @@ namespace bs { namespace ct
 
 	VulkanVertexInputManager::~VulkanVertexInputManager()
 	{
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		while (mVertexInputMap.begin() != mVertexInputMap.end())
 		{
@@ -54,7 +54,7 @@ namespace bs { namespace ct
 	SPtr<VulkanVertexInput> VulkanVertexInputManager::getVertexInfo(
 		const SPtr<VertexDeclaration>& vbDecl, const SPtr<VertexDeclaration>& shaderDecl)
 	{
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		VertexDeclarationKey pair;
 		pair.bufferDeclId = vbDecl->getId();
@@ -182,7 +182,7 @@ namespace bs { namespace ct
 		pair.bufferDeclId = vbDecl->getId();
 		pair.shaderDeclId = shaderInputDecl->getId();
 
-		Lock(mMutex);
+		Lock lock(mMutex);
 		newEntry.vertexInput = bs_shared_ptr_new<VulkanVertexInput>(mNextId++, vertexInputCI);
 		newEntry.lastUsedIdx = ++mLastUsedCounter;
 
@@ -191,7 +191,7 @@ namespace bs { namespace ct
 
 	void VulkanVertexInputManager::removeLeastUsed()
 	{
-		Lock(mMutex);
+		Lock lock(mMutex);
 
 		if (!mWarningShown)
 		{