Permalink
Browse files

jobmanager: add functions to pause job creation

useful for delaying all new job creation until later. As an example, we may
want to disable thumbnailing during video playback.

Not currently hooked up to anything.
  • Loading branch information...
1 parent f35cded commit a1eb6ba9a497006cd75003b01f2079a4e9d04f66 theuni committed Apr 9, 2012
Showing with 79 additions and 0 deletions.
  1. +45 −0 xbmc/utils/JobManager.cpp
  2. +34 −0 xbmc/utils/JobManager.h
View
@@ -239,6 +239,15 @@ CJob *CJobManager::PopJob()
if (m_jobQueue[priority].size() && m_processing.size() < GetMaxWorkers(CJob::PRIORITY(priority)))
{
CWorkItem job = m_jobQueue[priority].front();
+
+ // skip adding any paused types
+ if (priority <= CJob::PRIORITY_LOW)
+ {
+ std::vector<std::string>::iterator i = find(m_pausedTypes.begin(), m_pausedTypes.end(), job.m_job->GetType());
+ if (i != m_pausedTypes.end())
+ return NULL;
+ }
+
m_jobQueue[priority].pop_front();
// add to the processing vector
m_processing.push_back(job);
@@ -249,6 +258,42 @@ CJob *CJobManager::PopJob()
return NULL;
}
+void CJobManager::Pause(const std::string &pausedType)
+{
+ CSingleLock lock(m_section);
+ // just push it in so we get ref counting,
+ // the queue will resume when all Pause requests
+ // for a given type have been UnPaused.
+ m_pausedTypes.push_back(pausedType);
+}
+
+void CJobManager::UnPause(const std::string &pausedType)
+{
+ CSingleLock lock(m_section);
+ std::vector<std::string>::iterator i = find(m_pausedTypes.begin(), m_pausedTypes.end(), pausedType);
+ if (i != m_pausedTypes.end())
+ m_pausedTypes.erase(i);
+}
+
+bool CJobManager::IsPaused(const std::string &pausedType)
+{
+ CSingleLock lock(m_section);
+ std::vector<std::string>::iterator i = find(m_pausedTypes.begin(), m_pausedTypes.end(), pausedType);
+ return (i != m_pausedTypes.end());
+}
+
+int CJobManager::IsProcessing(const std::string &pausedType)
+{
+ int jobsMatched = 0;
+ CSingleLock lock(m_section);
+ for(Processing::iterator it = m_processing.begin(); it < m_processing.end(); it++)
+ {
+ if (pausedType == std::string(it->m_job->GetType()))
+ jobsMatched++;
+ }
+ return jobsMatched;
+}
+
CJob *CJobManager::GetNextJob(const CJobWorker *worker)
{
CSingleLock lock(m_section);
View
@@ -215,6 +215,39 @@ class CJobManager
*/
void CancelJobs();
+ /*!
+ \brief Suspends queueing of the specified type until unpaused
+ Useful to (for ex) stop queuing thumb jobs during video playback. Only affects PRIORITY_LOW or lower.
+ Does not affect currently processing jobs, use IsProcessing to see if any need to be waited on
+ Types accumulate, so more than one can be set at a time.
+ Refcounted, so UnPause() must be called once for each Pause().
+ \param pausedType only jobs of this type will be affected
+ \sa UnPause(), IsPaused(), IsProcessing()
+ */
+ void Pause(const std::string &pausedType);
+
+ /*!
+ \brief Resumes queueing of the specified type
+ \param pausedType only jobs of this type will be affected
+ \sa Pause(), IsPaused(), IsProcessing()
+ */
+ void UnPause(const std::string &pausedType);
+
+ /*!
+ \brief Checks if jobs of specified type are paused.
+ \param pausedType only jobs of this type will be affected
+ \sa Pause(), UnPause(), IsProcessing()
+ */
+ bool IsPaused(const std::string &pausedType);
+
+ /*!
+ \brief Checks to see if any jobs of a specific type are currently processing.
+ \param pausedType Job type to search for
+ \return Number of matching jobs
+ \sa Pause(), UnPause(), IsPaused()
+ */
+ int IsProcessing(const std::string &pausedType);
+
protected:
friend class CJobWorker;
friend class CJob;
@@ -275,4 +308,5 @@ class CJobManager
CCriticalSection m_section;
CEvent m_jobEvent;
bool m_running;
+ std::vector<std::string> m_pausedTypes;
};

0 comments on commit a1eb6ba

Please sign in to comment.