GDAL

gdal_abstractbandblockcache.h
1/******************************************************************************
2 *
3 * Name: gdal_abstractbandblockcache.h
4 * Project: GDAL Core
5 * Purpose: Declaration of GDALAbstractBandBlockCache base class
6 * Author: Frank Warmerdam, warmerdam@pobox.com
7 *
8 ******************************************************************************
9 * Copyright (c) 1998, Frank Warmerdam
10 * Copyright (c) 2007-2014, Even Rouault <even dot rouault at spatialys.com>
11 *
12 * SPDX-License-Identifier: MIT
13 ****************************************************************************/
14
15#ifndef GDALABSTRACTBANDBLOCKCACHE_H_INCLUDED
16#define GDALABSTRACTBANDBLOCKCACHE_H_INCLUDED
17
18#include "cpl_port.h"
19#include "cpl_error.h"
20
21 typedef struct _CPLCond CPLCond;
22 typedef struct _CPLLock CPLLock;
23 typedef struct _CPLMutex CPLMutex;
24
25 class GDALRasterBand;
26 class GDALRasterBlock;
27
28/* ******************************************************************** */
29/* GDALAbstractBandBlockCache */
30/* ******************************************************************** */
31
33
35// only used by GDALRasterBand implementation.
36
37 class GDALAbstractBandBlockCache /* non final */
38{
39 // List of blocks that can be freed or recycled, and its lock
40 CPLLock *hSpinLock = nullptr;
41 GDALRasterBlock *psListBlocksToFree = nullptr;
42
43 // Band keep alive counter, and its lock & condition
44 CPLCond *hCond = nullptr;
45 CPLMutex *hCondMutex = nullptr;
46 volatile int nKeepAliveCounter = 0;
47
48 volatile int m_nDirtyBlocks = 0;
49
50 CPL_DISALLOW_COPY_ASSIGN(GDALAbstractBandBlockCache)
51
52 protected:
53 explicit GDALAbstractBandBlockCache(GDALRasterBand *poBand);
54
55 GDALRasterBand *poBand;
56
57 int m_nInitialDirtyBlocksInFlushCache = 0;
58 int m_nLastTick = -1;
59 size_t m_nWriteDirtyBlocksDisabled = 0;
60
61 void FreeDanglingBlocks();
62 void UnreferenceBlockBase();
63
64 void StartDirtyBlockFlushingLog();
65 void UpdateDirtyBlockFlushingLog();
66 void EndDirtyBlockFlushingLog();
67
68 public:
69 virtual ~GDALAbstractBandBlockCache();
70
71 GDALRasterBlock *CreateBlock(int nXBlockOff, int nYBlockOff);
72 void AddBlockToFreeList(GDALRasterBlock *poBlock);
73 void IncDirtyBlocks(int nInc);
74 void WaitCompletionPendingTasks();
75
76 void EnableDirtyBlockWriting()
77 {
78 --m_nWriteDirtyBlocksDisabled;
79 }
80
81 void DisableDirtyBlockWriting()
82 {
83 ++m_nWriteDirtyBlocksDisabled;
84 }
85
86 bool HasDirtyBlocks() const
87 {
88 return m_nDirtyBlocks > 0;
89 }
90
91 virtual bool Init() = 0;
92 virtual bool IsInitOK() = 0;
93 virtual CPLErr FlushCache() = 0;
94 virtual CPLErr AdoptBlock(GDALRasterBlock *poBlock) = 0;
95 virtual GDALRasterBlock *TryGetLockedBlockRef(int nXBlockOff,
96 int nYBlockYOff) = 0;
97 virtual CPLErr UnreferenceBlock(GDALRasterBlock *poBlock) = 0;
98 virtual CPLErr FlushBlock(int nXBlockOff, int nYBlockOff,
99 int bWriteDirtyBlock) = 0;
100};
101
102GDALAbstractBandBlockCache *
103GDALArrayBandBlockCacheCreate(GDALRasterBand *poBand);
104GDALAbstractBandBlockCache *
105GDALHashSetBandBlockCacheCreate(GDALRasterBand *poBand);
106
108
109#endif
GDALRasterBand
A single raster band (or channel).
Definition gdal_rasterband.h:105
GDALRasterBlock
A single raster block in the block cache.
Definition gdal_rasterblock.h:33
cpl_error.h
CPL error handling services.
CPLErr
CPLErr
Error category.
Definition cpl_error.h:37
cpl_port.h
Core portability definitions for CPL.
CPL_DISALLOW_COPY_ASSIGN
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition cpl_port.h:936