]> git.saurik.com Git - wxWidgets.git/blobdiff - src/unix/threadpsx.cpp
allow customization of individual grid lines appearance (patch 1496015)
[wxWidgets.git] / src / unix / threadpsx.cpp
index d7237bb4712ede0f7214211a5cfa53065ba6113c..60172047a55aa833df234acdeca3bb34ecdea68a 100644 (file)
 
 #if wxUSE_THREADS
 
 
 #if wxUSE_THREADS
 
+#include "wx/thread.h"
+
 #ifndef WX_PRECOMP
     #include "wx/dynarray.h"
 #ifndef WX_PRECOMP
     #include "wx/dynarray.h"
+    #include "wx/intl.h"
+    #include "wx/log.h"
+    #include "wx/utils.h"
+    #include "wx/timer.h"
+    #include "wx/stopwatch.h"
+    #include "wx/module.h"
 #endif
 
 #endif
 
-#include "wx/thread.h"
-#include "wx/module.h"
-#include "wx/utils.h"
-#include "wx/log.h"
-#include "wx/intl.h"
-#include "wx/timer.h"
-#include "wx/stopwatch.h"
-
 #include <stdio.h>
 #include <unistd.h>
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <pthread.h>
@@ -112,6 +112,9 @@ WX_DEFINE_ARRAY_PTR(wxThread *, wxArrayThread);
 // be left in memory
 static wxArrayThread gs_allThreads;
 
 // be left in memory
 static wxArrayThread gs_allThreads;
 
+// a mutex to protect gs_allThreads
+static wxMutex *gs_mutexAllThreads = NULL;
+
 // the id of the main thread
 static pthread_t gs_tidMain = (pthread_t)-1;
 
 // the id of the main thread
 static pthread_t gs_tidMain = (pthread_t)-1;
 
@@ -1065,7 +1068,11 @@ bool wxThread::SetConcurrency(size_t level)
 wxThread::wxThread(wxThreadKind kind)
 {
     // add this thread to the global list of all threads
 wxThread::wxThread(wxThreadKind kind)
 {
     // add this thread to the global list of all threads
-    gs_allThreads.Add(this);
+    {
+        wxMutexLocker lock(*gs_mutexAllThreads);
+
+        gs_allThreads.Add(this);
+    }
 
     m_internal = new wxThreadInternal();
 
 
     m_internal = new wxThreadInternal();
 
@@ -1547,7 +1554,11 @@ wxThread::~wxThread()
     delete m_internal;
 
     // remove this thread from the global array
     delete m_internal;
 
     // remove this thread from the global array
-    gs_allThreads.Remove(this);
+    {
+        wxMutexLocker lock(*gs_mutexAllThreads);
+
+        gs_allThreads.Remove(this);
+    }
 }
 
 // -----------------------------------------------------------------------------
 }
 
 // -----------------------------------------------------------------------------
@@ -1611,11 +1622,13 @@ bool wxThreadModule::OnInit()
 
     gs_tidMain = pthread_self();
 
 
     gs_tidMain = pthread_self();
 
+    gs_mutexAllThreads = new wxMutex();
+
     gs_mutexGui = new wxMutex();
     gs_mutexGui->Lock();
 
     gs_mutexDeleteThread = new wxMutex();
     gs_mutexGui = new wxMutex();
     gs_mutexGui->Lock();
 
     gs_mutexDeleteThread = new wxMutex();
-    gs_condAllDeleted = new wxCondition( *gs_mutexDeleteThread );
+    gs_condAllDeleted = new wxCondition(*gs_mutexDeleteThread);
 
     return true;
 }
 
     return true;
 }
@@ -1642,13 +1655,19 @@ void wxThreadModule::OnExit()
         }
     }
 
         }
     }
 
-    // terminate any threads left
-    size_t count = gs_allThreads.GetCount();
-    if ( count != 0u )
+    size_t count;
+
     {
     {
-        wxLogDebug(wxT("%lu threads were not terminated by the application."),
-                   (unsigned long)count);
-    }
+        wxMutexLocker lock(*gs_mutexAllThreads);
+
+        // terminate any threads left
+        count = gs_allThreads.GetCount();
+        if ( count != 0u )
+        {
+            wxLogDebug(wxT("%lu threads were not terminated by the application."),
+                       (unsigned long)count);
+        }
+    } // unlock mutex before deleting the threads as they lock it in their dtor
 
     for ( size_t n = 0u; n < count; n++ )
     {
 
     for ( size_t n = 0u; n < count; n++ )
     {
@@ -1657,6 +1676,8 @@ void wxThreadModule::OnExit()
         gs_allThreads[0]->Delete();
     }
 
         gs_allThreads[0]->Delete();
     }
 
+    delete gs_mutexAllThreads;
+
     // destroy GUI mutex
     gs_mutexGui->Unlock();
     delete gs_mutexGui;
     // destroy GUI mutex
     gs_mutexGui->Unlock();
     delete gs_mutexGui;