1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

On windows, flush the mapping view when syncing content to disk.

FossilOrigin-Name: a828e73dc1ae50189bdf73f60caeb7308738ad7a
This commit is contained in:
drh
2015-03-31 19:40:05 +00:00
3 changed files with 38 additions and 10 deletions

View File

@@ -197,8 +197,10 @@ WINBASEAPI LPVOID WINAPI MapViewOfFile(HANDLE, DWORD, DWORD, DWORD, SIZE_T);
#endif /* SQLITE_OS_WINRT */
/*
** This file mapping API is common to both Win32 and WinRT.
** These file mapping APIs are common to both Win32 and WinRT.
*/
WINBASEAPI BOOL WINAPI FlushViewOfFile(LPCVOID, SIZE_T);
WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID);
#endif /* SQLITE_WIN32_FILEMAPPING_API */
@@ -1083,6 +1085,15 @@ static struct win_syscall {
#define osUuidCreateSequential \
((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[78].pCurrent)
#if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0
{ "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 },
#else
{ "FlushViewOfFile", (SYSCALL)0, 0 },
#endif
#define osFlushViewOfFile \
((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[79].pCurrent)
}; /* End of the overrideable system calls */
/*
@@ -2788,6 +2799,22 @@ static int winSync(sqlite3_file *id, int flags){
osGetCurrentProcessId(), pFile, pFile->h));
return SQLITE_OK;
#else
#if SQLITE_MAX_MMAP_SIZE>0
if( pFile->pMapRegion ){
if( osFlushViewOfFile(pFile->pMapRegion, 0) ){
OSTRACE(("SYNC-MMAP pid=%lu, pFile=%p, pMapRegion=%p, "
"rc=SQLITE_OK\n", osGetCurrentProcessId(),
pFile, pFile->pMapRegion));
}else{
pFile->lastErrno = osGetLastError();
OSTRACE(("SYNC-MMAP pid=%lu, pFile=%p, pMapRegion=%p, "
"rc=SQLITE_IOERR_MMAP\n", osGetCurrentProcessId(),
pFile, pFile->pMapRegion));
return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
"winSync1", pFile->zPath);
}
}
#endif
rc = osFlushFileBuffers(pFile->h);
SimulateIOError( rc=FALSE );
if( rc ){
@@ -2799,7 +2826,7 @@ static int winSync(sqlite3_file *id, int flags){
OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_FSYNC\n",
osGetCurrentProcessId(), pFile, pFile->h));
return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno,
"winSync", pFile->zPath);
"winSync2", pFile->zPath);
}
#endif
}
@@ -5573,7 +5600,7 @@ int sqlite3_os_init(void){
/* Double-check that the aSyscall[] array has been constructed
** correctly. See ticket [bb3a86e890c8e96ab] */
assert( ArraySize(aSyscall)==79 );
assert( ArraySize(aSyscall)==80 );
/* get memory map allocation granularity */
memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));