Browse Source

Fixed threading issues on shutdown in TaskScheduler (I think)
Removed resource unloads from Main as they're automatic now

Marko Pintera 11 years ago
parent
commit
615bc66f11

+ 1 - 1
BansheeUtility/Include/BsTaskScheduler.h

@@ -125,7 +125,7 @@ namespace BansheeEngine
 		/**
 		 * @brief	Worker method that runs a single task.
 		 */
-		void runTask(const TaskPtr& task);
+		void runTask(TaskPtr task);
 
 		/**
 		 * @brief	Blocks the calling thread until the specified task has completed.

+ 2 - 1
BansheeUtility/Include/BsThreadPool.h

@@ -47,7 +47,7 @@ namespace BansheeEngine
 		 * @note	Caller must ensure worker method is not null and that the thread
 		 * 			is currently idle, otherwise undefined behavior will occur.
 		 */
-		void start(std::function<void()> workerMethod);
+		void start(std::function<void()> workerMethod, UINT32 id);
 
 		/**
 		 * @brief	Attempts to join the currently running thread and destroys it. Caller must ensure
@@ -233,6 +233,7 @@ namespace BansheeEngine
 		UINT32 mIdleTimeout;
 		UINT32 mAge;
 		
+		std::atomic_uint mUniqueId;
 		BS_MUTEX(mMutex);
 	};
 

+ 1 - 1
BansheeUtility/Source/BsTaskScheduler.cpp

@@ -137,7 +137,7 @@ namespace BansheeEngine
 		}
 	}
 
-	void TaskScheduler::runTask(const TaskPtr& task)
+	void TaskScheduler::runTask(TaskPtr task)
 	{
 		task->mTaskWorker();
 

+ 6 - 3
BansheeUtility/Source/BsThreadPool.cpp

@@ -20,7 +20,10 @@ namespace BansheeEngine
 			for (auto& thread : mPool->mThreads)
 			{
 				if (thread->getId() == mThreadId)
+				{
 					parentThread = thread;
+					break;
+				}
 			}
 		}
 
@@ -55,7 +58,7 @@ namespace BansheeEngine
 			BS_THREAD_WAIT(mStartedCond, mMutex, lock);
 	}
 
-	void PooledThread::start(std::function<void()> workerMethod)
+	void PooledThread::start(std::function<void()> workerMethod, UINT32 id)
 	{
 		{
 			BS_LOCK_MUTEX(mMutex);
@@ -64,7 +67,7 @@ namespace BansheeEngine
 			mIdle = false;
 			mIdleTime = std::time(nullptr);
 			mThreadReady = true;
-			mId++;
+			mId = id;
 		}
 
 		BS_THREAD_NOTIFY_ONE(mReadyCond);
@@ -167,7 +170,7 @@ namespace BansheeEngine
 	HThread ThreadPool::run(const String& name, std::function<void()> workerMethod)
 	{
 		PooledThread* thread = getThread(name);
-		thread->start(workerMethod);
+		thread->start(workerMethod, mUniqueId++);
 
 		return HThread(this, thread->getId());
 	}

+ 0 - 25
ExampleProject/Main/Main.cpp

@@ -43,11 +43,6 @@ namespace BansheeEngine
 	 */
 	void setUpExample();
 
-	/**
-	 * Releases all resources and prepares the example fur shutdown.
-	 */
-	void shutDownExample();
-
 	/**
 	 * Toggles the primary window between full-screen and windowed mode.
 	 */
@@ -100,9 +95,6 @@ int CALLBACK WinMain(
 	// window or exits in some other way.
 	Application::instance().runMainLoop();
 
-	// Perform cleanup
-	shutDownExample();
-
 	Application::shutDown();
 
 	return 0;
@@ -452,23 +444,6 @@ namespace BansheeEngine
 		videoModeListBox->onSelectionChanged.connect(&videoModeChanged);
 	}
 
-	void shutDownExample()
-	{
-		// We require all handles to be released before shutdown.
-		gResources().unload(exampleModel);
-		gResources().unload(exampleTexture);
-		gResources().unload(exampleFragmentGPUProg);
-		gResources().unload(exampleVertexGPUProg);
-
-		exampleModel = nullptr;
-		exampleTexture = nullptr;
-		exampleFragmentGPUProg = nullptr;
-		exampleVertexGPUProg = nullptr;
-
-		sceneCamera = nullptr;
-		profilerOverlay = nullptr;
-	}
-
 	void toggleFullscreen()
 	{
 		RenderWindowPtr window = gApplication().getPrimaryWindow();