diff --git a/manifest b/manifest index 57619c3f91..635f1985a7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Cleanup\sthe\sWindows\ssyscall\stable,\sremoving\sthe\sunused\sCreateFileMapping\sentry. -D 2012-03-13T01:30:20.255 +C Defer\screation\sof\sthe\ssleep\sevent\sobject\suntil\sit\sis\sneeded.\s\sAdded\ssqlite3_win32_write_debug\sand\ssqlite3_win32_sleep\sAPIs\sto\sassist\sin\sportability\sto\sWinRT. +D 2012-03-13T03:35:07.176 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2f37e468503dbe79d35c9f6dffcf3fae1ae9ec20 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -160,14 +160,14 @@ F src/mutex.h 2a79e0c10c26412546b501ee0f3d92b42decf63e F src/mutex_noop.c 7682796b7d8d39bf1c138248858efcd10c9e1553 F src/mutex_os2.c 882d735098c07c8c6a5472b8dd66e19675fe117f F src/mutex_unix.c c3a4e00f96ba068a8dbef34084465979aaf369cc -F src/mutex_w32.c be6dc2be432aa27e1b0d0a19a0da7bace9e4e441 +F src/mutex_w32.c 1170f64d08dc35cd43f6d0bfa833cac5da979279 F src/notify.c 976dd0f6171d4588e89e874fcc765e92914b6d30 F src/os.c e1acdc09ff3ac2412945cca9766e2dcf4675f31c F src/os.h 38aabd5e3ecd4162332076f55bb09cec02165cca F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_os2.c 4a75888ba3dfc820ad5e8177025972d74d7f2440 F src/os_unix.c 0e3d2942d228d0366fb80a3640f35caf413b66d1 -F src/os_win.c 8e0c3142f06e049cead46bc1d83bbc939f582a67 +F src/os_win.c 30a479f366f206b663d4d5a6c647aa76d18055d0 F src/pager.c 3955b62cdb5bb64559607cb474dd12a6c8e1d4a5 F src/pager.h ef1eaf8593e78f73885c1dfac27ad83bee23bdc5 F src/parse.y 1ddd71ae55f4b7cbb2672526ea4de023de0f519e @@ -992,7 +992,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 -P 6b997d9c32076c480ff4f101ff93bae3f443e252 -R 6cc20b48ffd82e276454874a3dd9ea0d +P fb7d8bf6ec5c0ef9a948bc14c28770e34f57db1a +R 4746d41be07bb3c220103324ba770fee U mistachkin -Z b8edd09153177d0ea866248aa43a320b +Z d05d3c51b5da1f2a8562520fe1f66220 diff --git a/manifest.uuid b/manifest.uuid index 85fee2b70b..98bbae7cfa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fb7d8bf6ec5c0ef9a948bc14c28770e34f57db1a \ No newline at end of file +7af88ad306612dd316827c506dbf8df7477b2ec1 \ No newline at end of file diff --git a/src/mutex_w32.c b/src/mutex_w32.c index 4c3855faf4..3717900608 100644 --- a/src/mutex_w32.c +++ b/src/mutex_w32.c @@ -109,6 +109,8 @@ static int winMutex_isInit = 0; */ static long winMutex_lock = 0; +extern void sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */ + static int winMutexInit(void){ /* The first to increment to 1 does actual initialization */ if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){ @@ -124,11 +126,7 @@ static int winMutexInit(void){ }else{ /* Someone else is in the process of initing the static mutexes */ while( !winMutex_isInit ){ -#if SQLITE_OS_WINRT - Yield(); /* NOP */ -#else - Sleep(1); -#endif + sqlite3_win32_sleep(1); } } return SQLITE_OK; diff --git a/src/os_win.c b/src/os_win.c index 35e3634e6f..3f676c7df6 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -24,6 +24,13 @@ */ #include "os_common.h" +/* +** Macro to find the minimum of two numeric values. +*/ +#ifndef MIN +# define MIN(x,y) ((x)<(y)?(x):(y)) +#endif + /* ** Some Microsoft compilers lack this definition. */ @@ -87,6 +94,13 @@ struct winFile { #define WINFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */ #define WINFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */ +/* + * The size of the buffer used by sqlite3_win32_write_debug(). + */ +#ifndef SQLITE_WIN32_DBG_BUF_SIZE +# define SQLITE_WIN32_DBG_BUF_SIZE (4096-sizeof(DWORD)) +#endif + /* * If compiled with SQLITE_WIN32_MALLOC on Windows, we will use the * various Win32 API heap functions instead of our own. @@ -748,6 +762,22 @@ static struct win_syscall { #define osGetNativeSystemInfo ((VOID(WINAPI*)( \ LPSYSTEM_INFO))aSyscall[68].pCurrent) +#if defined(SQLITE_WIN32_HAS_ANSI) + { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 }, +#else + { "OutputDebugStringA", (SYSCALL)0, 0 }, +#endif + +#define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[69].pCurrent) + +#if defined(SQLITE_WIN32_HAS_WIDE) + { "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 }, +#else + { "OutputDebugStringW", (SYSCALL)0, 0 }, +#endif + +#define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[70].pCurrent) + }; /* End of the overrideable system calls */ /* @@ -834,20 +864,62 @@ static const char *winNextSystemCall(sqlite3_vfs *p, const char *zName){ } /* -** The following routine Suspends the thread for at least ms milliseconds. This is equivalent -** to the win32 Sleep() interface. +** This function outputs the specified (ANSI) string to the Win32 debugger +** (if available). +*/ + +void sqlite3_win32_write_debug(char *zBuf, int nBuf){ + char zDbgBuf[SQLITE_WIN32_DBG_BUF_SIZE]; + int nMin = MIN(nBuf,SQLITE_WIN32_DBG_BUF_SIZE-1); /* may be negative. */ + if( nMin<-1 ) nMin = -1; /* all negative values become -1. */ +#if defined(SQLITE_WIN32_HAS_ANSI) + if( nMin>0 ){ + memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE); + memcpy(zDbgBuf, zBuf, nMin); + OutputDebugStringA(zDbgBuf); + }else{ + OutputDebugStringA(zBuf); + } +#elif defined(SQLITE_WIN32_HAS_WIDE) + memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE); + if ( osMultiByteToWideChar( + osAreFileApisANSI() ? CP_ACP : CP_OEMCP, 0, zBuf, + nMin, zDbgBuf, SQLITE_WIN32_DBG_BUF_SIZE/sizeof(WCHAR))<=0 ){ + return; + } + OutputDebugStringW(zDbgBuf); +#else + if( nMin>0 ){ + memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE); + memcpy(zDbgBuf, zBuf, nMin); + fprintf(stderr, "%s", zDbgBuf); + }else{ + fprintf(stderr, "%s", zBuf); + } +#endif +} + +/* +** The following routine suspends the current thread for at least ms +** milliseconds. This is equivalent to the Win32 Sleep() interface. */ #if SQLITE_OS_WINRT -static HANDLE sleepObj; -static void portableSleep(int ms){ - osWaitForSingleObjectEx(sleepObj, ms, FALSE); -} -#else -static void portableSleep(int ms){ - osSleep(ms); -} +static HANDLE sleepObj = NULL; #endif +void sqlite3_win32_sleep(DWORD milliseconds){ +#if SQLITE_OS_WINRT + if ( sleepObj==NULL ){ + sleepObj = osCreateEventExW(NULL, NULL, CREATE_EVENT_MANUAL_RESET, + SYNCHRONIZE); + } + assert( sleepObj!=NULL ); + osWaitForSingleObjectEx(sleepObj, milliseconds, FALSE); +#else + osSleep(milliseconds); +#endif +} + /* ** Return true (non-zero) if we are running under WinNT, Win2K, WinXP, ** or WinCE. Return false (zero) for Win95, Win98, or WinME. @@ -1351,7 +1423,7 @@ static int retryIoerr(int *pnRetry, DWORD *pError){ if( e==ERROR_ACCESS_DENIED || e==ERROR_LOCK_VIOLATION || e==ERROR_SHARING_VIOLATION ){ - portableSleep(win32IoerrRetryDelay*(1+*pnRetry)); + sqlite3_win32_sleep(win32IoerrRetryDelay*(1+*pnRetry)); ++*pnRetry; return 1; } @@ -1824,7 +1896,7 @@ static int winClose(sqlite3_file *id){ do{ rc = osCloseHandle(pFile->h); /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */ - }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (portableSleep(100), 1) ); + }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) ); #if SQLITE_OS_WINCE #define WINCE_DELETION_ATTEMPTS 3 winceDestroyLock(pFile); @@ -1835,7 +1907,7 @@ static int winClose(sqlite3_file *id){ && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff && cnt++ < WINCE_DELETION_ATTEMPTS ){ - portableSleep(100); /* Wait a little before trying again */ + sqlite3_win32_sleep(100); /* Wait a little before trying again */ } sqlite3_free(pFile->zDeleteOnClose); } @@ -2238,7 +2310,7 @@ static int winLock(sqlite3_file *id, int locktype){ ** copy this retry logic. It is a hack intended for Windows only. */ OSTRACE(("could not get a PENDING lock. cnt=%d\n", cnt)); - if( cnt ) portableSleep(1); + if( cnt ) sqlite3_win32_sleep(1); } gotPendingLock = res; if( !res ){ @@ -3819,7 +3891,7 @@ static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){ ** Sleep for a little while. Return the amount of time slept. */ static int winSleep(sqlite3_vfs *pVfs, int microsec){ - portableSleep((microsec+999)/1000); + sqlite3_win32_sleep((microsec+999)/1000); UNUSED_PARAMETER(pVfs); return ((microsec+999)/1000)*1000; } @@ -3961,12 +4033,7 @@ int sqlite3_os_init(void){ /* Double-check that the aSyscall[] array has been constructed ** correctly. See ticket [bb3a86e890c8e96ab] */ - assert( ArraySize(aSyscall)==70 ); - -#if SQLITE_OS_WINRT - sleepObj = osCreateEventExW(NULL, NULL, CREATE_EVENT_MANUAL_RESET, - SYNCHRONIZE); -#endif + assert( ArraySize(aSyscall)==71 ); #ifndef SQLITE_OMIT_WAL /* get memory map allocation granularity */ @@ -3985,8 +4052,10 @@ int sqlite3_os_init(void){ int sqlite3_os_end(void){ #if SQLITE_OS_WINRT - osCloseHandle(sleepObj); - sleepObj = NULL; + if( sleepObj != NULL ){ + osCloseHandle(sleepObj); + sleepObj = NULL; + } #endif return SQLITE_OK; }