Krita Source Code Documentation
Loading...
Searching...
No Matches
KisTileDataSwapper Class Reference

#include <kis_tile_data_swapper.h>

+ Inheritance diagram for KisTileDataSwapper:

Public Member Functions

void checkFreeMemory ()
 
void kick ()
 
 KisTileDataSwapper (KisTileDataStore *store)
 
void terminateSwapper ()
 
void testingRereadConfig ()
 
 ~KisTileDataSwapper () override
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Public Attributes

QMutex cycleLock
 
KisStoreLimits limits
 
QSemaphore semaphore
 
QAtomicInt shouldExitFlag
 
KisTileDataStorestore
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Private Member Functions

void doJob ()
 
template<class strategy >
qint64 pass (qint64 needToFreeMetric)
 
void run () override
 
void waitForWork ()
 

Private Attributes

Private *const m_d
 

Static Private Attributes

static const qint32 DELAY = 0.7 * SEC
 
static const qint32 TIMEOUT = -1
 

Detailed Description

Definition at line 36 of file kis_tile_data_swapper.cpp.

Constructor & Destructor Documentation

◆ KisTileDataSwapper()

KisTileDataSwapper::KisTileDataSwapper ( KisTileDataStore * store)

Definition at line 46 of file kis_tile_data_swapper.cpp.

47 : QThread(),
48 m_d(new Private())
49{
50 m_d->shouldExitFlag = 0;
51 m_d->store = store;
52}

References m_d, and store.

◆ ~KisTileDataSwapper()

KisTileDataSwapper::~KisTileDataSwapper ( )
override

Definition at line 54 of file kis_tile_data_swapper.cpp.

55{
56 delete m_d;
57}

References m_d.

Member Function Documentation

◆ checkFreeMemory()

void KisTileDataSwapper::checkFreeMemory ( )

Definition at line 92 of file kis_tile_data_swapper.cpp.

93{
94// dbgKrita <<"check memory: high limit -" << m_d->limits.emergencyThreshold() <<"in mem -" << m_d->store->numTilesInMemory();
95 if(m_d->store->memoryMetric() > m_d->limits.emergencyThreshold())
96 doJob();
97}

References doJob(), and m_d.

◆ doJob()

void KisTileDataSwapper::doJob ( )
private

In emergency case usual threads have access to this function as well

Definition at line 99 of file kis_tile_data_swapper.cpp.

100{
105 QMutexLocker locker(&m_d->cycleLock);
106
107 qint32 memoryMetric = m_d->store->memoryMetric();
108
109 DEBUG_ACTION("Started swap cycle");
110 DEBUG_VALUE(m_d->store->numTiles());
111 DEBUG_VALUE(m_d->store->numTilesInMemory());
112 DEBUG_VALUE(memoryMetric);
113
114 DEBUG_VALUE(m_d->limits.softLimitThreshold());
115 DEBUG_VALUE(m_d->limits.hardLimitThreshold());
116
117
118 if(memoryMetric > m_d->limits.softLimitThreshold()) {
119 qint32 softFree = memoryMetric - m_d->limits.softLimit();
120 DEBUG_VALUE(softFree);
121 DEBUG_ACTION("\t pass0");
122 memoryMetric -= pass<SoftSwapStrategy>(softFree);
123 DEBUG_VALUE(memoryMetric);
124
125 if(memoryMetric > m_d->limits.hardLimitThreshold()) {
126 qint32 hardFree = memoryMetric - m_d->limits.hardLimit();
127 DEBUG_VALUE(hardFree);
128 DEBUG_ACTION("\t pass1");
129 memoryMetric -= pass<AggressiveSwapStrategy>(hardFree);
130 DEBUG_VALUE(memoryMetric);
131 }
132 }
133}
#define DEBUG_VALUE(value)
#define DEBUG_ACTION(action)

References DEBUG_ACTION, DEBUG_VALUE, and m_d.

◆ kick()

void KisTileDataSwapper::kick ( )

Definition at line 59 of file kis_tile_data_swapper.cpp.

60{
61 m_d->semaphore.release();
62}

References m_d.

◆ pass()

template<class strategy >
qint64 KisTileDataSwapper::pass ( qint64 needToFreeMetric)
private

Definition at line 185 of file kis_tile_data_swapper.cpp.

186{
187 qint64 freedMetric = 0;
188 QList<KisTileData*> additionalCandidates;
189
190 typename strategy::iterator *iter =
191 strategy::beginIteration(m_d->store);
192
193 KisTileData *item = 0;
194
195 while (iter->hasNext()) {
196 item = iter->next();
197
198 if (freedMetric >= needToFreeMetric) break;
199
200 if (!strategy::isInteresting(item)) continue;
201
202 if (strategy::swapOutFirst(item)) {
203 if (iter->trySwapOut(item)) {
204 freedMetric += item->pixelSize();
205 }
206 }
207 else {
208 item->markOld();
209 additionalCandidates.append(item);
210 }
211
212 }
213
214 Q_FOREACH (item, additionalCandidates) {
215 if (freedMetric >= needToFreeMetric) break;
216
217 if (iter->trySwapOut(item)) {
218 freedMetric += item->pixelSize();
219 }
220 }
221
222 strategy::endIteration(m_d->store, iter);
223
224 return freedMetric;
225}
quint32 pixelSize() const

References m_d, KisTileData::markOld(), and KisTileData::pixelSize().

◆ run()

void KisTileDataSwapper::run ( )
overrideprivate

Definition at line 78 of file kis_tile_data_swapper.cpp.

79{
80 while (1) {
82
83 if (m_d->shouldExitFlag)
84 return;
85
86 QThread::msleep(DELAY);
87
88 doJob();
89 }
90}
static const qint32 DELAY

References DELAY, doJob(), m_d, and waitForWork().

◆ terminateSwapper()

void KisTileDataSwapper::terminateSwapper ( )

Definition at line 64 of file kis_tile_data_swapper.cpp.

65{
66 unsigned long exitTimeout = 100;
67 do {
68 m_d->shouldExitFlag = true;
69 kick();
70 } while(!wait(exitTimeout));
71}

References kick(), and m_d.

◆ testingRereadConfig()

void KisTileDataSwapper::testingRereadConfig ( )

Definition at line 227 of file kis_tile_data_swapper.cpp.

228{
229 m_d->limits = KisStoreLimits();
230}

References m_d.

◆ waitForWork()

void KisTileDataSwapper::waitForWork ( )
private

Definition at line 73 of file kis_tile_data_swapper.cpp.

74{
75 m_d->semaphore.tryAcquire(1, TIMEOUT);
76}
static const qint32 TIMEOUT

References m_d, and TIMEOUT.

Member Data Documentation

◆ cycleLock

QMutex KisTileDataSwapper::cycleLock

Definition at line 43 of file kis_tile_data_swapper.cpp.

◆ DELAY

const qint32 KisTileDataSwapper::DELAY = 0.7 * SEC
staticprivate

Definition at line 42 of file kis_tile_data_swapper.h.

◆ limits

KisStoreLimits KisTileDataSwapper::limits

Definition at line 42 of file kis_tile_data_swapper.cpp.

◆ m_d

Private* const KisTileDataSwapper::m_d
private

Definition at line 46 of file kis_tile_data_swapper.h.

◆ semaphore

QSemaphore KisTileDataSwapper::semaphore

Definition at line 39 of file kis_tile_data_swapper.cpp.

◆ shouldExitFlag

QAtomicInt KisTileDataSwapper::shouldExitFlag

Definition at line 40 of file kis_tile_data_swapper.cpp.

◆ store

KisTileDataStore* KisTileDataSwapper::store

Definition at line 41 of file kis_tile_data_swapper.cpp.

◆ TIMEOUT

const qint32 KisTileDataSwapper::TIMEOUT = -1
staticprivate

Definition at line 41 of file kis_tile_data_swapper.h.


The documentation for this class was generated from the following files: