Use a correct method to detect last queue texture

This commit is contained in:
Benau 2017-03-12 15:03:02 +08:00
parent 27fcc4e266
commit 498ce3ebc9
3 changed files with 11 additions and 6 deletions

View File

@ -366,13 +366,13 @@ void STKTexManager::checkThreadedLoadTextures(bool util_queue_empty)
{ {
for (ThreadedTexLoader* ttl : m_all_tex_loaders) for (ThreadedTexLoader* ttl : m_all_tex_loaders)
{ {
ttl->lock(); if (ttl->lastQueueReady())
if (ttl->hasCompletedTextures())
{ {
ttl->lock();
ttl->setFinishLoading(); ttl->setFinishLoading();
uploaded = true; uploaded = true;
ttl->unlock(false/*finish_it*/);
} }
ttl->unlock(false/*finish_it*/);
} }
break; break;
} }

View File

@ -33,6 +33,7 @@ void* ThreadedTexLoader::startRoutine(void *obj)
{ {
pthread_mutex_lock(&ttl->m_mutex); pthread_mutex_lock(&ttl->m_mutex);
bool finished = ttl->finishedLoading(); bool finished = ttl->finishedLoading();
bool has_completed_tex = !ttl->m_completed_textures.empty();
pthread_mutex_unlock(&ttl->m_mutex); pthread_mutex_unlock(&ttl->m_mutex);
if (finished) if (finished)
{ {
@ -40,6 +41,7 @@ void* ThreadedTexLoader::startRoutine(void *obj)
} }
pthread_mutex_lock(ttl->m_texture_queue_mutex); pthread_mutex_lock(ttl->m_texture_queue_mutex);
bool waiting = ttl->m_stktm->isThreadedLoadTexturesEmpty(); bool waiting = ttl->m_stktm->isThreadedLoadTexturesEmpty();
ttl->m_last_queue_ready.setAtomic(has_completed_tex && waiting);
while (waiting) while (waiting)
{ {
pthread_cond_wait(ttl->m_cond_request, ttl->m_texture_queue_mutex); pthread_cond_wait(ttl->m_cond_request, ttl->m_texture_queue_mutex);

View File

@ -20,9 +20,9 @@
#include "utils/can_be_deleted.hpp" #include "utils/can_be_deleted.hpp"
#include "utils/no_copy.hpp" #include "utils/no_copy.hpp"
#include "utils/synchronised.hpp"
#include "utils/types.hpp" #include "utils/types.hpp"
#include <pthread.h>
#include <vector> #include <vector>
namespace irr namespace irr
@ -54,6 +54,8 @@ private:
bool m_finished_loading, m_locked; bool m_finished_loading, m_locked;
Synchronised<bool> m_last_queue_ready;
std::vector<irr::video::ITexture*> m_completed_textures; std::vector<irr::video::ITexture*> m_completed_textures;
public: public:
@ -67,7 +69,7 @@ public:
m_pbo_ptr(pbo_ptr), m_texture_queue_mutex(mutex), m_pbo_ptr(pbo_ptr), m_texture_queue_mutex(mutex),
m_cond_request(cond), m_stktm(stktm), m_cond_request(cond), m_stktm(stktm),
m_tex_size_loaded(0), m_finished_loading(false), m_tex_size_loaded(0), m_finished_loading(false),
m_locked(false) m_locked(false), m_last_queue_ready(false)
{ {
pthread_mutex_init(&m_mutex, NULL); pthread_mutex_init(&m_mutex, NULL);
pthread_create(&m_thread, NULL, &startRoutine, this); pthread_create(&m_thread, NULL, &startRoutine, this);
@ -83,11 +85,12 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void setFinishLoading() void setFinishLoading()
{ {
m_last_queue_ready.setAtomic(false);
m_finished_loading = true; m_finished_loading = true;
m_tex_size_loaded = 0; m_tex_size_loaded = 0;
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
bool hasCompletedTextures() const { return !m_completed_textures.empty(); } bool lastQueueReady() const { return m_last_queue_ready.getAtomic(); }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void handleCompletedTextures(); void handleCompletedTextures();
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------