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 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included
20 * in all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 * DEALINGS IN THE SOFTWARE.
29 ****************************************************************************/
30
31 #ifndef CPL_VIRTUAL_MEM_INCLUDED
32 #define CPL_VIRTUAL_MEM_INCLUDED
33
34 #include <stddef.h>
35
36 #include "cpl_port.h"
37 #include "cpl_vsi.h"
38
39 CPL_C_START
40
62 typedef struct CPLVirtualMem CPLVirtualMem;
63
74 typedef void (*CPLVirtualMemCachePageCbk)(CPLVirtualMem* ctxt,
75 size_t nOffset,
76 void* pPageToFill,
77 size_t nToFill,
78 void* pUserData);
79
90 typedef void (*CPLVirtualMemUnCachePageCbk)(CPLVirtualMem* ctxt,
91 size_t nOffset,
92 const void* pPageToBeEvicted,
93 size_t nToBeEvicted,
94 void* pUserData);
95
99 typedef void (*CPLVirtualMemFreeUserData)(void* pUserData);
100
102 typedef enum
103 {
106 VIRTUALMEM_READONLY,
109 VIRTUALMEM_READONLY_ENFORCED,
112 VIRTUALMEM_READWRITE
113 } CPLVirtualMemAccessMode;
114
121 size_t CPL_DLL CPLGetPageSize(void);
122
167 CPLVirtualMem CPL_DLL *CPLVirtualMemNew(size_t nSize,
168 size_t nCacheSize,
169 size_t nPageSizeHint,
170 int bSingleThreadUsage,
171 CPLVirtualMemAccessMode eAccessMode,
172 CPLVirtualMemCachePageCbk pfnCachePage,
173 CPLVirtualMemUnCachePageCbk pfnUnCachePage,
174 CPLVirtualMemFreeUserData pfnFreeUserData,
175 void *pCbkUserData);
176
182 int CPL_DLL CPLIsVirtualMemFileMapAvailable(void);
183
210 CPLVirtualMem CPL_DLL *CPLVirtualMemFileMapNew( VSILFILE* fp,
211 vsi_l_offset nOffset,
212 vsi_l_offset nLength,
213 CPLVirtualMemAccessMode eAccessMode,
214 CPLVirtualMemFreeUserData pfnFreeUserData,
215 void *pCbkUserData );
216
236 CPLVirtualMem CPL_DLL *CPLVirtualMemDerivedNew(CPLVirtualMem* pVMemBase,
237 vsi_l_offset nOffset,
238 vsi_l_offset nSize,
239 CPLVirtualMemFreeUserData pfnFreeUserData,
240 void *pCbkUserData);
241
253 void CPL_DLL CPLVirtualMemFree(CPLVirtualMem* ctxt);
254
270 void CPL_DLL *CPLVirtualMemGetAddr(CPLVirtualMem* ctxt);
271
279 size_t CPL_DLL CPLVirtualMemGetSize(CPLVirtualMem* ctxt);
280
288 int CPL_DLL CPLVirtualMemIsFileMapping(CPLVirtualMem* ctxt);
289
297 CPLVirtualMemAccessMode CPL_DLL CPLVirtualMemGetAccessMode(CPLVirtualMem* ctxt);
298
309 size_t CPL_DLL CPLVirtualMemGetPageSize(CPLVirtualMem* ctxt);
310
328 int CPL_DLL CPLVirtualMemIsAccessThreadSafe(CPLVirtualMem* ctxt);
329
342 void CPL_DLL CPLVirtualMemDeclareThread(CPLVirtualMem* ctxt);
343
356 void CPL_DLL CPLVirtualMemUnDeclareThread(CPLVirtualMem* ctxt);
357
375 void CPL_DLL CPLVirtualMemPin(CPLVirtualMem* ctxt,
376 void* pAddr, size_t nSize, int bWriteOp);
377
385 void CPL_DLL CPLVirtualMemManagerTerminate(void);
386
387 CPL_C_END
388
389 #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:339
CPL_C_START
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:337
CPLIsVirtualMemFileMapAvailable
int CPLIsVirtualMemFileMapAvailable(void)
Return if virtual memory mapping of a file is available.
Definition: cpl_virtualmem.cpp:2156
CPLVirtualMemGetSize
size_t CPLVirtualMemGetSize(CPLVirtualMem *ctxt)
Return the size of the virtual memory mapping.
Definition: cpl_virtualmem.cpp:2238
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:74
CPLVirtualMemManagerTerminate
void CPLVirtualMemManagerTerminate(void)
Cleanup any resource and handlers related to virtual memory.
Definition: cpl_virtualmem.cpp:1992
CPLVirtualMemGetAddr
void * CPLVirtualMemGetAddr(CPLVirtualMem *ctxt)
Return the pointer to the start of a virtual memory mapping.
Definition: cpl_virtualmem.cpp:2202
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:1986
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:2015
CPLVirtualMemIsFileMapping
int CPLVirtualMemIsFileMapping(CPLVirtualMem *ctxt)
Return if the virtual memory mapping is a direct file mapping.
Definition: cpl_virtualmem.cpp:2211
CPLVirtualMemUnDeclareThread
void CPLVirtualMemUnDeclareThread(CPLVirtualMem *ctxt)
Declare that a thread will stop accessing a virtual memory mapping.
Definition: cpl_virtualmem.cpp:1984
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:90
CPLVirtualMemFreeUserData
void(* CPLVirtualMemFreeUserData)(void *pUserData)
Callback triggered when a virtual memory mapping is destroyed.
Definition: cpl_virtualmem.h:99
CPLVirtualMemGetAccessMode
CPLVirtualMemAccessMode CPLVirtualMemGetAccessMode(CPLVirtualMem *ctxt)
Return the access mode of the virtual memory mapping.
Definition: cpl_virtualmem.cpp:2220
CPLVirtualMemDeclareThread
void CPLVirtualMemDeclareThread(CPLVirtualMem *ctxt)
Declare that a thread will access a virtual memory mapping.
Definition: cpl_virtualmem.cpp:1982
CPLVirtualMem
struct CPLVirtualMem CPLVirtualMem
Opaque type that represents a virtual memory mapping.
Definition: cpl_virtualmem.h:62
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:2256
CPLVirtualMemIsAccessThreadSafe
int CPLVirtualMemIsAccessThreadSafe(CPLVirtualMem *ctxt)
Return TRUE if this memory mapping can be accessed safely from concurrent threads.
Definition: cpl_virtualmem.cpp:2247
CPLVirtualMemFree
void CPLVirtualMemFree(CPLVirtualMem *ctxt)
Free a virtual memory mapping.
Definition: cpl_virtualmem.cpp:2169
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:1965
CPLVirtualMemAccessMode
CPLVirtualMemAccessMode
Access mode of a virtual memory mapping.
Definition: cpl_virtualmem.h:103
VIRTUALMEM_READONLY_ENFORCED
@ VIRTUALMEM_READONLY_ENFORCED
Definition: cpl_virtualmem.h:109
VIRTUALMEM_READWRITE
@ VIRTUALMEM_READWRITE
Definition: cpl_virtualmem.h:112
VIRTUALMEM_READONLY
@ VIRTUALMEM_READONLY
Definition: cpl_virtualmem.h:106
CPLVirtualMemGetPageSize
size_t CPLVirtualMemGetPageSize(CPLVirtualMem *ctxt)
Return the page size associated to a virtual memory mapping.
Definition: cpl_virtualmem.cpp:2229
CPLGetPageSize
size_t CPLGetPageSize(void)
Return the size of a page of virtual memory.
Definition: cpl_virtualmem.cpp:2143
cpl_vsi.h
Standard C Covers.
VSILFILE
FILE VSILFILE
Opaque type for a FILE that implements the VSIVirtualHandle API.
Definition: cpl_vsi.h:156
vsi_l_offset
GUIntBig vsi_l_offset
Type for a file offset.
Definition: cpl_vsi.h:140