From 446d4b8a5d08d1af08ebe6baa77088b130bf7018 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 19 Aug 2006 19:37:45 +0000 Subject: [PATCH] Synced threading changes between MySQLX and Sqlite --- dlls/mysqlx/threading.cpp | 2 +- dlls/sqlite/threading.cpp | 28 +++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/dlls/mysqlx/threading.cpp b/dlls/mysqlx/threading.cpp index c38a6a73..e381f2be 100644 --- a/dlls/mysqlx/threading.cpp +++ b/dlls/mysqlx/threading.cpp @@ -17,7 +17,7 @@ void ShutdownThreading() { if (g_pWorker) { - g_pWorker->Stop(false); + g_pWorker->Stop(true); delete g_pWorker; g_pWorker = NULL; } diff --git a/dlls/sqlite/threading.cpp b/dlls/sqlite/threading.cpp index f8d8038b..913575c7 100644 --- a/dlls/sqlite/threading.cpp +++ b/dlls/sqlite/threading.cpp @@ -263,6 +263,7 @@ void OnPluginsLoaded() { g_QueueLock = g_Threader.MakeMutex(); } + g_pWorker = new ThreadWorker(&g_Threader, 250); if (!g_pWorker->Start()) { @@ -307,16 +308,37 @@ void StartFrame() void OnPluginsUnloading() { if (!g_pWorker) + { return; + } g_pWorker->Stop(false); delete g_pWorker; g_pWorker = NULL; + + g_QueueLock->Lock(); + size_t remaining = g_ThreadQueue.size(); + if (remaining) + { + MysqlThread *kmThread; + do + { + kmThread = g_ThreadQueue.front(); + g_ThreadQueue.pop(); + g_QueueLock->Unlock(); + kmThread->Execute(); + kmThread->Invalidate(); + g_FreeThreads.push(kmThread); + g_QueueLock->Lock(); + } while (!g_ThreadQueue.empty()); + } + + g_QueueLock->Unlock(); } /*********************** -* ATOMIC RESULT STUFF * -***********************/ + * ATOMIC RESULT STUFF * + ***********************/ AtomicResult::AtomicResult() { @@ -418,7 +440,7 @@ const char *AtomicResult::GetRaw(unsigned int columnId, size_t *length) const char *AtomicResult::GetStringSafe(unsigned int columnId) { const char *str = GetString(columnId); - + return str ? str : ""; }