|
Krita Source Code Documentation
|
#include <kis_updater_context.h>
Inheritance diagram for KisUpdaterContext:Public Member Functions | |
| void | addMergeJob (KisBaseRectsWalkerSP walker) |
| void | addSpontaneousJob (KisSpontaneousJob *spontaneousJob) |
| void | addStrokeJob (KisStrokeJob *strokeJob) |
| void | continueUpdate (const QRect &rc) |
| int | currentLevelOfDetail () const |
| void | doSomeUsefulWork () |
| KisUpdaterContextSnapshotEx | getContextSnapshotEx () const |
| void | getJobsSnapshot (qint32 &numMergeJobs, qint32 &numStrokeJobs) |
| bool | hasSpareThread () |
| bool | isJobAllowed (KisBaseRectsWalkerSP walker) |
| void | jobFinished () |
| void | jobThreadExited () |
| KisUpdaterContext (qint32 threadCount=useIdealThreadCountTag, KisUpdateScheduler *parent=0) | |
| void | lock () |
| void | setTestingMode (bool value) |
| void | setThreadsLimit (int value) |
| int | threadsLimit () const |
| void | unlock () |
| void | waitForDone () |
| ~KisUpdaterContext () | |
Static Public Attributes | |
| static const int | useIdealThreadCountTag = -1 |
Protected Member Functions | |
| qint32 | findSpareThread () |
Static Protected Member Functions | |
| static bool | walkerIntersectsJob (KisBaseRectsWalkerSP walker, const KisUpdateJobItem *job) |
Protected Attributes | |
| QReadWriteLock | m_exclusiveJobLock |
| QVector< KisUpdateJobItem * > | m_jobs |
| QMutex | m_lock |
| KisLockFreeLodCounter | m_lodCounter |
| int | m_numRunningThreads = 0 |
| QMutex | m_runningThreadsMutex |
| KisUpdateScheduler * | m_scheduler |
| bool | m_testingMode = false |
| QThreadPool | m_threadPool |
| QWaitCondition | m_waitForDoneCondition |
Private Member Functions | |
| void | clear () |
| const QVector< KisUpdateJobItem * > | getJobs () |
| void | startThread (int index) |
Friends | |
| class | KisSimpleUpdateQueueTest |
| class | KisStrokesQueueTest |
| class | KisUpdateJobItem |
| class | KisUpdaterContextTest |
| class | KisUpdateSchedulerTest |
Definition at line 27 of file kis_updater_context.h.
| KisUpdaterContext::KisUpdaterContext | ( | qint32 | threadCount = useIdealThreadCountTag, |
| KisUpdateScheduler * | parent = 0 ) |
Definition at line 18 of file kis_updater_context.cpp.
References setThreadsLimit().
| KisUpdaterContext::~KisUpdaterContext | ( | ) |
Definition at line 29 of file kis_updater_context.cpp.
References clear(), m_jobs, m_testingMode, and m_threadPool.
| void KisUpdaterContext::addMergeJob | ( | KisBaseRectsWalkerSP | walker | ) |
Registers the job and starts executing it. The caller must ensure that the context is locked with lock(), job is allowed with isWalkerAllowed() and there is a spare thread for running it with hasSpareThread()
NOTE: In theory, isJobAllowed() and addMergeJob() should be merged into one atomic method like bool push(), because this implementation of KisUpdaterContext will not work in case of multiple producers. But currently we have only one producer (one thread in a time), that is guaranteed by the lock()/unlock() pair in KisAbstractUpdateQueue::processQueue.
Definition at line 164 of file kis_updater_context.cpp.
References KisLockFreeLodCounter::addLod(), findSpareThread(), KisBaseRectsWalker::levelOfDetail(), m_jobs, m_lodCounter, m_testingMode, and startThread().
| void KisUpdaterContext::addSpontaneousJob | ( | KisSpontaneousJob * | spontaneousJob | ) |
Adds a spontaneous job to the context. The prerequisites are the same as for addMergeJob()
Definition at line 194 of file kis_updater_context.cpp.
References KisLockFreeLodCounter::addLod(), findSpareThread(), KisSpontaneousJob::levelOfDetail(), m_jobs, m_lodCounter, m_testingMode, and startThread().
| void KisUpdaterContext::addStrokeJob | ( | KisStrokeJob * | strokeJob | ) |
Adds a stroke job to the context. The prerequisites are the same as for addMergeJob()
Definition at line 179 of file kis_updater_context.cpp.
References KisLockFreeLodCounter::addLod(), findSpareThread(), KisStrokeJob::levelOfDetail(), m_jobs, m_lodCounter, m_testingMode, and startThread().
|
private |
Definition at line 312 of file kis_updater_context.cpp.
References m_jobs, m_lodCounter, KisLockFreeLodCounter::testingClear(), and KisUpdateJobItem::testingSetDone().
| void KisUpdaterContext::continueUpdate | ( | const QRect & | rc | ) |
Definition at line 275 of file kis_updater_context.cpp.
References KisUpdateScheduler::continueUpdate(), and m_scheduler.
| int KisUpdaterContext::currentLevelOfDetail | ( | ) | const |
Returns the current level of detail of all the running jobs in the context. If there are no jobs, returns -1.
Definition at line 99 of file kis_updater_context.cpp.
References m_lodCounter, and KisLockFreeLodCounter::readLod().
| void KisUpdaterContext::doSomeUsefulWork | ( | ) |
Definition at line 280 of file kis_updater_context.cpp.
References KisUpdateScheduler::doSomeUsefulWork(), and m_scheduler.
|
protected |
Definition at line 230 of file kis_updater_context.cpp.
References m_jobs.
| KisUpdaterContextSnapshotEx KisUpdaterContext::getContextSnapshotEx | ( | ) | const |
We cannot use Q_FOREACH here since the function may be called concurrently without any locks, causing detaching of the vector and causing a crash. Only read-only accesses are allowed in such environment
Definition at line 64 of file kis_updater_context.cpp.
References KisStrokeJobData::BARRIER, KisStrokeJobData::CONCURRENT, ContextEmpty, HasBarrierJob, HasConcurrentJob, HasMergeJob, HasSequentialJob, HasUniquelyConcurrentJob, m_jobs, KisUpdateJobItem::MERGE, KisStrokeJobData::SEQUENTIAL, KisUpdateJobItem::SPONTANEOUS, KisUpdateJobItem::STROKE, and KisStrokeJobData::UNIQUELY_CONCURRENT.
|
private |
Definition at line 307 of file kis_updater_context.cpp.
References m_jobs.
| void KisUpdaterContext::getJobsSnapshot | ( | qint32 & | numMergeJobs, |
| qint32 & | numStrokeJobs ) |
Returns the number of currently running jobs of each type. To use this information you should lock the context beforehand.
We cannot use Q_FOREACH here since the function may be called concurrently without any locks, causing detaching of the vector and causing a crash. Only read-only accesses are allowed in such environment
Definition at line 40 of file kis_updater_context.cpp.
References m_jobs, KisUpdateJobItem::MERGE, KisUpdateJobItem::SPONTANEOUS, and KisUpdateJobItem::STROKE.
| bool KisUpdaterContext::hasSpareThread | ( | ) |
Check whether there is a spare thread for running one more job
We cannot use Q_FOREACH here since the function may be called concurrently without any locks, causing detaching of the vector and causing a crash. Only read-only accesses are allowed in such environment
Definition at line 104 of file kis_updater_context.cpp.
References m_jobs.
| bool KisUpdaterContext::isJobAllowed | ( | KisBaseRectsWalkerSP | walker | ) |
Checks whether the walker intersects with any of currently executing walkers. If it does, it is not allowed to go in. It should be called with the lock held.
We cannot use Q_FOREACH here since the function may be called concurrently without any locks, causing detaching of the vector and causing a crash. Only read-only accesses are allowed in such environment
Definition at line 123 of file kis_updater_context.cpp.
References currentLevelOfDetail(), KisBaseRectsWalker::levelOfDetail(), m_jobs, and walkerIntersectsJob().
| void KisUpdaterContext::jobFinished | ( | ) |
Definition at line 285 of file kis_updater_context.cpp.
References m_lodCounter, m_scheduler, KisLockFreeLodCounter::removeLod(), and KisUpdateScheduler::spareThreadAppeared().
| void KisUpdaterContext::jobThreadExited | ( | ) |
Definition at line 291 of file kis_updater_context.cpp.
References KIS_SAFE_ASSERT_RECOVER_NOOP, m_numRunningThreads, m_runningThreadsMutex, and m_waitForDoneCondition.
| void KisUpdaterContext::lock | ( | ) |
Locks the context to guarantee an exclusive access to the context
Definition at line 239 of file kis_updater_context.cpp.
References m_lock.
| void KisUpdaterContext::setTestingMode | ( | bool | value | ) |
Definition at line 302 of file kis_updater_context.cpp.
References m_testingMode, and value().
| void KisUpdaterContext::setThreadsLimit | ( | int | value | ) |
Set the number of threads available for this updater context WARNING: one cannot change the number of threads if there is at least one job running in the context! So before calling this method make sure you do two things: 1) barrierLock() the update scheduler 2) lock() the context
Definition at line 249 of file kis_updater_context.cpp.
References KIS_SAFE_ASSERT_RECOVER_RETURN, KisUpdateJobItem, m_jobs, m_threadPool, and value().
|
private |
Definition at line 146 of file kis_updater_context.cpp.
References m_jobs, m_numRunningThreads, m_runningThreadsMutex, and m_threadPool.
| int KisUpdaterContext::threadsLimit | ( | ) | const |
Return the number of available threads in the context. Make sure you lock the context before calling this function!
Definition at line 269 of file kis_updater_context.cpp.
References KIS_SAFE_ASSERT_RECOVER_NOOP, m_jobs, and m_threadPool.
| void KisUpdaterContext::unlock | ( | ) |
Unlocks the context
Definition at line 244 of file kis_updater_context.cpp.
References m_lock.
| void KisUpdaterContext::waitForDone | ( | ) |
Block execution of the caller until all the jobs are finished
Definition at line 209 of file kis_updater_context.cpp.
References m_numRunningThreads, m_runningThreadsMutex, and m_waitForDoneCondition.
|
staticprotected |
TODO: theoretically, we should compare rects intersection on a per-layer basis. The current solution is too rough and basically makes updates single-threaded in some cases (e.g. when a transform mask is present in the stack)
Definition at line 218 of file kis_updater_context.cpp.
References KisBaseRectsWalker::accessRect(), and KisUpdateJobItem::accessRect().
|
friend |
Definition at line 166 of file kis_updater_context.h.
|
friend |
Definition at line 165 of file kis_updater_context.h.
|
friend |
Definition at line 167 of file kis_updater_context.h.
|
friend |
Definition at line 163 of file kis_updater_context.h.
|
friend |
Definition at line 164 of file kis_updater_context.h.
|
protected |
The lock is shared by all the child update job items. When an item wants to run a usual (non-exclusive) job, it locks the lock for read access. When an exclusive access is requested, it locks it for write
Definition at line 149 of file kis_updater_context.h.
|
protected |
Definition at line 155 of file kis_updater_context.h.
|
protected |
Definition at line 151 of file kis_updater_context.h.
|
protected |
Definition at line 157 of file kis_updater_context.h.
|
protected |
Definition at line 153 of file kis_updater_context.h.
|
protected |
Definition at line 152 of file kis_updater_context.h.
|
protected |
Definition at line 158 of file kis_updater_context.h.
|
protected |
Definition at line 159 of file kis_updater_context.h.
|
protected |
Definition at line 156 of file kis_updater_context.h.
|
protected |
Definition at line 154 of file kis_updater_context.h.
|
static |
Definition at line 30 of file kis_updater_context.h.