1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-05 15:55:57 +03:00

Make the Win32 thread handles are available after the threads exit.

FossilOrigin-Name: 565c5af7a75ad5c759ce1a61dab3a61c42819644
This commit is contained in:
mistachkin
2014-07-29 16:37:53 +00:00
parent 19f30dc171
commit b1ac2bc8da
4 changed files with 30 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
C Fix\sthe\sthreads\sbuild\son\sWindows\swhen\sSQLITE_MAX_WORKER_THREADS\sis\sgreater\nthan\s0. C Make\sthe\sWin32\sthread\shandles\sare\savailable\safter\sthe\sthreads\sexit.
D 2014-07-29T15:18:00.197 D 2014-07-29T16:37:53.918
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in cf57f673d77606ab0f2d9627ca52a9ba1464146a F Makefile.in cf57f673d77606ab0f2d9627ca52a9ba1464146a
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -208,7 +208,7 @@ F src/os.h 60d419395e32a8029fa380a80a3da2e9030f635e
F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa
F src/os_unix.c a7baf1b30f3c58ba20b813e01aab23b18ae44f85 F src/os_unix.c a7baf1b30f3c58ba20b813e01aab23b18ae44f85
F src/os_win.c 047e903174b018c50f425be793eafa8d849737a9 F src/os_win.c 5f8c5568cc749d6ab44006124e7701f463559223
F src/os_win.h 057344a6720b4c8405d9bd98f58cb37a6ee46c25 F src/os_win.h 057344a6720b4c8405d9bd98f58cb37a6ee46c25
F src/pager.c f6bb1fa6cdf2062f2d8aec3e64db302bca519ab8 F src/pager.c f6bb1fa6cdf2062f2d8aec3e64db302bca519ab8
F src/pager.h ffd5607f7b3e4590b415b007a4382f693334d428 F src/pager.h ffd5607f7b3e4590b415b007a4382f693334d428
@@ -277,7 +277,7 @@ F src/test_thread.c 1e133a40b50e9c035b00174035b846e7eef481cb
F src/test_vfs.c f84075a388527892ff184988f43b69ce69b8083c F src/test_vfs.c f84075a388527892ff184988f43b69ce69b8083c
F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698 F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698
F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
F src/threads.c 28c72cb7818fea8df83116c54d774e9541e60121 F src/threads.c dfc566f8b5744914bb3e6fe77b5ed63037b9b35d
F src/tokenize.c ae45399d6252b4d736af43bee1576ce7bff86aec F src/tokenize.c ae45399d6252b4d736af43bee1576ce7bff86aec
F src/trigger.c 66f3470b03b52b395e839155786966e3e037fddb F src/trigger.c 66f3470b03b52b395e839155786966e3e037fddb
F src/update.c 01564b3c430f6c7b0a35afaf7aba7987206fa3a5 F src/update.c 01564b3c430f6c7b0a35afaf7aba7987206fa3a5
@@ -1189,7 +1189,8 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P b2f7eb3cc27ecf9a6a88907991148bca1a7d54b3 P f37db3a03d95b508066745613029b7dd1240b31c
R d111ee75a275c87deb7a4599506773e2 Q -2773a5f9879a106a89a3d0bc3c5bfdcb2fe43c7c
U drh R 3e55555e18d084a6f84ef756240b91ed
Z e24fba9313c2b62a7de12b4c1acec1ff U mistachkin
Z e9ccfd5ccb7ae9590b75500531d4b897

View File

@@ -1 +1 @@
f37db3a03d95b508066745613029b7dd1240b31c 565c5af7a75ad5c759ce1a61dab3a61c42819644

View File

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

View File

@@ -100,21 +100,25 @@ int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){
/* A running thread */ /* A running thread */
struct SQLiteThread { struct SQLiteThread {
uintptr_t tid; /* The thread handle */ uintptr_t tid; /* The thread handle */
unsigned id; /* The thread identifier */
void *(*xTask)(void*); /* The routine to run as a thread */ void *(*xTask)(void*); /* The routine to run as a thread */
void *pIn; /* Argument to xTask */ void *pIn; /* Argument to xTask */
void *pResult; /* Result of xTask */ void *pResult; /* Result of xTask */
}; };
/* Thread procedure Win32 compatibility shim */ /* Thread procedure Win32 compatibility shim */
static void sqlite3ThreadProc( static unsigned __stdcall sqlite3ThreadProc(
void *pArg /* IN: Pointer to the SQLiteThread structure */ void *pArg /* IN: Pointer to the SQLiteThread structure */
){ ){
SQLiteThread *p = (SQLiteThread *)pArg; SQLiteThread *p = (SQLiteThread *)pArg;
assert( p!=0 ); assert( p!=0 );
assert( p->id==GetCurrentThreadId() );
assert( p->xTask!=0 ); assert( p->xTask!=0 );
p->pResult = p->xTask(p->pIn); p->pResult = p->xTask(p->pIn);
_endthread();
_endthreadex(0);
return 0; /* NOT REACHED */
} }
/* Create a new thread */ /* Create a new thread */
@@ -135,37 +139,36 @@ int sqlite3ThreadCreate(
}else{ }else{
p->xTask = xTask; p->xTask = xTask;
p->pIn = pIn; p->pIn = pIn;
p->tid = _beginthread(sqlite3ThreadProc, 0, p); p->tid = _beginthreadex(0, 0, sqlite3ThreadProc, p, 0, &p->id);
if( p->tid==(uintptr_t)-1 ){ if( p->tid==(uintptr_t)-1 ){
memset(p, 0, sizeof(*p)); memset(p, 0, sizeof(*p));
} }
} }
if( p->xTask==0 ){ if( p->xTask==0 ){
p->id = GetCurrentThreadId();
p->pResult = xTask(pIn); p->pResult = xTask(pIn);
} }
*ppThread = p; *ppThread = p;
return SQLITE_OK; return SQLITE_OK;
} }
/* Wait on an object */ DWORD sqlite3Win32Wait(HANDLE hObject); /* os_win.c */
DWORD sqlite3Win32Wait(HANDLE hObject){
DWORD rc;
while( (rc = WaitForSingleObjectEx(hObject, INFINITE,
TRUE))==WAIT_IO_COMPLETION ){}
return rc;
}
/* Get the results of the thread */ /* Get the results of the thread */
int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){ int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){
DWORD rc; DWORD rc;
BOOL bRc;
assert( ppOut!=0 ); assert( ppOut!=0 );
if( p==0 ) return SQLITE_NOMEM; if( p==0 ) return SQLITE_NOMEM;
if( p->xTask==0 ){ if( p->xTask==0 ){
rc = WAIT_OBJECT_0; rc = WAIT_OBJECT_0;
}else{ }else{
assert( p->id!=0 && p->id!=GetCurrentThreadId() );
rc = sqlite3Win32Wait((HANDLE)p->tid); rc = sqlite3Win32Wait((HANDLE)p->tid);
assert( rc!=WAIT_IO_COMPLETION ); assert( rc!=WAIT_IO_COMPLETION );
bRc = CloseHandle((HANDLE)p->tid);
assert( bRc );
} }
if( rc==WAIT_OBJECT_0 ) *ppOut = p->pResult; if( rc==WAIT_OBJECT_0 ) *ppOut = p->pResult;
sqlite3_free(p); sqlite3_free(p);