From: Alexander P. <ale...@us...> - 2008-10-29 17:05:36
|
Build Version : T2.5.0.21249 Firebird 2.5 Alpha 1 (writeBuildNum.sh,v 1.21410 2008/10/29 17:05:22 alexpeshkof ) Update of /cvsroot/firebird/firebird2/src/jrd In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv915/jrd Modified Files: ThreadStart.cpp ThreadStart.h svc.cpp svc.h why.cpp Log Message: Fixed CORE-2158: AV in client/embedded library when unloading it Index: ThreadStart.cpp =================================================================== RCS file: /cvsroot/firebird/firebird2/src/jrd/ThreadStart.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -b -U3 -r1.7 -r1.8 --- ThreadStart.cpp 10 Oct 2008 15:58:04 -0000 1.7 +++ ThreadStart.cpp 29 Oct 2008 17:05:22 -0000 1.8 @@ -177,21 +177,33 @@ if (state) Firebird::system_call_failed::raise("pthread_attr_init", state); - pthread_attr_setscope(&pattr, PTHREAD_SCOPE_SYSTEM); + state = pthread_attr_setscope(&pattr, PTHREAD_SCOPE_SYSTEM); + if (state) + Firebird::system_call_failed::raise("pthread_attr_setscope", state); - pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_DETACHED); + if (!thd_id) + { + state = pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_DETACHED); + if (state) + Firebird::system_call_failed::raise("pthread_attr_setdetachstate", state); + } state = pthread_create(&thread, &pattr, THREAD_ENTRYPOINT, THREAD_ARG); - pthread_attr_destroy(&pattr); + int state2 = pthread_attr_destroy(&pattr); if (state) Firebird::system_call_failed::raise("pthread_create", state); + if (state2) + Firebird::system_call_failed::raise("pthread_attr_destroy", state2); #else #if ( defined LINUX || defined FREEBSD ) if (state = pthread_create(&thread, NULL, THREAD_ENTRYPOINT, THREAD_ARG)) Firebird::system_call_failed::raise("pthread_create", state); + if (!thd_id) + { if (state = pthread_detach(thread)) Firebird::system_call_failed::raise("pthread_detach", state); + } #else @@ -224,15 +236,38 @@ if (state) Firebird::system_call_failed::raise("pthread_create", state); + if (!thd_id) + { state = pthread_detach(&thread); if (state) Firebird::system_call_failed::raise("pthread_detach", state); + } + state = pthread_attr_delete(&pattr); if (state) Firebird::system_call_failed::raise("pthread_attr_delete", state); #endif /* linux */ #endif /* HP10 */ + + if (thd_id) + { + *static_cast<pthread_t*>(thd_id) = thread; + } +} + +void THD_detach(ThreadHandle& thread) +{ + int state = pthread_detach(thread); + if (state) + Firebird::system_call_failed::raise("pthread_detach", state); +} + +void THD_wait_for_completion(ThreadHandle& thread) +{ + int state = pthread_join(thread, NULL); + if (state) + Firebird::system_call_failed::raise("pthread_join", state); } #endif /* USE_POSIX_THREADS */ @@ -349,6 +384,16 @@ CloseHandle(handle); } } + +void THD_detach(ThreadHandle& handle) +{ + CloseHandle(handle); +} + +void THD_wait_for_completion(ThreadHandle& handle) +{ + WaitForSingleObject(handle, INFINITE); +} #endif // WIN_NT Index: ThreadStart.h =================================================================== RCS file: /cvsroot/firebird/firebird2/src/jrd/ThreadStart.h,v retrieving revision 1.3 retrieving revision 1.4 diff -b -U3 -r1.3 -r1.4 --- ThreadStart.h 6 Jun 2008 15:51:40 -0000 1.3 +++ ThreadStart.h 29 Oct 2008 17:05:22 -0000 1.4 @@ -62,4 +62,14 @@ int API_ROUTINE gds__thread_start(ThreadEntryPoint*, void*, int, int, void*); } +#ifdef WIN_NT +typedef HANDLE ThreadHandle; +#endif +#ifdef USE_POSIX_THREADS +typedef pthread_t ThreadHandle; +#endif + +void THD_detach(ThreadHandle& handle); +void THD_wait_for_completion(ThreadHandle& handle); + #endif // JRD_THREADSTART_H Index: svc.cpp =================================================================== RCS file: /cvsroot/firebird/firebird2/src/jrd/svc.cpp,v retrieving revision 1.242 retrieving revision 1.243 diff -b -U3 -r1.242 -r1.243 --- svc.cpp 16 Sep 2008 14:18:51 -0000 1.242 +++ svc.cpp 29 Oct 2008 17:05:22 -0000 1.243 @@ -844,9 +844,11 @@ Service::~Service() { -#ifdef WIN_NT - CloseHandle((HANDLE) svc_handle); -#endif + if (svc_handle) + { + THD_detach(svc_handle); + svc_handle = 0; + } MutexLockGuard guard(svc_mutex); AllServices& all(allServices); @@ -1855,7 +1857,7 @@ svc_flags |= SVC_thd_running; } - gds__thread_start(serv->serv_thd, this, THREAD_medium, 0, (void *) &svc_handle); + gds__thread_start(serv->serv_thd, this, THREAD_medium, 0, &svc_handle); // Check for the service being detached. This will prevent the thread // from waiting infinitely if the client goes away. @@ -1984,7 +1986,7 @@ argv[0] = svc_service->serv_name; } - gds__thread_start(service_thread, this, THREAD_medium, 0, (void*) &svc_handle); + gds__thread_start(service_thread, this, THREAD_medium, 0, &svc_handle); } @@ -2074,13 +2076,13 @@ if (svc_flags & SVC_finished) { svc_flags &= ~SVC_thd_running; - -#ifdef WIN_NT - CloseHandle((HANDLE) svc_handle); -#endif + if (svc_handle) + { + THD_detach(svc_handle); svc_handle = 0; } } + } } Index: svc.h =================================================================== RCS file: /cvsroot/firebird/firebird2/src/jrd/svc.h,v retrieving revision 1.66 retrieving revision 1.67 diff -b -U3 -r1.66 -r1.67 --- svc.h 10 Oct 2008 15:58:04 -0000 1.66 +++ svc.h 29 Oct 2008 17:05:22 -0000 1.67 @@ -200,7 +200,7 @@ private: ISC_STATUS_ARRAY svc_status; // status vector for running service Firebird::string svc_parsed_sw; // Here point elements of argv - SLONG svc_handle; // "handle" of thread running service + ThreadHandle svc_handle; // "handle" of thread running service ULONG svc_stdout_head; ULONG svc_stdout_tail; UCHAR svc_stdout[SVC_STDOUT_BUFFER_SIZE + 1]; // output from service Index: why.cpp =================================================================== RCS file: /cvsroot/firebird/firebird2/src/jrd/why.cpp,v retrieving revision 1.216 retrieving revision 1.217 diff -b -U3 -r1.216 -r1.217 --- why.cpp 16 Oct 2008 02:31:49 -0000 1.216 +++ why.cpp 29 Oct 2008 17:05:22 -0000 1.217 @@ -830,7 +830,7 @@ fb_shutdown(SHUTDOWN_TIMEOUT, fb_shutrsn_exit_called); } - GlobalPtr<SignalSafeSemaphore> shutdownSemaphore, shutdownFini; + GlobalPtr<SignalSafeSemaphore> shutdownSemaphore; THREAD_ENTRY_DECLARE shutdownThread(THREAD_ENTRY_PARAM) { @@ -865,7 +865,6 @@ } } - shutdownFini->release(); return 0; } @@ -899,7 +898,7 @@ { InstanceControl::registerShutdown(atExitShutdown); - gds__thread_start(shutdownThread, 0, 0, 0, 0); + gds__thread_start(shutdownThread, 0, 0, 0, &handle); procInt = ISC_signal(SIGINT, handlerInt, 0); procTerm = ISC_signal(SIGTERM, handlerTerm, 0); @@ -914,9 +913,11 @@ { // must be done to let shutdownThread close shutdownSemaphore->release(); - shutdownFini->enter(); + THD_wait_for_completion(handle); } } + private: + ThreadHandle handle; }; #endif //UNIX |