GDAL

cpl_virtualmem.h
Go to the documentation of this file.
1/**********************************************************************
2 * $Id$
3 *
4 * Name: cpl_virtualmem.h
5 * Project: CPL - Common Portability Library
6 * Purpose: Virtual memory
7 * Author: Even Rouault, <even dot rouault at spatialys.com>
8 *
9 **********************************************************************
10 * Copyright (c) 2014, Even Rouault <even dot rouault at spatialys.com>
11 *
12 * SPDX-License-Identifier: MIT
13 ****************************************************************************/
14
15#ifndef CPL_VIRTUAL_MEM_INCLUDED
16#define CPL_VIRTUAL_MEM_INCLUDED
17
18#include <stddef.h>
19
20#include "cpl_port.h"
21#include "cpl_vsi.h"
22
23 CPL_C_START
24
46 typedef struct CPLVirtualMem CPLVirtualMem;
47
59 typedef void (*CPLVirtualMemCachePageCbk)(CPLVirtualMem *ctxt, size_t nOffset,
60 void *pPageToFill, size_t nToFill,
61 void *pUserData);
62
74 typedef void (*CPLVirtualMemUnCachePageCbk)(CPLVirtualMem *ctxt, size_t nOffset,
75 const void *pPageToBeEvicted,
76 size_t nToBeEvicted,
77 void *pUserData);
78
82 typedef void (*CPLVirtualMemFreeUserData)(void *pUserData);
83
85 typedef enum
86{
89 VIRTUALMEM_READONLY,
92 VIRTUALMEM_READONLY_ENFORCED,
95 VIRTUALMEM_READWRITE
96} CPLVirtualMemAccessMode;
97
104 size_t CPL_DLL CPLGetPageSize(void);
105
150 CPLVirtualMem CPL_DLL *
151 CPLVirtualMemNew(size_t nSize, size_t nCacheSize, size_t nPageSizeHint,
152 int bSingleThreadUsage, CPLVirtualMemAccessMode eAccessMode,
153 CPLVirtualMemCachePageCbk pfnCachePage,
154 CPLVirtualMemUnCachePageCbk pfnUnCachePage,
155 CPLVirtualMemFreeUserData pfnFreeUserData, void *pCbkUserData);
156
162 int CPL_DLL CPLIsVirtualMemFileMapAvailable(void);
163
190 CPLVirtualMem CPL_DLL *CPLVirtualMemFileMapNew(
191 VSILFILE *fp, vsi_l_offset nOffset, vsi_l_offset nLength,
192 CPLVirtualMemAccessMode eAccessMode,
193 CPLVirtualMemFreeUserData pfnFreeUserData, void *pCbkUserData);
194
214 CPLVirtualMem CPL_DLL *CPLVirtualMemDerivedNew(
215 CPLVirtualMem *pVMemBase, vsi_l_offset nOffset, vsi_l_offset nSize,
216 CPLVirtualMemFreeUserData pfnFreeUserData, void *pCbkUserData);
217
229 void CPL_DLL CPLVirtualMemFree(CPLVirtualMem *ctxt);
230
246 void CPL_DLL *CPLVirtualMemGetAddr(CPLVirtualMem *ctxt);
247
255 size_t CPL_DLL CPLVirtualMemGetSize(CPLVirtualMem *ctxt);
256
264 int CPL_DLL CPLVirtualMemIsFileMapping(CPLVirtualMem *ctxt);
265
273 CPLVirtualMemAccessMode CPL_DLL CPLVirtualMemGetAccessMode(CPLVirtualMem *ctxt);
274
285 size_t CPL_DLL CPLVirtualMemGetPageSize(CPLVirtualMem *ctxt);
286
304 int CPL_DLL CPLVirtualMemIsAccessThreadSafe(CPLVirtualMem *ctxt);
305
318 void CPL_DLL CPLVirtualMemDeclareThread(CPLVirtualMem *ctxt);
319
332 void CPL_DLL CPLVirtualMemUnDeclareThread(CPLVirtualMem *ctxt);
333
351 void CPL_DLL CPLVirtualMemPin(CPLVirtualMem *ctxt, void *pAddr, size_t nSize,
352 int bWriteOp);
353
361 void CPL_DLL CPLVirtualMemManagerTerminate(void);
362
363 CPL_C_END
364
365#endif /* CPL_VIRTUAL_MEM_INCLUDED */
cpl_port.h
Core portability definitions for CPL.
CPL_C_END
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:283
CPL_C_START
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:279
CPLIsVirtualMemFileMapAvailable
int CPLIsVirtualMemFileMapAvailable(void)
Return if virtual memory mapping of a file is available.
Definition cpl_virtualmem.cpp:2137
CPLVirtualMemFileMapNew
CPLVirtualMem * CPLVirtualMemFileMapNew(VSILFILE *fp, vsi_l_offset nOffset, vsi_l_offset nLength, CPLVirtualMemAccessMode eAccessMode, CPLVirtualMemFreeUserData pfnFreeUserData, void *pCbkUserData)
Create a new virtual memory mapping from a file.
Definition cpl_virtualmem.cpp:2107
CPLVirtualMemGetSize
size_t CPLVirtualMemGetSize(CPLVirtualMem *ctxt)
Return the size of the virtual memory mapping.
Definition cpl_virtualmem.cpp:2219
CPLVirtualMemNew
CPLVirtualMem * CPLVirtualMemNew(size_t nSize, size_t nCacheSize, size_t nPageSizeHint, int bSingleThreadUsage, CPLVirtualMemAccessMode eAccessMode, CPLVirtualMemCachePageCbk pfnCachePage, CPLVirtualMemUnCachePageCbk pfnUnCachePage, CPLVirtualMemFreeUserData pfnFreeUserData, void *pCbkUserData)
Create a new virtual memory mapping.
Definition cpl_virtualmem.cpp:1948
CPLVirtualMemCachePageCbk
void(* CPLVirtualMemCachePageCbk)(CPLVirtualMem *ctxt, size_t nOffset, void *pPageToFill, size_t nToFill, void *pUserData)
Callback triggered when a still unmapped page of virtual memory is accessed.
Definition cpl_virtualmem.h:59
CPLVirtualMemManagerTerminate
void CPLVirtualMemManagerTerminate(void)
Cleanup any resource and handlers related to virtual memory.
Definition cpl_virtualmem.cpp:1974
CPLVirtualMemPin
void CPLVirtualMemPin(CPLVirtualMem *ctxt, void *pAddr, size_t nSize, int bWriteOp)
Make sure that a region of virtual memory will be realized.
Definition cpl_virtualmem.cpp:1969
CPLVirtualMemIsFileMapping
int CPLVirtualMemIsFileMapping(CPLVirtualMem *ctxt)
Return if the virtual memory mapping is a direct file mapping.
Definition cpl_virtualmem.cpp:2192
CPLVirtualMemGetAddr
void * CPLVirtualMemGetAddr(CPLVirtualMem *ctxt)
Return the pointer to the start of a virtual memory mapping.
Definition cpl_virtualmem.cpp:2183
CPLVirtualMemUnDeclareThread
void CPLVirtualMemUnDeclareThread(CPLVirtualMem *ctxt)
Declare that a thread will stop accessing a virtual memory mapping.
Definition cpl_virtualmem.cpp:1965
CPLVirtualMemUnCachePageCbk
void(* CPLVirtualMemUnCachePageCbk)(CPLVirtualMem *ctxt, size_t nOffset, const void *pPageToBeEvicted, size_t nToBeEvicted, void *pUserData)
Callback triggered when a dirty mapped page is going to be freed.
Definition cpl_virtualmem.h:74
CPLVirtualMemFreeUserData
void(* CPLVirtualMemFreeUserData)(void *pUserData)
Callback triggered when a virtual memory mapping is destroyed.
Definition cpl_virtualmem.h:82
CPLVirtualMemDerivedNew
CPLVirtualMem * CPLVirtualMemDerivedNew(CPLVirtualMem *pVMemBase, vsi_l_offset nOffset, vsi_l_offset nSize, CPLVirtualMemFreeUserData pfnFreeUserData, void *pCbkUserData)
Create a new virtual memory mapping derived from an other virtual memory mapping.
Definition cpl_virtualmem.cpp:2237
CPLVirtualMemGetAccessMode
CPLVirtualMemAccessMode CPLVirtualMemGetAccessMode(CPLVirtualMem *ctxt)
Return the access mode of the virtual memory mapping.
Definition cpl_virtualmem.cpp:2201
CPLVirtualMemDeclareThread
void CPLVirtualMemDeclareThread(CPLVirtualMem *ctxt)
Declare that a thread will access a virtual memory mapping.
Definition cpl_virtualmem.cpp:1961
CPLVirtualMem
struct CPLVirtualMem CPLVirtualMem
Opaque type that represents a virtual memory mapping.
Definition cpl_virtualmem.h:46
CPLVirtualMemIsAccessThreadSafe
int CPLVirtualMemIsAccessThreadSafe(CPLVirtualMem *ctxt)
Return TRUE if this memory mapping can be accessed safely from concurrent threads.
Definition cpl_virtualmem.cpp:2228
CPLVirtualMemFree
void CPLVirtualMemFree(CPLVirtualMem *ctxt)
Free a virtual memory mapping.
Definition cpl_virtualmem.cpp:2150
CPLVirtualMemAccessMode
CPLVirtualMemAccessMode
Access mode of a virtual memory mapping.
Definition cpl_virtualmem.h:86
VIRTUALMEM_READONLY_ENFORCED
@ VIRTUALMEM_READONLY_ENFORCED
Definition cpl_virtualmem.h:92
VIRTUALMEM_READWRITE
@ VIRTUALMEM_READWRITE
Definition cpl_virtualmem.h:95
VIRTUALMEM_READONLY
@ VIRTUALMEM_READONLY
Definition cpl_virtualmem.h:89
CPLVirtualMemGetPageSize
size_t CPLVirtualMemGetPageSize(CPLVirtualMem *ctxt)
Return the page size associated to a virtual memory mapping.
Definition cpl_virtualmem.cpp:2210
CPLGetPageSize
size_t CPLGetPageSize(void)
Return the size of a page of virtual memory.
Definition cpl_virtualmem.cpp:2124
cpl_vsi.h
Standard C Covers.
vsi_l_offset
GUIntBig vsi_l_offset
Type for a file offset.
Definition cpl_vsi.h:130
VSIVirtualHandle
Virtual file handle.
Definition cpl_vsi_virtual.h:47