diff --git a/Utilities/otbossim/include/ossim/elevation/ossimElevManager.h b/Utilities/otbossim/include/ossim/elevation/ossimElevManager.h index 3d4170adea0d947543b3ce085ce1831ba09f07c8..eadea79069bcf043409982ed8990a0587d7f1d31 100644 --- a/Utilities/otbossim/include/ossim/elevation/ossimElevManager.h +++ b/Utilities/otbossim/include/ossim/elevation/ossimElevManager.h @@ -124,7 +124,7 @@ protected: // bool m_useGeoidIfNullFlag; - OpenThreads::ReadWriteMutex m_mutex; + OpenThreads::Mutex m_mutex; }; #endif diff --git a/Utilities/otbossim/src/ossim/elevation/ossimElevManager.cpp b/Utilities/otbossim/src/ossim/elevation/ossimElevManager.cpp index b356c9bf7ab3e685bdd78bc0e1d730f84777f60c..b0661041d075c54a6ad90de2ef688f448da8bdd3 100644 --- a/Utilities/otbossim/src/ossim/elevation/ossimElevManager.cpp +++ b/Utilities/otbossim/src/ossim/elevation/ossimElevManager.cpp @@ -59,7 +59,7 @@ ossimElevManager::~ossimElevManager() double ossimElevManager::getHeightAboveEllipsoid(const ossimGpt& gpt) { - m_mutex.readLock(); + OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_mutex); if(!isSourceEnabled()) return ossim::nan(); double result = ossim::nan(); @@ -80,13 +80,12 @@ double ossimElevManager::getHeightAboveEllipsoid(const ossimGpt& gpt) { result += m_elevationOffset; } - m_mutex.readUnlock(); return result; } double ossimElevManager::getHeightAboveMSL(const ossimGpt& gpt) { - m_mutex.readLock(); + OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_mutex); if(!isSourceEnabled()) return ossim::nan(); double result = ossim::nan(); ossim_uint32 idx = 0; @@ -106,7 +105,6 @@ double ossimElevManager::getHeightAboveMSL(const ossimGpt& gpt) { result += m_elevationOffset; } - m_mutex.readUnlock(); return result; } @@ -191,11 +189,9 @@ void ossimElevManager::getOpenCellList(std::vector<ossimFilename>& list) const void ossimElevManager::clear() { - m_mutex.writeLock(); + OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_mutex); m_elevationDatabaseList.clear(); - - m_mutex.writeUnlock(); } bool ossimElevManager::saveState(ossimKeywordlist& kwl, @@ -301,13 +297,12 @@ void ossimElevManager::addDatabase(ossimElevationDatabase* database) { if(!database) return; ossimRefPtr<ossimElevationDatabase> tempDb = database; - m_mutex.writeLock(); + OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_mutex); if(std::find(m_elevationDatabaseList.begin(), m_elevationDatabaseList.end(), database) == m_elevationDatabaseList.end()) { m_elevationDatabaseList.push_back(database); } - m_mutex.writeUnlock(); } diff --git a/Utilities/otbossim/src/ossim/elevation/ossimElevationDatabase.cpp b/Utilities/otbossim/src/ossim/elevation/ossimElevationDatabase.cpp index f2d86a6c9f22f22e365177013a190d3e2188f132..7f7934e4689e024c86edf9334d3ae625ee54fb29 100644 --- a/Utilities/otbossim/src/ossim/elevation/ossimElevationDatabase.cpp +++ b/Utilities/otbossim/src/ossim/elevation/ossimElevationDatabase.cpp @@ -70,29 +70,32 @@ ossimRefPtr<ossimElevCellHandler> ossimElevationCellDatabase::getOrCreateCellHan { ossimRefPtr<ossimElevCellHandler> result = 0; ossim_uint64 id = createId(gpt); - m_cacheMapMutex.lock(); - CellMap::iterator iter = m_cacheMap.find(id); - - if(iter != m_cacheMap.end()) + { - iter->second->updateTimestamp(); - result = iter->second->m_handler.get(); - m_cacheMapMutex.unlock(); - return result.get(); + OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_cacheMapMutex); + CellMap::iterator iter = m_cacheMap.find(id); + if(iter != m_cacheMap.end()) + { + iter->second->updateTimestamp(); + result = iter->second->m_handler.get(); + + return result.get(); + } } - m_cacheMapMutex.unlock(); - + result = createCell(gpt); - m_cacheMapMutex.lock(); - if(result.valid()) - { - m_cacheMap.insert(std::make_pair(id, new CellInfo(id, result.get()))); - } - if(m_cacheMap.size() > m_maxOpenCells) + { - flushCacheToMinOpenCells(); + OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_cacheMapMutex); + if(result.valid()) + { + m_cacheMap.insert(std::make_pair(id, new CellInfo(id, result.get()))); + } + if(m_cacheMap.size() > m_maxOpenCells) + { + flushCacheToMinOpenCells(); + } } - m_cacheMapMutex.unlock(); return result; diff --git a/Utilities/otbossim/src/ossim/elevation/ossimSrtmElevationDatabase.cpp b/Utilities/otbossim/src/ossim/elevation/ossimSrtmElevationDatabase.cpp index 0bb05494f9eb8ab194488283bb297e5e1652a342..1603dcb2d09d1f19ac757837a70f020029efd0ed 100644 --- a/Utilities/otbossim/src/ossim/elevation/ossimSrtmElevationDatabase.cpp +++ b/Utilities/otbossim/src/ossim/elevation/ossimSrtmElevationDatabase.cpp @@ -208,7 +208,7 @@ ossimSrtmElevationDatabase::createCell(const ossimGpt& gpt) #if 0 ossimRefPtr<ossimElevCellHandler> result = 0; ossim_uint64 id = createId(gpt); - m_cacheMapMutex.lock(); + OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_cacheMapMutex); CellMap::iterator iter = m_cacheMap.find(id); if(iter != m_cacheMap.end()) @@ -235,7 +235,6 @@ ossimSrtmElevationDatabase::createCell(const ossimGpt& gpt) } } } - m_cacheMapMutex.unlock(); return result; #endif