GDALRasterBlock *GDALArrayBandBlockCache::TryGetLockedBlockRef( int nXBlockOff, int nYBlockOff ) { GDALRasterBlock *poBlock; int nBlockIndex = 0; /* -------------------------------------------------------------------- */ /* Simple case for single level caches. */ /* -------------------------------------------------------------------- */ if( !bSubBlockingActive ) { nBlockIndex = nXBlockOff + nYBlockOff * poBand->nBlocksPerRow; while( TRUE ) { poBlock = u.papoBlocks[nBlockIndex]; if( poBlock == NULL ) return NULL; if( poBlock->TakeLock() ) break; } } else { /* -------------------------------------------------------------------- */ /* Identify our subblock. */ /* -------------------------------------------------------------------- */ int nSubBlock = TO_SUBBLOCK(nXBlockOff) + TO_SUBBLOCK(nYBlockOff) * nSubBlocksPerRow; /* -------------------------------------------------------------------- */ /* Check within subblock. */ /* -------------------------------------------------------------------- */ GDALRasterBlock **papoSubBlockGrid = u.papapoBlocks[nSubBlock]; if( papoSubBlockGrid == NULL ) return NULL; int nBlockInSubBlock = WITHIN_SUBBLOCK(nXBlockOff) + WITHIN_SUBBLOCK(nYBlockOff) * SUBBLOCK_SIZE; while( TRUE ) { poBlock = papoSubBlockGrid[nBlockInSubBlock]; if( poBlock == NULL ) return NULL; if( poBlock->TakeLock() ) break; } } return poBlock; }
GDALRasterBlock *GDALHashSetBandBlockCache::TryGetLockedBlockRef( int nXBlockOff, int nYBlockOff ) { GDALRasterBlock oBlockForLookup(nXBlockOff, nYBlockOff); GDALRasterBlock* poBlock; { CPLLockHolderOptionalLockD( hLock ); auto oIter = m_oSet.find(&oBlockForLookup); if( oIter == m_oSet.end() ) return nullptr; poBlock = *oIter; } if( !poBlock->TakeLock() ) return nullptr; return poBlock; }