]> git.saurik.com Git - wxWidgets.git/commitdiff
* Fixed a memory leak in wxThread
authorGuilhem Lavaux <lavaux@easynet.fr>
Tue, 24 Nov 1998 19:01:20 +0000 (19:01 +0000)
committerGuilhem Lavaux <lavaux@easynet.fr>
Tue, 24 Nov 1998 19:01:20 +0000 (19:01 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1033 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

14 files changed:
src/gtk/threadgui.inc
src/gtk/threadno.cpp
src/gtk/threadpsx.cpp
src/gtk/threadsgi.cpp
src/gtk1/threadgui.inc
src/gtk1/threadno.cpp
src/gtk1/threadpsx.cpp
src/gtk1/threadsgi.cpp
src/motif/thread.cpp
src/msw/thread.cpp
src/qt/threadno.cpp
src/qt/threadpsx.cpp
src/qt/threadsgi.cpp
src/stubs/thread.cpp

index baa8fe8b763600ca108d905f6a2a8f1c103e26b2..46073d4e0ba1a752c20330ed5f3718cab5838b20 100644 (file)
@@ -79,12 +79,12 @@ void wxMutexGuiLeave()
 
 void wxMutexGuiEnter()
 {
-  wxMainMutex.Lock();
+  wxMainMutex->Lock();
 }
 
 void wxMutexGuiLeave()
 {
-  wxMainMutex.Unlock();
+  wxMainMutex->Unlock();
 }
 
 #endif
index 3a1f3460c79ef1eebda8b8ab04a806ac84278126..375d2ac6a71964732fbf8abb993ef5bf27b25125 100644 (file)
@@ -138,7 +138,7 @@ bool wxThread::IsAlive() const
 void wxThread::SetPriority(int WXUNUSED(prio)) { }
 int wxThread::GetPriority() const { return 0; }
 
-wxMutex wxMainMutex; // controls access to all GUI functions
+wxMutex *wxMainMutex; // controls access to all GUI functions
 
 wxThread::wxThread()
 {
@@ -168,13 +168,15 @@ public:
 };
 
 bool wxThreadModule::OnInit() {
-  wxMainMutex.Lock();
+  wxMainMutex = new wxMutex();
+  wxMainMutex->Lock();
   return TRUE;
 }
 
 void wxThreadModule::OnExit()
 {
-  wxMainMutex.Unlock();
+  wxMainMutex->Unlock();
+  delete wxMainMutex;
 }
 
 IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
index 9623b91c303a63aeef06bf525e80071857d1b9bf..2d4912c05a32cd4b4d73b2e94867c8a081ba277d 100644 (file)
@@ -37,7 +37,7 @@ static pthread_t p_mainid;
 static wxMutex p_list_mutex;
 static wxList p_threads_list;
 
-wxMutex wxMainMutex; // controls access to all GUI functions
+wxMutex *wxMainMutex; // controls access to all GUI functions
 
 /////////////////////////////////////////////////////////////////////////////
 // GUI thread manager
@@ -288,10 +288,10 @@ void *wxThread::Join()
       wxYield();
 
     if (do_unlock)
-      wxMainMutex.Unlock();
+      wxMainMutex->Unlock();
     pthread_join(p_internal->thread_id, &status);
     if (do_unlock)
-      wxMainMutex.Lock();
+      wxMainMutex->Lock();
 
     p_list_mutex.Lock();
     delete p_threads_list.Nth(p_internal->id);
@@ -377,17 +377,19 @@ class wxThreadModule : public wxModule {
   DECLARE_DYNAMIC_CLASS(wxThreadModule)
 public:
   virtual bool OnInit() {
+    wxMainMutex = new wxMutex();
     wxThreadGuiInit();
     p_mainid = pthread_self();
     p_threads_list = wxList(wxKEY_INTEGER);
-    wxMainMutex.Lock();
+    wxMainMutex->Lock();
 
     return TRUE;
   }
 
   virtual void OnExit() {
-    wxMainMutex.Unlock();
+    wxMainMutex->Unlock();
     wxThreadGuiExit();
+    delete wxMainMutex;
   }
 };
 
index 3503e79616da18ce44d6ac9d691944ef9178a9e1..66b6b0da7b21b0a62ce8403fb5390eaa7c9c5947 100644 (file)
@@ -34,7 +34,7 @@ enum thread_state {
 /////////////////////////////////////////////////////////////////////////////
 
 static int p_mainid;
-wxMutex wxMainMutex;
+wxMutex *wxMainMutex;
 
 #include "threadgui.inc"
 
@@ -166,10 +166,10 @@ void *wxThread::Join()
     int stat;
 
     if (do_unlock)
-      wxMainMutex.Unlock();
+      wxMainMutex->Unlock();
     waitpid(p_internal->thread_id, &stat, 0);
     if (do_unlock)
-      wxMainMutex.Lock();
+      wxMainMutex->Lock();
     if (!WIFEXITED(stat) && !WIFSIGNALED(stat))
       return 0;
     p_internal->state = STATE_IDLE;
@@ -238,14 +238,16 @@ class wxThreadModule : public wxModule {
   DECLARE_DYNAMIC_CLASS(wxThreadModule)
 public:
   virtual bool OnInit() {
+    wxMainMutex = new wxMutex();
     wxThreadGuiInit();
     p_mainid = (int)getpid();
-    wxMainMutex.Lock();
+    wxMainMutex->Lock();
   }
 
   virtual void OnExit() {
-    wxMainMutex.Unlock();
+    wxMainMutex->Unlock();
     wxThreadGuiExit();
+    delete wxMainMutex;
   }
 };
 
index baa8fe8b763600ca108d905f6a2a8f1c103e26b2..46073d4e0ba1a752c20330ed5f3718cab5838b20 100644 (file)
@@ -79,12 +79,12 @@ void wxMutexGuiLeave()
 
 void wxMutexGuiEnter()
 {
-  wxMainMutex.Lock();
+  wxMainMutex->Lock();
 }
 
 void wxMutexGuiLeave()
 {
-  wxMainMutex.Unlock();
+  wxMainMutex->Unlock();
 }
 
 #endif
index 3a1f3460c79ef1eebda8b8ab04a806ac84278126..375d2ac6a71964732fbf8abb993ef5bf27b25125 100644 (file)
@@ -138,7 +138,7 @@ bool wxThread::IsAlive() const
 void wxThread::SetPriority(int WXUNUSED(prio)) { }
 int wxThread::GetPriority() const { return 0; }
 
-wxMutex wxMainMutex; // controls access to all GUI functions
+wxMutex *wxMainMutex; // controls access to all GUI functions
 
 wxThread::wxThread()
 {
@@ -168,13 +168,15 @@ public:
 };
 
 bool wxThreadModule::OnInit() {
-  wxMainMutex.Lock();
+  wxMainMutex = new wxMutex();
+  wxMainMutex->Lock();
   return TRUE;
 }
 
 void wxThreadModule::OnExit()
 {
-  wxMainMutex.Unlock();
+  wxMainMutex->Unlock();
+  delete wxMainMutex;
 }
 
 IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
index 9623b91c303a63aeef06bf525e80071857d1b9bf..2d4912c05a32cd4b4d73b2e94867c8a081ba277d 100644 (file)
@@ -37,7 +37,7 @@ static pthread_t p_mainid;
 static wxMutex p_list_mutex;
 static wxList p_threads_list;
 
-wxMutex wxMainMutex; // controls access to all GUI functions
+wxMutex *wxMainMutex; // controls access to all GUI functions
 
 /////////////////////////////////////////////////////////////////////////////
 // GUI thread manager
@@ -288,10 +288,10 @@ void *wxThread::Join()
       wxYield();
 
     if (do_unlock)
-      wxMainMutex.Unlock();
+      wxMainMutex->Unlock();
     pthread_join(p_internal->thread_id, &status);
     if (do_unlock)
-      wxMainMutex.Lock();
+      wxMainMutex->Lock();
 
     p_list_mutex.Lock();
     delete p_threads_list.Nth(p_internal->id);
@@ -377,17 +377,19 @@ class wxThreadModule : public wxModule {
   DECLARE_DYNAMIC_CLASS(wxThreadModule)
 public:
   virtual bool OnInit() {
+    wxMainMutex = new wxMutex();
     wxThreadGuiInit();
     p_mainid = pthread_self();
     p_threads_list = wxList(wxKEY_INTEGER);
-    wxMainMutex.Lock();
+    wxMainMutex->Lock();
 
     return TRUE;
   }
 
   virtual void OnExit() {
-    wxMainMutex.Unlock();
+    wxMainMutex->Unlock();
     wxThreadGuiExit();
+    delete wxMainMutex;
   }
 };
 
index 3503e79616da18ce44d6ac9d691944ef9178a9e1..66b6b0da7b21b0a62ce8403fb5390eaa7c9c5947 100644 (file)
@@ -34,7 +34,7 @@ enum thread_state {
 /////////////////////////////////////////////////////////////////////////////
 
 static int p_mainid;
-wxMutex wxMainMutex;
+wxMutex *wxMainMutex;
 
 #include "threadgui.inc"
 
@@ -166,10 +166,10 @@ void *wxThread::Join()
     int stat;
 
     if (do_unlock)
-      wxMainMutex.Unlock();
+      wxMainMutex->Unlock();
     waitpid(p_internal->thread_id, &stat, 0);
     if (do_unlock)
-      wxMainMutex.Lock();
+      wxMainMutex->Lock();
     if (!WIFEXITED(stat) && !WIFSIGNALED(stat))
       return 0;
     p_internal->state = STATE_IDLE;
@@ -238,14 +238,16 @@ class wxThreadModule : public wxModule {
   DECLARE_DYNAMIC_CLASS(wxThreadModule)
 public:
   virtual bool OnInit() {
+    wxMainMutex = new wxMutex();
     wxThreadGuiInit();
     p_mainid = (int)getpid();
-    wxMainMutex.Lock();
+    wxMainMutex->Lock();
   }
 
   virtual void OnExit() {
-    wxMainMutex.Unlock();
+    wxMainMutex->Unlock();
     wxThreadGuiExit();
+    delete wxMainMutex;
   }
 };
 
index c1977870033391c12ae2cb20445dc10a350dfa76..ca3833153ab740fc161123c04b307ae9bdc11906 100644 (file)
@@ -28,7 +28,7 @@ enum thread_state {
 // Static variables
 /////////////////////////////////////////////////////////////////////////////
 
-wxMutex wxMainMutex; // controls access to all GUI functions
+wxMutex *wxMainMutex; // controls access to all GUI functions
 
 /////////////////////////////////////////////////////////////////////////////
 // Windows implementation
@@ -243,13 +243,15 @@ class wxThreadModule : public wxModule {
 public:
   virtual bool OnInit() {
     /* TODO p_mainid = GetCurrentThread(); */
-    wxMainMutex.Lock();
+    wxMainMutex = new wxMutex();
+    wxMainMutex->Lock();
     return TRUE;
   }
 
   // Global cleanup
   virtual void OnExit() {
-    wxMainMutex.Unlock();
+    wxMainMutex->Unlock();
+    delete wxMainMutex;
   }
 };
 
index 176d1e4cc138afccf061d037be6b66131bf62f0a..a592fbf29ec0740e73d4556b0aec85195f6ae230 100644 (file)
@@ -44,7 +44,7 @@ enum thread_state {
 /////////////////////////////////////////////////////////////////////////////
 
 static HANDLE p_mainid;
-wxMutex wxMainMutex; // controls access to all GUI functions
+wxMutex *wxMainMutex; // controls access to all GUI functions
 
 /////////////////////////////////////////////////////////////////////////////
 // Windows implementation
@@ -260,10 +260,10 @@ void *wxThread::Join()
     return NULL;
 
   if (wxThread::IsMain())
-    wxMainMutex.Unlock();
+    wxMainMutex->Unlock();
   WaitForSingleObject(p_internal->thread_id, INFINITE);
   if (wxThread::IsMain())
-    wxMainMutex.Lock();
+    wxMainMutex->Lock();
 
   GetExitCodeThread(p_internal->thread_id, &exit_code);
   CloseHandle(p_internal->thread_id);
@@ -310,14 +310,16 @@ class wxThreadModule : public wxModule {
   DECLARE_DYNAMIC_CLASS(wxThreadModule)
 public:
   virtual bool OnInit() {
+    wxMainMutex = new wxMutex();
     p_mainid = GetCurrentThread();
-    wxMainMutex.Lock();
+    wxMainMutex->Lock();
     return TRUE;
   }
 
   // Global cleanup
   virtual void OnExit() {
-    wxMainMutex.Unlock();
+    wxMainMutex->Unlock();
+    delete wxMainMutex;
   }
 };
 
index b0db0f426af8383fe938e16e7bb24d4fa9dfef22..8cf94d1e0621c9eff0e419cceb89e79370c35e18 100644 (file)
@@ -143,7 +143,7 @@ bool wxThread::IsAlive() const
 void wxThread::SetPriority(int WXUNUSED(prio)) { }
 int wxThread::GetPriority() const { return 0; }
 
-wxMutex wxMainMutex; // controls access to all GUI functions
+wxMutex *wxMainMutex; // controls access to all GUI functions
 
 wxThread::wxThread()
 {
@@ -173,13 +173,15 @@ public:
 };
 
 bool wxThreadModule::OnInit() {
-  wxMainMutex.Lock();
+  wxMainMutex = new wxMutex();
+  wxMainMutex->Lock();
   return TRUE;
 }
 
 void wxThreadModule::OnExit()
 {
-  wxMainMutex.Unlock();
+  wxMainMutex->Unlock();
+  delete wxMainMutex;
 }
 
 IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
index 9623b91c303a63aeef06bf525e80071857d1b9bf..2d4912c05a32cd4b4d73b2e94867c8a081ba277d 100644 (file)
@@ -37,7 +37,7 @@ static pthread_t p_mainid;
 static wxMutex p_list_mutex;
 static wxList p_threads_list;
 
-wxMutex wxMainMutex; // controls access to all GUI functions
+wxMutex *wxMainMutex; // controls access to all GUI functions
 
 /////////////////////////////////////////////////////////////////////////////
 // GUI thread manager
@@ -288,10 +288,10 @@ void *wxThread::Join()
       wxYield();
 
     if (do_unlock)
-      wxMainMutex.Unlock();
+      wxMainMutex->Unlock();
     pthread_join(p_internal->thread_id, &status);
     if (do_unlock)
-      wxMainMutex.Lock();
+      wxMainMutex->Lock();
 
     p_list_mutex.Lock();
     delete p_threads_list.Nth(p_internal->id);
@@ -377,17 +377,19 @@ class wxThreadModule : public wxModule {
   DECLARE_DYNAMIC_CLASS(wxThreadModule)
 public:
   virtual bool OnInit() {
+    wxMainMutex = new wxMutex();
     wxThreadGuiInit();
     p_mainid = pthread_self();
     p_threads_list = wxList(wxKEY_INTEGER);
-    wxMainMutex.Lock();
+    wxMainMutex->Lock();
 
     return TRUE;
   }
 
   virtual void OnExit() {
-    wxMainMutex.Unlock();
+    wxMainMutex->Unlock();
     wxThreadGuiExit();
+    delete wxMainMutex;
   }
 };
 
index 3503e79616da18ce44d6ac9d691944ef9178a9e1..66b6b0da7b21b0a62ce8403fb5390eaa7c9c5947 100644 (file)
@@ -34,7 +34,7 @@ enum thread_state {
 /////////////////////////////////////////////////////////////////////////////
 
 static int p_mainid;
-wxMutex wxMainMutex;
+wxMutex *wxMainMutex;
 
 #include "threadgui.inc"
 
@@ -166,10 +166,10 @@ void *wxThread::Join()
     int stat;
 
     if (do_unlock)
-      wxMainMutex.Unlock();
+      wxMainMutex->Unlock();
     waitpid(p_internal->thread_id, &stat, 0);
     if (do_unlock)
-      wxMainMutex.Lock();
+      wxMainMutex->Lock();
     if (!WIFEXITED(stat) && !WIFSIGNALED(stat))
       return 0;
     p_internal->state = STATE_IDLE;
@@ -238,14 +238,16 @@ class wxThreadModule : public wxModule {
   DECLARE_DYNAMIC_CLASS(wxThreadModule)
 public:
   virtual bool OnInit() {
+    wxMainMutex = new wxMutex();
     wxThreadGuiInit();
     p_mainid = (int)getpid();
-    wxMainMutex.Lock();
+    wxMainMutex->Lock();
   }
 
   virtual void OnExit() {
-    wxMainMutex.Unlock();
+    wxMainMutex->Unlock();
     wxThreadGuiExit();
+    delete wxMainMutex;
   }
 };
 
index c1977870033391c12ae2cb20445dc10a350dfa76..ca3833153ab740fc161123c04b307ae9bdc11906 100644 (file)
@@ -28,7 +28,7 @@ enum thread_state {
 // Static variables
 /////////////////////////////////////////////////////////////////////////////
 
-wxMutex wxMainMutex; // controls access to all GUI functions
+wxMutex *wxMainMutex; // controls access to all GUI functions
 
 /////////////////////////////////////////////////////////////////////////////
 // Windows implementation
@@ -243,13 +243,15 @@ class wxThreadModule : public wxModule {
 public:
   virtual bool OnInit() {
     /* TODO p_mainid = GetCurrentThread(); */
-    wxMainMutex.Lock();
+    wxMainMutex = new wxMutex();
+    wxMainMutex->Lock();
     return TRUE;
   }
 
   // Global cleanup
   virtual void OnExit() {
-    wxMainMutex.Unlock();
+    wxMainMutex->Unlock();
+    delete wxMainMutex;
   }
 };