Krita Source Code Documentation
Loading...
Searching...
No Matches
KisLockFreeCacheWithModeConsistency< T, Mode > Class Template Referenceabstract

#include <kis_lock_free_cache.h>

Public Member Functions

getValue (Mode mode) const
 
void invalidate ()
 
bool tryGetValue (T &result, Mode mode) const
 
virtual ~KisLockFreeCacheWithModeConsistency ()
 

Protected Member Functions

virtual T calculateNewValue () const =0
 

Private Attributes

Mode m_mode
 
KisCacheStateValue m_state
 
m_value
 

Detailed Description

template<typename T, typename Mode>
class KisLockFreeCacheWithModeConsistency< T, Mode >

Definition at line 165 of file kis_lock_free_cache.h.

Constructor & Destructor Documentation

◆ ~KisLockFreeCacheWithModeConsistency()

template<typename T , typename Mode >
virtual KisLockFreeCacheWithModeConsistency< T, Mode >::~KisLockFreeCacheWithModeConsistency ( )
inlinevirtual

Definition at line 168 of file kis_lock_free_cache.h.

169 {
170 }

Member Function Documentation

◆ calculateNewValue()

template<typename T , typename Mode >
virtual T KisLockFreeCacheWithModeConsistency< T, Mode >::calculateNewValue ( ) const
protectedpure virtual

Calculate the value. Used by the cache internally. Reimplemented by the user.

Implemented in KisPaintDeviceCache::ExactBoundsCache, KisPaintDeviceCache::NonDefaultPixelCache, and KisPaintDeviceCache::RegionCache.

◆ getValue()

template<typename T , typename Mode >
T KisLockFreeCacheWithModeConsistency< T, Mode >::getValue ( Mode mode) const
inline

Calculate the value or fetch it from the cache

Definition at line 182 of file kis_lock_free_cache.h.

182 {
184 bool isValid = false;
185 T savedValue;
186 Mode savedMode;
187
188 if (m_state.startRead(&seqValue)) {
189 savedValue = m_value;
190 savedMode = m_mode;
191 isValid = m_state.endRead(seqValue);
192 isValid &= savedMode == mode;
193 }
194
195 if (isValid) {
196 return savedValue;
197 } else if (m_state.startWrite(&seqValue)) {
198 savedValue = calculateNewValue();
199 m_value = savedValue;
200 m_mode = mode;
201 m_state.endWrite(seqValue);
202 return savedValue;
203 } else {
204 return calculateNewValue();
205 }
206 }
bool endRead(int seq) const
bool startWrite(int *seq)
bool startRead(int *seq) const
virtual T calculateNewValue() const =0

References KisLockFreeCacheWithModeConsistency< T, Mode >::calculateNewValue(), KisCacheStateValue::endRead(), KisCacheStateValue::endWrite(), KisLockFreeCacheWithModeConsistency< T, Mode >::m_mode, KisLockFreeCacheWithModeConsistency< T, Mode >::m_state, KisLockFreeCacheWithModeConsistency< T, Mode >::m_value, KisCacheStateValue::startRead(), and KisCacheStateValue::startWrite().

◆ invalidate()

template<typename T , typename Mode >
void KisLockFreeCacheWithModeConsistency< T, Mode >::invalidate ( )
inline

Notify the cache that the value has changed

Definition at line 175 of file kis_lock_free_cache.h.

175 {
177 }

References KisCacheStateValue::invalidate(), and KisLockFreeCacheWithModeConsistency< T, Mode >::m_state.

◆ tryGetValue()

template<typename T , typename Mode >
bool KisLockFreeCacheWithModeConsistency< T, Mode >::tryGetValue ( T & result,
Mode mode ) const
inline

Definition at line 208 of file kis_lock_free_cache.h.

208 {
210 bool isValid = false;
211 T newValue;
212 Mode savedMode;
213
214 if (m_state.startRead(&seqValue)) {
215 newValue = m_value;
216 savedMode = m_mode;
217 isValid = m_state.endRead(seqValue);
218 isValid &= savedMode == mode;
219 }
220
221 if (isValid) {
222 result = newValue;
223 }
224
225 return isValid;
226 }

References KisCacheStateValue::endRead(), KisLockFreeCacheWithModeConsistency< T, Mode >::m_mode, KisLockFreeCacheWithModeConsistency< T, Mode >::m_state, KisLockFreeCacheWithModeConsistency< T, Mode >::m_value, and KisCacheStateValue::startRead().

Member Data Documentation

◆ m_mode

template<typename T , typename Mode >
Mode KisLockFreeCacheWithModeConsistency< T, Mode >::m_mode
mutableprivate

Definition at line 238 of file kis_lock_free_cache.h.

◆ m_state

template<typename T , typename Mode >
KisCacheStateValue KisLockFreeCacheWithModeConsistency< T, Mode >::m_state
mutableprivate

Definition at line 236 of file kis_lock_free_cache.h.

◆ m_value

template<typename T , typename Mode >
T KisLockFreeCacheWithModeConsistency< T, Mode >::m_value
mutableprivate

Definition at line 237 of file kis_lock_free_cache.h.


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