diff options
author | Jonathan Marshall <jmarshall@never.you.mind> | 2012-05-25 22:38:15 +1200 |
---|---|---|
committer | Jonathan Marshall <jmarshall@never.you.mind> | 2012-05-26 15:54:39 +1200 |
commit | b1d686dae222ff452a6db2c9d7132b4152511054 (patch) | |
tree | 3f7bffc1c89eaa81b858eb78ba0d92aecb089050 | |
parent | 23aa0ab7cbb2bd6b39e8e194c2b25f4944e8ffdd (diff) |
Increment texture use counts in a separate job to ensure it's done off-thread
-rw-r--r-- | xbmc/TextureCache.cpp | 13 | ||||
-rw-r--r-- | xbmc/TextureCache.h | 11 | ||||
-rw-r--r-- | xbmc/TextureCacheJob.cpp | 28 | ||||
-rw-r--r-- | xbmc/TextureCacheJob.h | 21 |
4 files changed, 65 insertions, 8 deletions
diff --git a/xbmc/TextureCache.cpp b/xbmc/TextureCache.cpp index 1c8fa0cef1..ab04ea8ced 100644 --- a/xbmc/TextureCache.cpp +++ b/xbmc/TextureCache.cpp @@ -217,10 +217,17 @@ bool CTextureCache::AddCachedTexture(const CStdString &url, const CTextureDetail return m_database.AddCachedTexture(url, details); } -bool CTextureCache::IncrementUseCount(const CTextureDetails &details) +void CTextureCache::IncrementUseCount(const CTextureDetails &details) { - CSingleLock lock(m_databaseSection); - return m_database.IncrementUseCount(details); + static const size_t count_before_update = 100; + CSingleLock lock(m_useCountSection); + m_useCounts.reserve(count_before_update); + m_useCounts.push_back(details); + if (m_useCounts.size() >= count_before_update) + { + AddJob(new CTextureUseCountJob(m_useCounts)); + m_useCounts.clear(); + } } bool CTextureCache::SetCachedTextureValid(const CStdString &url, bool updateable) diff --git a/xbmc/TextureCache.h b/xbmc/TextureCache.h index 3115033fae..0ccb78956f 100644 --- a/xbmc/TextureCache.h +++ b/xbmc/TextureCache.h @@ -186,12 +186,11 @@ private: */ bool ClearCachedTexture(const CStdString &url, CStdString &cacheFile); - /*! \brief Increment the use count of a texture in the database - Thread-safe wrapper of CTextureDatabase::IncrementUseCount - \param details the texture to increment the use count - \return true on success, false otherwise + /*! \brief Increment the use count of a texture + Stores locally before calling CTextureDatabase::IncrementUseCount via a CUseCountJob + \sa CUseCountJob, CTextureDatabase::IncrementUseCount */ - bool IncrementUseCount(const CTextureDetails &details); + void IncrementUseCount(const CTextureDetails &details); /*! \brief Set a previously cached texture as valid in the database Thread-safe wrapper of CTextureDatabase::SetCachedTextureValid @@ -209,5 +208,7 @@ private: std::set<CStdString> m_processing; ///< currently processing list to avoid 2 jobs being processed at once CCriticalSection m_processingSection; CEvent m_completeEvent; ///< Set whenever a job has finished + std::vector<CTextureDetails> m_useCounts; ///< Use count tracking + CCriticalSection m_useCountSection; }; diff --git a/xbmc/TextureCacheJob.cpp b/xbmc/TextureCacheJob.cpp index d24fcc2b43..24b873dcf8 100644 --- a/xbmc/TextureCacheJob.cpp +++ b/xbmc/TextureCacheJob.cpp @@ -247,3 +247,31 @@ bool CTextureDDSJob::DoWork() } return false; } + +CTextureUseCountJob::CTextureUseCountJob(const std::vector<CTextureDetails> &textures) : m_textures(textures) +{ +} + +bool CTextureUseCountJob::operator==(const CJob* job) const +{ + if (strcmp(job->GetType(),GetType()) == 0) + { + const CTextureUseCountJob* useJob = dynamic_cast<const CTextureUseCountJob*>(job); + if (useJob && useJob->m_textures == m_textures) + return true; + } + return false; +} + +bool CTextureUseCountJob::DoWork() +{ + CTextureDatabase db; + if (db.Open()) + { + db.BeginTransaction(); + for (std::vector<CTextureDetails>::const_iterator i = m_textures.begin(); i != m_textures.end(); ++i) + db.IncrementUseCount(*i); + db.CommitTransaction(); + } + return true; +} diff --git a/xbmc/TextureCacheJob.h b/xbmc/TextureCacheJob.h index f342dbe3ac..c40561007e 100644 --- a/xbmc/TextureCacheJob.h +++ b/xbmc/TextureCacheJob.h @@ -39,6 +39,12 @@ public: width = height = 0; updateable = false; }; + bool operator==(const CTextureDetails &right) const + { + return (id == right.id && + file == right.file && + width == right.width ); + }; int id; std::string file; std::string hash; @@ -128,3 +134,18 @@ public: CStdString m_original; }; + +/* \brief Job class for storing the use count of textures + */ +class CTextureUseCountJob : public CJob +{ +public: + CTextureUseCountJob(const std::vector<CTextureDetails> &textures); + + virtual const char* GetType() const { return "usecount"; }; + virtual bool operator==(const CJob *job) const; + virtual bool DoWork(); + +private: + std::vector<CTextureDetails> m_textures; +}; |