]> git.saurik.com Git - wxWidgets.git/commitdiff
use critical section to protect global TablesInUse (patch 1660652)
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 7 Mar 2007 21:28:05 +0000 (21:28 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 7 Mar 2007 21:28:05 +0000 (21:28 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44642 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/db.cpp
src/common/dbtable.cpp

index 5e37eaf86051b7fe12142043d66cf2d2d06bab4c..a881c22c4c32ff5dd3548b4d4b7b68ebc61e5d96 100644 (file)
@@ -63,6 +63,7 @@ wxChar const *SQL_CATALOG_FILENAME     = wxT("catalog.txt");
 
 #ifdef __WXDEBUG__
     extern wxList TablesInUse;
+    extern wxCriticalSection csTablesInUse;
 #endif
 
 // SQL Log defaults to be used by GetDbConnection
@@ -1746,21 +1747,24 @@ void wxDb::Close(void)
     wxASSERT(nTables == 0);
 
 #ifdef __WXDEBUG__
-    wxTablesInUse *tiu;
-    wxList::compatibility_iterator pNode;
-    pNode = TablesInUse.GetFirst();
-    wxString s,s2;
-    while (pNode)
     {
-        tiu = (wxTablesInUse *)pNode->GetData();
-        if (tiu->pDb == this)
+        wxCriticalSectionLocker lock(csTablesInUse);
+        wxTablesInUse *tiu;
+        wxList::compatibility_iterator pNode;
+        pNode = TablesInUse.GetFirst();
+        wxString s,s2;
+        while (pNode)
         {
-            s.Printf(wxT("(%-20s)     tableID:[%6lu]     pDb:[%p]"),
-                     tiu->tableName, tiu->tableID, wx_static_cast(void*, tiu->pDb));
-            s2.Printf(wxT("Orphaned table found using pDb:[%p]"), wx_static_cast(void*, this));
-            wxLogDebug(s.c_str(),s2.c_str());
+            tiu = (wxTablesInUse *)pNode->GetData();
+            if (tiu->pDb == this)
+            {
+                s.Printf(wxT("(%-20s)     tableID:[%6lu]     pDb:[%p]"),
+                        tiu->tableName, tiu->tableID, wx_static_cast(void*, tiu->pDb));
+                s2.Printf(wxT("Orphaned table found using pDb:[%p]"), wx_static_cast(void*, this));
+                wxLogDebug(s.c_str(),s2.c_str());
+            }
+            pNode = pNode->GetNext();
         }
-        pNode = pNode->GetNext();
     }
 #endif
 
@@ -2306,7 +2310,6 @@ bool wxDb::ExecSql(const wxString &pSqlStmt, wxDbColInf** columns, short& numcol
             return false;
         }
 
-        pColInf[colNum].sqlDataType = Sqllen;
         switch (Sqllen)
         {
 #if wxUSE_UNICODE
index 7c76c5480dea254996684cdc409989271a34347e..2596771ee701e0324d4d7400d4abca046589a453 100644 (file)
@@ -60,6 +60,7 @@ ULONG lastTableID = 0;
 
 #ifdef __WXDEBUG__
     wxList TablesInUse;
+    wxCriticalSection csTablesInUse;
 #endif
 
 
@@ -182,7 +183,10 @@ bool wxDbTable::initialize(wxDb *pwxDb, const wxString &tblName, const UWORD num
     tableInUse->tableName = tblName;
     tableInUse->tableID   = tableID;
     tableInUse->pDb       = pDb;
-    TablesInUse.Append(tableInUse);
+    {
+        wxCriticalSectionLocker lock(csTablesInUse);
+        TablesInUse.Append(tableInUse);
+    }
 #endif
 
     pDb->WriteSqlLog(s);
@@ -308,17 +312,20 @@ void wxDbTable::cleanup()
         bool found = false;
 
         wxList::compatibility_iterator pNode;
-        pNode = TablesInUse.GetFirst();
-        while (pNode && !found)
         {
-            if (((wxTablesInUse *)pNode->GetData())->tableID == tableID)
+            wxCriticalSectionLocker lock(csTablesInUse);
+            pNode = TablesInUse.GetFirst();
+            while (!found && pNode)
             {
-                found = true;
-                delete (wxTablesInUse *)pNode->GetData();
-                TablesInUse.Erase(pNode);
+                if (((wxTablesInUse *)pNode->GetData())->tableID == tableID)
+                {
+                    found = true;
+                    delete (wxTablesInUse *)pNode->GetData();
+                    TablesInUse.Erase(pNode);
+                }
+                else
+                    pNode = pNode->GetNext();
             }
-            else
-                pNode = pNode->GetNext();
         }
         if (!found)
         {