diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/os_win.c | 33 | ||||
-rw-r--r-- | src/test1.c | 26 |
2 files changed, 41 insertions, 18 deletions
diff --git a/src/os_win.c b/src/os_win.c index 0ca5db6b4..a006627bf 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -2191,6 +2191,7 @@ static int winOpen( winFile *pFile = (winFile*)id; void *zConverted; /* Filename in OS encoding */ const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */ + int cnt = 0; /* If argument zPath is a NULL pointer, this function is required to open ** a temporary file. Use this buffer to store the file name in. @@ -2310,31 +2311,31 @@ static int winOpen( #endif if( isNT() ){ - h = CreateFileW((WCHAR*)zConverted, - dwDesiredAccess, - dwShareMode, - NULL, - dwCreationDisposition, - dwFlagsAndAttributes, - NULL - ); + while( (h = CreateFileW((WCHAR*)zConverted, + dwDesiredAccess, + dwShareMode, NULL, + dwCreationDisposition, + dwFlagsAndAttributes, + NULL))==INVALID_HANDLE_VALUE && + retryIoerr(&cnt) ){} /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. ** Since the ASCII version of these Windows API do not exist for WINCE, ** it's important to not reference them for WINCE builds. */ #if SQLITE_OS_WINCE==0 }else{ - h = CreateFileA((char*)zConverted, - dwDesiredAccess, - dwShareMode, - NULL, - dwCreationDisposition, - dwFlagsAndAttributes, - NULL - ); + while( (h = CreateFileA((char*)zConverted, + dwDesiredAccess, + dwShareMode, NULL, + dwCreationDisposition, + dwFlagsAndAttributes, + NULL))==INVALID_HANDLE_VALUE && + retryIoerr(&cnt) ){} #endif } + logIoerr(cnt); + OSTRACE(("OPEN %d %s 0x%lx %s\n", h, zName, dwDesiredAccess, h==INVALID_HANDLE_VALUE ? "failed" : "ok")); diff --git a/src/test1.c b/src/test1.c index 9a5a50103..3b933ba68 100644 --- a/src/test1.c +++ b/src/test1.c @@ -5645,6 +5645,7 @@ static int test_test_control( ** background thread. */ struct win32FileLocker { + char *evName; /* Name of event to signal thread startup */ HANDLE h; /* Handle of the file to be locked */ int delay1; /* Delay before locking */ int delay2; /* Delay before unlocking */ @@ -5660,6 +5661,13 @@ struct win32FileLocker { */ static void win32_file_locker(void *pAppData){ struct win32FileLocker *p = (struct win32FileLocker*)pAppData; + if( p->evName ){ + HANDLE ev = OpenEvent(EVENT_MODIFY_STATE, FALSE, p->evName); + if ( ev ){ + SetEvent(ev); + CloseHandle(ev); + } + } if( p->delay1 ) Sleep(p->delay1); if( LockFile(p->h, 0, 0, 100000000, 0) ){ Sleep(p->delay2); @@ -5688,16 +5696,18 @@ static int win32_file_lock( int objc, Tcl_Obj *CONST objv[] ){ - static struct win32FileLocker x = { 0, 0, 0 }; + static struct win32FileLocker x = { "win32_file_lock", 0, 0, 0, 0, 0 }; const char *zFilename; + char zBuf[200]; int retry = 0; + HANDLE ev; + DWORD wResult; if( objc!=4 && objc!=1 ){ Tcl_WrongNumArgs(interp, 1, objv, "FILENAME DELAY1 DELAY2"); return TCL_ERROR; } if( objc==1 ){ - char zBuf[200]; sqlite3_snprintf(sizeof(zBuf), zBuf, "%d %d %d %d %d", x.ok, x.err, x.delay1, x.delay2, x.h); Tcl_AppendResult(interp, zBuf, (char*)0); @@ -5721,8 +5731,20 @@ static int win32_file_lock( Tcl_AppendResult(interp, "cannot open file: ", zFilename, (char*)0); return TCL_ERROR; } + ev = CreateEvent(NULL, TRUE, FALSE, x.evName); + if ( !ev ){ + Tcl_AppendResult(interp, "cannot create event: ", x.evName, (char*)0); + return TCL_ERROR; + } _beginthread(win32_file_locker, 0, (void*)&x); Sleep(0); + if ( (wResult = WaitForSingleObject(ev, 10000))!=WAIT_OBJECT_0 ){ + sqlite3_snprintf(sizeof(zBuf), zBuf, "0x%x", wResult); + Tcl_AppendResult(interp, "wait failed: ", zBuf, (char*)0); + CloseHandle(ev); + return TCL_ERROR; + } + CloseHandle(ev); return TCL_OK; } #endif |