1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Add Win32 support to the internal threads interface. Also, add several asserts and fix a few typos.

FossilOrigin-Name: 793195d37109c75eba84f7190c8fe0b8722f76f7
This commit is contained in:
mistachkin
2012-07-21 22:49:08 +00:00
parent f51446a38c
commit da0e47109e
5 changed files with 103 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
C Add\san\sinternal\sinterface\sthat\sallows\sthe\scode\sto\stake\sadvantage\sof\smultiple\ncores\sby\spushing\ssubcomputations\soff\sinto\sseparate\sthreads.\s\sThe\sinterface\nis\snot\scurrently\sused.
D 2012-07-21T19:40:42.441
C Add\sWin32\ssupport\sto\sthe\sinternal\sthreads\sinterface.\s\sAlso,\sadd\sseveral\sasserts\sand\sfix\sa\sfew\stypos.
D 2012-07-21T22:49:08.403
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 7a89f9692d1369faa4071310164ffba0504c324d
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -163,7 +163,7 @@ F src/os.c e1acdc09ff3ac2412945cca9766e2dcf4675f31c
F src/os.h c2ebd26a68a4223fe170b003852b97d9e7211498
F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
F src/os_unix.c d7c96b5d140f550f07345870112fae5d7ef99757
F src/os_win.c e3d3d3e26b65a35d4293d753137a58510bd3299b
F src/os_win.c 899783012ed47a756cd4358b43ecfa139cf14ace
F src/pager.c e381c118b77dc22021a1a59d3fec24815e91df78
F src/pager.h 8b8c9bc065a3c66769df8724dfdf492ee1aab3c5
F src/parse.y f29df90bd3adc64b33114ab1de9fb7768fcf2099
@@ -180,7 +180,7 @@ F src/select.c f6c4833c4d8e94714761d99013d74f381e084f1d
F src/shell.c 076e1c90d594644f36027c8ecff9a392cf2d3a06
F src/sqlite.h.in 310ae7e538883fa1619ab0638c775ce11ad43015
F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477
F src/sqliteInt.h 273e9d00296d3a76519c0446698c23787d8951f9
F src/sqliteInt.h 4bb99c73090cde71ea5534d0f9c3ee299a1c10e7
F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
F src/status.c 35939e7e03abf1b7577ce311f48f682c40de3208
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
@@ -231,7 +231,7 @@ F src/test_vfs.c da6d0d982b11756c94c1760196355d33d03ff745
F src/test_vfstrace.c 6b28adb2a0e8ecd0f2e3581482e1f658b11b4067
F src/test_wholenumber.c 3d2b9ed1505c40ad5c5ca2ad16ae7a289d6cc251
F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
F src/threads.c df23fc534a54fe7e1ff935628fa14a9318d27ae3
F src/threads.c 82ea90092f36d02f887e85f7559efc1519f9edd3
F src/tokenize.c 1e86210d3976717a19238ea7b047fac481fe8c12
F src/trigger.c ee7e178fb9188f44b532cebd449a7c1df90fb684
F src/update.c d3076782c887c10e882996550345da9c4c9f9dea
@@ -1006,10 +1006,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
P e4163596339c2166f9c4356ab824fff8bda8d0b0
R e05d278833a84eb0e1d0c443cf6ae5d1
T *branch * threads
T *sym-threads *
T -sym-trunk *
U drh
Z d49696325d34c649ba05b5124d6547e7
P 0e4d977a4a07d6de50acbf022c7dd947998b8d96
R a23a964d0745aaa13c7e5378646293f9
U mistachkin
Z d6738fe175fa5cec50ba76dfb911d019

View File

@@ -1 +1 @@
0e4d977a4a07d6de50acbf022c7dd947998b8d96
793195d37109c75eba84f7190c8fe0b8722f76f7

View File

@@ -945,6 +945,10 @@ void sqlite3_win32_sleep(DWORD milliseconds){
#endif
}
DWORD sqlite3Win32Wait(HANDLE hObject){
return osWaitForSingleObjectEx(hObject, INFINITE, TRUE);
}
/*
** Return true (non-zero) if we are running under WinNT, Win2K, WinXP,
** or WinCE. Return false (zero) for Win95, Win98, or WinME.

View File

@@ -3314,4 +3314,11 @@ SQLITE_EXTERN void (*sqlite3IoTrace)(const char*,...);
int sqlite3ThreadCreate(SQLiteThread**,void*(*)(void*),void*);
int sqlite3ThreadJoin(SQLiteThread*, void**);
/*
** Win32 interface
*/
#if SQLITE_OS_WIN
DWORD sqlite3Win32Wait(HANDLE hObject);
#endif
#endif /* _SQLITEINT_H_ */

View File

@@ -47,19 +47,25 @@ int sqlite3ThreadCreate(
SQLiteThread *p;
int rc;
*ppThread = p = sqlite3Malloc(sizeof(*p));
if( p==0 ) return SQLITE_OK;
assert( ppThread!=0 );
assert( xTask!=0 );
*ppThread = 0;
p = sqlite3Malloc(sizeof(*p));
if( p==0 ) return SQLITE_NOMEM;
rc = pthread_create(&p->tid, 0, xTask, pIn);
if( rc ){
sqlite3_free(p);
return SQLITE_ERROR;
}
*ppThread = p;
return SQLITE_OK;
}
/* Get the results of the thread */
int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){
int rc;
assert( ppOut!=0 );
if( p==0 ) return SQLITE_NOMEM;
rc = pthread_join(p->tid, ppOut);
sqlite3_free(p);
@@ -70,6 +76,71 @@ int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){
/******************************** End Unix Pthreads *************************/
/********************************* Win32 Threads ****************************/
#if SQLITE_OS_WIN && !SQLITE_OS_WINRT
#define SQLITE_THREADS_IMPLEMENTED 1 /* Prevent the single-thread code below */
#include <process.h>
/* A running thread */
struct SQLiteThread {
uintptr_t tid; /* The thread handle */
void *(*xTask)(void*); /* The routine to run as a thread */
void *pIn; /* Argument to xTask */
void *pResult; /* Result of xTask */
};
/* Thread procedure Win32 compatibility shim */
static void sqlite3ThreadProc(
void *pArg /* IN: Pointer to the SQLiteThread structure */
){
SQLiteThread *p = (SQLiteThread *)pArg;
assert( p!=0 );
assert( p->xTask!=0 );
p->pResult = p->xTask(p->pIn);
_endthread();
}
/* Create a new thread */
int sqlite3ThreadCreate(
SQLiteThread **ppThread, /* OUT: Write the thread object here */
void *(*xTask)(void*), /* Routine to run in a separate thread */
void *pIn /* Argument passed into xTask() */
){
SQLiteThread *p;
assert( ppThread!=0 );
assert( xTask!=0 );
*ppThread = 0;
p = sqlite3Malloc(sizeof(*p));
if( p==0 ) return SQLITE_NOMEM;
p->xTask = xTask; p->pIn = pIn;
p->tid = _beginthread(sqlite3ThreadProc, 0, p);
if( p->tid==(uintptr_t)-1 ){
sqlite3_free(p);
return SQLITE_ERROR;
}
*ppThread = p;
return SQLITE_OK;
}
/* Get the results of the thread */
int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){
DWORD rc;
assert( ppOut!=0 );
if( p==0 ) return SQLITE_NOMEM;
rc = sqlite3Win32Wait((HANDLE)p->tid);
if( rc==WAIT_OBJECT_0 ) *ppOut = p->pResult;
sqlite3_free(p);
return (rc==WAIT_OBJECT_0) ? SQLITE_OK : SQLITE_ERROR;
}
#endif /* SQLITE_OS_WIN && !SQLITE_OS_WINRT */
/******************************** End Win32 Threads *************************/
/********************************* Single-Threaded **************************/
#ifndef SQLITE_THREADS_IMPLEMENTED
/*
@@ -92,7 +163,11 @@ int sqlite3ThreadCreate(
void *pIn /* Argument passed into xTask() */
){
SQLiteThread *p;
*ppThread = p = sqlite3Malloc(sizeof(*p));
assert( ppThread!=0 );
assert( xTask!=0 );
*ppThread = 0;
p = sqlite3Malloc(sizeof(*p));
if( p==0 ) return SQLITE_NOMEM;
if( (SQLITE_PTR_TO_INT(p)/17)&1 ){
p->xTask = xTask;
@@ -101,14 +176,16 @@ int sqlite3ThreadCreate(
p->xTask = 0;
p->pResult = xTask(pIn);
}
return p;
*ppThread = p;
return SQLITE_OK;
}
/* Get the results of the thread */
int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){
assert( ppOut!=0 );
if( p==0 ) return SQLITE_NOMEM;
if( p->xTask ){
*ppOut = = p->xTask(p->pIn);
*ppOut = p->xTask(p->pIn);
}else{
*ppOut = p->pResult;
}