Просмотр исходного кода

Making blockUntilComplete an internal method

Marko Pintera 11 лет назад
Родитель
Сommit
4667ba6cc9

+ 5 - 2
BansheeUtility/Include/BsAsyncOp.h

@@ -87,10 +87,13 @@ namespace BansheeEngine
 		/**
 		 * @brief	Blocks the caller thread until the AsyncOp completes.
 		 *
-		 * @note	Do not call this on the thread that is completing the async op, as it
+		 * @note	Internal method.
+		 *			Do not call this on the thread that is completing the async op, as it
 		 *			will cause a deadlock.
+		 *			Make sure the command you are waiting for is actually queued for execution
+		 *			because a deadlock will occurr otherwise.
 		 */
-		void blockUntilComplete() const;
+		void _blockUntilComplete() const;
 
 		/**
 		 * @brief	Retrieves the value returned by the async operation. Only valid

+ 1 - 1
BansheeUtility/Source/BsAsyncOp.cpp

@@ -25,7 +25,7 @@ namespace BansheeEngine
 			BS_THREAD_NOTIFY_ALL(mSyncData->mCondition);
 	}
 
-	void AsyncOp::blockUntilComplete() const
+	void AsyncOp::_blockUntilComplete() const
 	{
 		if (mSyncData == nullptr)
 		{

+ 7 - 1
SBansheeEngine/Source/BsScriptAsyncOp.cpp

@@ -58,6 +58,12 @@ namespace BansheeEngine
 
 	void ScriptAsyncOp::internal_blockUntilComplete(ScriptAsyncOp* thisPtr)
 	{
-		thisPtr->mAsyncOp.blockUntilComplete();
+		if (!thisPtr->mAsyncOp.hasCompleted())
+		{
+			// Note: Assuming the AsyncOp was queued via accessor. This will deadlock
+			// if it wasn't.
+			gCoreThread().getAccessor()->submitToCoreThread();
+			thisPtr->mAsyncOp._blockUntilComplete();
+		}
 	}
 }