|
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 | isIdle () const |
| 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 320 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 283 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 288 of file kis_updater_context.cpp.
References KisUpdateScheduler::doSomeUsefulWork(), and m_scheduler.
|
protected |
Definition at line 238 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 315 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::isIdle | ( | ) | const |
Returns true if there are no jobs running in the context
If there is any contestion on the context's mutex, the function will simply return false, whatever context's state really is. Obviously, if there is a contention, the object is not "idle" :)
Definition at line 218 of file kis_updater_context.cpp.
References m_numRunningThreads, and m_runningThreadsMutex.
| 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 293 of file kis_updater_context.cpp.
References m_lodCounter, m_scheduler, KisLockFreeLodCounter::removeLod(), and KisUpdateScheduler::spareThreadAppeared().
| void KisUpdaterContext::jobThreadExited | ( | ) |
Definition at line 299 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 247 of file kis_updater_context.cpp.
References m_lock.
| void KisUpdaterContext::setTestingMode | ( | bool | value | ) |
Definition at line 310 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 257 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 277 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 252 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 226 of file kis_updater_context.cpp.
References KisBaseRectsWalker::accessRect(), and KisUpdateJobItem::accessRect().
|
friend |
Definition at line 175 of file kis_updater_context.h.
|
friend |
Definition at line 174 of file kis_updater_context.h.
|
friend |
Definition at line 176 of file kis_updater_context.h.
|
friend |
Definition at line 172 of file kis_updater_context.h.
|
friend |
Definition at line 173 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 158 of file kis_updater_context.h.
|
protected |
Definition at line 164 of file kis_updater_context.h.
|
protected |
Definition at line 160 of file kis_updater_context.h.
|
protected |
Definition at line 166 of file kis_updater_context.h.
|
protected |
Definition at line 162 of file kis_updater_context.h.
|
mutableprotected |
Definition at line 161 of file kis_updater_context.h.
|
protected |
Definition at line 167 of file kis_updater_context.h.
|
protected |
Definition at line 168 of file kis_updater_context.h.
|
protected |
Definition at line 165 of file kis_updater_context.h.
|
protected |
Definition at line 163 of file kis_updater_context.h.
|
static |
Definition at line 30 of file kis_updater_context.h.