Przeglądaj źródła

Add a variable to control bakground thread execution

Daniele Bartolini 12 lat temu
rodzic
commit
7c65157b10
2 zmienionych plików z 6 dodań i 1 usunięć
  1. 5 1
      src/ResourceManager.cpp
  2. 1 0
      src/ResourceManager.h

+ 5 - 1
src/ResourceManager.cpp

@@ -45,6 +45,7 @@ ResourceManager::ResourceManager(ResourceArchive& archive, Allocator& allocator)
 	m_resources(m_allocator),
 	m_loading_queue(m_allocator),
 	m_loaded_queue(m_allocator),
+	m_background_thread_should_run(true),
 	m_thread(ResourceManager::background_thread, (void*)this, "resource-loader-thread")
 {
 }
@@ -52,6 +53,7 @@ ResourceManager::ResourceManager(ResourceArchive& archive, Allocator& allocator)
 //-----------------------------------------------------------------------------
 ResourceManager::~ResourceManager()
 {
+	m_background_thread_should_run = false;
 }
 
 //-----------------------------------------------------------------------------
@@ -282,7 +284,7 @@ ResourceId ResourceManager::load(uint32_t name, uint32_t type)
 //-----------------------------------------------------------------------------
 void ResourceManager::background_load()
 {
-	while (true)
+	while (m_background_thread_should_run)
 	{
 		m_loading_mutex.lock();
 		while (m_loading_queue.size() == 0)
@@ -383,6 +385,8 @@ void* ResourceManager::background_thread(void* thiz)
 	ResourceManager* mgr = (ResourceManager*)thiz;
 
 	mgr->background_load();
+
+	return NULL;
 }
 
 } // namespace crown

+ 1 - 0
src/ResourceManager.h

@@ -158,6 +158,7 @@ private:
 	Queue<LoadedResource>	m_loaded_queue;
 
 	// Background loading thread
+	bool 					m_background_thread_should_run;
 	Thread					m_thread;
 
 	mutable Mutex			m_loading_mutex;