Commit b4755b74 authored by Andrey Kamakin's avatar Andrey Kamakin

Fixed code issues and made blocking map to be default one.

Ref T8874
parent 73125cb1
...@@ -169,7 +169,7 @@ option(HIDE_SAFE_ASSERTS "Don't show message box for \"safe\" asserts, just igno ...@@ -169,7 +169,7 @@ option(HIDE_SAFE_ASSERTS "Don't show message box for \"safe\" asserts, just igno
configure_file(config-hide-safe-asserts.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-hide-safe-asserts.h) configure_file(config-hide-safe-asserts.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-hide-safe-asserts.h)
add_feature_info("Safe Asserts" HIDE_SAFE_ASSERTS "Don't show message box for \"safe\" asserts, just ignore them automatically and dump a message to the terminal.") add_feature_info("Safe Asserts" HIDE_SAFE_ASSERTS "Don't show message box for \"safe\" asserts, just ignore them automatically and dump a message to the terminal.")
option(USE_LOCK_FREE_HASH_TABLE "Use lock free hash table instead of blocking." ON) option(USE_LOCK_FREE_HASH_TABLE "Use lock free hash table instead of blocking." OFF)
configure_file(config-hash-table-implementaion.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-hash-table-implementaion.h) configure_file(config-hash-table-implementaion.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-hash-table-implementaion.h)
add_feature_info("Lock free hash table" USE_LOCK_FREE_HASH_TABLE "Use lock free hash table instead of blocking.") add_feature_info("Lock free hash table" USE_LOCK_FREE_HASH_TABLE "Use lock free hash table instead of blocking.")
......
/* config-hash-table-implementation.h. Generated by cmake from config-hash-table-implementation.h.cmake */ /* config-hash-table-implementation.h. Generated by cmake from config-hash-table-implementation.h.cmake */
/* Define if you have ocio, the OpenColorIO Library */
#cmakedefine USE_LOCK_FREE_HASH_TABLE 1 #cmakedefine USE_LOCK_FREE_HASH_TABLE 1
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* How to use: * How to use:
* 1) each hash must be unique, otherwise tiles would rewrite each-other * 1) each hash must be unique, otherwise tiles would rewrite each-other
* 2) 0 key is reserved, so can't be used * 2) 0 key is reserved, so can't be used
* 3) col and row must be less than 0x7FFF to garantee uniqueness of hash for each pair * 3) col and row must be less than 0x7FFF to guarantee uniqueness of hash for each pair
*/ */
template <class T> template <class T>
...@@ -152,16 +152,14 @@ private: ...@@ -152,16 +152,14 @@ private:
return wasDeleted; return wasDeleted;
} }
inline TileTypeSP get(quint32 key)
{
TileTypeSP result = m_map.get(key);
m_map.getGC().update(m_map.migrationInProcess());
return result;
}
private: private:
ConcurrentMap<quint32, TileType*> m_map; ConcurrentMap<quint32, TileType*> m_map;
QReadWriteLock m_rwLock;
/**
* We still need something to guard changes in m_defaultTileData,
* otherwise there will be concurrent read/writes, resulting in broken memory.
*/
QReadWriteLock m_defaultPixelDataLock;
QAtomicInt m_numTiles; QAtomicInt m_numTiles;
KisTileData *m_defaultTileData; KisTileData *m_defaultTileData;
...@@ -244,15 +242,16 @@ KisTileHashTableTraits2<T>::~KisTileHashTableTraits2() ...@@ -244,15 +242,16 @@ KisTileHashTableTraits2<T>::~KisTileHashTableTraits2()
template<class T> template<class T>
bool KisTileHashTableTraits2<T>::tileExists(qint32 col, qint32 row) bool KisTileHashTableTraits2<T>::tileExists(qint32 col, qint32 row)
{ {
quint32 idx = calculateHash(col, row); return getExistingTile(col, row);
return get(idx);
} }
template <class T> template <class T>
typename KisTileHashTableTraits2<T>::TileTypeSP KisTileHashTableTraits2<T>::getExistingTile(qint32 col, qint32 row) typename KisTileHashTableTraits2<T>::TileTypeSP KisTileHashTableTraits2<T>::getExistingTile(qint32 col, qint32 row)
{ {
quint32 idx = calculateHash(col, row); quint32 idx = calculateHash(col, row);
return get(idx); TileTypeSP result = m_map.get(idx);
m_map.getGC().update(m_map.migrationInProcess());
return result;
} }
template <class T> template <class T>
...@@ -265,7 +264,7 @@ typename KisTileHashTableTraits2<T>::TileTypeSP KisTileHashTableTraits2<T>::getT ...@@ -265,7 +264,7 @@ typename KisTileHashTableTraits2<T>::TileTypeSP KisTileHashTableTraits2<T>::getT
if (!mutator.getValue()) { if (!mutator.getValue()) {
{ {
QReadLocker guard(&m_rwLock); QReadLocker guard(&m_defaultPixelDataLock);
tile = new TileType(col, row, m_defaultTileData, m_mementoManager); tile = new TileType(col, row, m_defaultTileData, m_mementoManager);
} }
TileTypeSP::ref(&tile, tile.data()); TileTypeSP::ref(&tile, tile.data());
...@@ -295,7 +294,7 @@ typename KisTileHashTableTraits2<T>::TileTypeSP KisTileHashTableTraits2<T>::getR ...@@ -295,7 +294,7 @@ typename KisTileHashTableTraits2<T>::TileTypeSP KisTileHashTableTraits2<T>::getR
existingTile = tile; existingTile = tile;
if (!existingTile) { if (!existingTile) {
QReadLocker guard(&m_rwLock); QReadLocker guard(&m_defaultPixelDataLock);
tile = new TileType(col, row, m_defaultTileData, 0); tile = new TileType(col, row, m_defaultTileData, 0);
} }
...@@ -336,7 +335,7 @@ void KisTileHashTableTraits2<T>::clear() ...@@ -336,7 +335,7 @@ void KisTileHashTableTraits2<T>::clear()
template <class T> template <class T>
inline void KisTileHashTableTraits2<T>::setDefaultTileData(KisTileData *defaultTileData) inline void KisTileHashTableTraits2<T>::setDefaultTileData(KisTileData *defaultTileData)
{ {
QWriteLocker guard(&m_rwLock); QWriteLocker guard(&m_defaultPixelDataLock);
if (m_defaultTileData) { if (m_defaultTileData) {
m_defaultTileData->release(); m_defaultTileData->release();
m_defaultTileData = 0; m_defaultTileData = 0;
...@@ -351,7 +350,7 @@ inline void KisTileHashTableTraits2<T>::setDefaultTileData(KisTileData *defaultT ...@@ -351,7 +350,7 @@ inline void KisTileHashTableTraits2<T>::setDefaultTileData(KisTileData *defaultT
template <class T> template <class T>
inline KisTileData* KisTileHashTableTraits2<T>::defaultTileData() inline KisTileData* KisTileHashTableTraits2<T>::defaultTileData()
{ {
QReadLocker guard(&m_rwLock); QReadLocker guard(&m_defaultPixelDataLock);
return m_defaultTileData; return m_defaultTileData;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment