Masterwork From Distant Lands
ActivePublic

Authored by dkazakov on Aug 10 2017, 7:46 AM.
diff --git a/libs/image/tiles3/kis_tile_hash_table.h b/libs/image/tiles3/kis_tile_hash_table.h
index 6170cec..30b396c 100644
--- a/libs/image/tiles3/kis_tile_hash_table.h
+++ b/libs/image/tiles3/kis_tile_hash_table.h
@@ -26,7 +26,6 @@
#include <boost/thread/lock_guard.hpp>
#include <boost/thread/shared_lock_guard.hpp>
-
/**
* This is a template for a hash table that stores tiles (or some other
* objects resembling tiles). Actually, this object should only have
@@ -140,7 +139,7 @@ private:
void debugListLengthDistibution();
void sanityChecksumCheck();
private:
- template<class U> friend class KisTileHashTableIteratorTraits;
+ template<class U, class LockerType> friend class KisTileHashTableIteratorTraits;
typedef boost::shared_lock_guard<KisTileHashTableTraits<T>> ReadLockerImpl;
typedef boost::lock_guard<KisTileHashTableTraits<T>> WriteLockerImpl;
@@ -169,6 +168,7 @@ private:
#include "kis_tile_hash_table_p.h"
+#include <boost/thread/lockable_adapter.hpp>
/**
* Walks through all tiles inside hash table
@@ -176,31 +176,33 @@ private:
* during iterating with this iterator, because HT is locked.
* The only thing you can do is to delete current tile.
*/
-template<class T>
+template<class T, class LockerType = boost::lock_guard<KisTileHashTableTraits<T>> >
class KisTileHashTableIteratorTraits
{
public:
typedef T TileType;
typedef KisSharedPtr<T> TileTypeSP;
- KisTileHashTableIteratorTraits(KisTileHashTableTraits<T> *ht) {
+ KisTileHashTableIteratorTraits(KisTileHashTableTraits<T> *ht)
+ : m_locker(*ht)
+ {
m_hashTable = ht;
m_index = nextNonEmptyList(0);
if (m_index < KisTileHashTableTraits<T>::TABLE_SIZE)
m_tile = m_hashTable->m_hashTable[m_index];
//m_hashTable->m_lock.lockForWrite();
- m_hashTable->lock();
+ //m_hashTable->lock();
}
- ~KisTileHashTableIteratorTraits<T>() {
+ ~KisTileHashTableIteratorTraits() {
if (m_index != -1) {
//m_hashTable->m_lock.unlock();
- m_hashTable->unlock();
+ //m_hashTable->unlock();
}
}
- KisTileHashTableIteratorTraits<T>& operator++() {
+ KisTileHashTableIteratorTraits<T, LockerType>& operator++() {
next();
return *this;
}
@@ -248,13 +250,14 @@ public:
void destroy() {
m_index = -1;
- m_hashTable->unlock();
+ //m_hashTable->unlock();
//m_hashTable->m_lock.unlock();
}
protected:
TileTypeSP m_tile;
qint32 m_index;
KisTileHashTableTraits<T> *m_hashTable;
+ LockerType m_locker;
protected:
qint32 nextNonEmptyList(qint32 startIdx) {
@@ -268,11 +271,12 @@ protected:
return idx;
}
private:
- Q_DISABLE_COPY(KisTileHashTableIteratorTraits<T>)
+ Q_DISABLE_COPY(KisTileHashTableIteratorTraits)
};
typedef KisTileHashTableTraits<KisTile> KisTileHashTable;
typedef KisTileHashTableIteratorTraits<KisTile> KisTileHashTableIterator;
+typedef KisTileHashTableIteratorTraits<KisTile, boost::shared_lock_guard<KisTileHashTable>> KisTileHashTableConstIterator;
#endif /* KIS_TILEHASHTABLE_H_ */
diff --git a/libs/image/tiles3/kis_tiled_data_manager.cc b/libs/image/tiles3/kis_tiled_data_manager.cc
index 2191de5..9c44679 100644
--- a/libs/image/tiles3/kis_tiled_data_manager.cc
+++ b/libs/image/tiles3/kis_tiled_data_manager.cc
@@ -646,7 +646,7 @@ void KisTiledDataManager::recalculateExtent()
m_extentMaxX = qint32_MIN;
m_extentMaxY = qint32_MIN;
- KisTileHashTableIterator iter(m_hashTable);
+ KisTileHashTableConstIterator iter(m_hashTable);
KisTileSP tile;
while ((tile = iter.tile())) {
@@ -694,7 +694,7 @@ QRegion KisTiledDataManager::region() const
{
QRegion region;
- KisTileHashTableIterator iter(m_hashTable);
+ KisTileHashTableConstIterator iter(m_hashTable);
KisTileSP tile;
while ((tile = iter.tile())) {
dkazakov edited the content of this paste. (Show Details)Aug 10 2017, 7:46 AM
dkazakov changed the title of this paste from untitled to Masterwork From Distant Lands.
dkazakov updated the paste's language from autodetect to autodetect.