]> git.saurik.com Git - wxWidgets.git/commitdiff
Triued in vain to fix threads segvs with gcc
authorRobert Roebling <robert@roebling.de>
Sat, 2 Jan 1999 22:24:41 +0000 (22:24 +0000)
committerRobert Roebling <robert@roebling.de>
Sat, 2 Jan 1999 22:24:41 +0000 (22:24 +0000)
  Removed wxDebugStream

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1308 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

15 files changed:
include/wx/thread.h
include/wx/utils.h
samples/thread/Makefile.in
setup/maketmpl.in
src/common/utilscmn.cpp
src/gtk/app.cpp
src/gtk/threadno.cpp
src/gtk/threadpsx.cpp
src/gtk/threadsgi.cpp
src/gtk1/app.cpp
src/gtk1/threadno.cpp
src/gtk1/threadpsx.cpp
src/gtk1/threadsgi.cpp
src/motif/thread.cpp
src/msw/thread.cpp

index b02df5244f1e0d52dab50b6ed3484added7ccabd..aa435992563832a4cc1945eb73f08a7190c17bf5 100644 (file)
 #pragma interface "thread.h"
 #endif
 
-// ----------------------------------------------------------------------------
-// headers
-// ----------------------------------------------------------------------------
 #include "wx/object.h"
 #include "wx/setup.h"
+#include "wx/module.h"
 
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
 
-typedef enum {
+typedef enum 
+{
   wxMUTEX_NO_ERROR = 0,
   wxMUTEX_DEAD_LOCK,      // Mutex has been already locked by THE CALLING thread 
   wxMUTEX_BUSY,           // Mutex has been already locked by ONE thread
@@ -34,7 +33,8 @@ typedef enum {
   wxMUTEX_MISC_ERROR
 } wxMutexError;
 
-typedef enum {
+typedef enum 
+{
   wxTHREAD_NO_ERROR = 0,      // No error
   wxTHREAD_NO_RESOURCE,       // No resource left to create a new thread
   wxTHREAD_RUNNING,           // The thread is already running
@@ -42,16 +42,25 @@ typedef enum {
   wxTHREAD_MISC_ERROR         // Some other error
 } wxThreadError;
 
-// defines the interval of priority.
+/* defines the interval of priority. */
 #define WXTHREAD_MIN_PRIORITY     0
 #define WXTHREAD_DEFAULT_PRIORITY 50
 #define WXTHREAD_MAX_PRIORITY     100
 
+// ----------------------------------------------------------------------------
+// GUI mutex handling.
+// ----------------------------------------------------------------------------
+
+void WXDLLEXPORT wxMutexGuiEnter();
+void WXDLLEXPORT wxMutexGuiLeave();
+
 // ----------------------------------------------------------------------------
 // Mutex handler
 // ----------------------------------------------------------------------------
+
 class WXDLLEXPORT wxMutexInternal;
-class WXDLLEXPORT wxMutex {
+class WXDLLEXPORT wxMutex 
+{
 public:
   // constructor & destructor 
   wxMutex();
@@ -77,8 +86,10 @@ protected:
 // ----------------------------------------------------------------------------
 // Condition handler.
 // ----------------------------------------------------------------------------
+
 class wxConditionInternal;
-class WXDLLEXPORT wxCondition {
+class WXDLLEXPORT wxCondition 
+{
 public:
   // constructor & destructor
   wxCondition();
@@ -100,8 +111,10 @@ private:
 // ----------------------------------------------------------------------------
 // Thread management class
 // ----------------------------------------------------------------------------
+
 class wxThreadInternal;
-class WXDLLEXPORT wxThread {
+class WXDLLEXPORT wxThread 
+{
 public:
   // constructor & destructor.
   wxThread();
@@ -165,11 +178,20 @@ private:
 };
 
 // ----------------------------------------------------------------------------
-// Global functions and variables
+// Automatic initialization
 // ----------------------------------------------------------------------------
 
-// GUI mutex handling.
-void WXDLLEXPORT wxMutexGuiEnter();
-void WXDLLEXPORT wxMutexGuiLeave();
+class wxThreadModule : public wxModule 
+{
+  DECLARE_DYNAMIC_CLASS(wxThreadModule)
+  
+public:
+  wxThreadModule() {}
+
+  virtual bool OnInit();
+  virtual void OnExit();
+};
+
+
 
 #endif // __THREADH__
index 10fc015dd7a41e21aaa3aa1710d36712fa863baa..681f490af9660e258d40818cc9922975b6b9fed0 100644 (file)
@@ -157,46 +157,6 @@ WXDLLEXPORT wxWindow* wxFindWindowByName(const wxString& name, wxWindow *parent
 // Returns menu item id or -1 if none.
 WXDLLEXPORT int wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString);
 
-// A debugging stream buffer.
-// Under Windows, this writes to the Windows debug output.
-// Under other platforms, it writes to cerr.
-
-// ALl this horrible gubbins required for Borland, because the calling
-// convention needs to be the same as for streambuf.
-// Thanks to Gerhard.Vogt@embl-heidelberg.de for this solution.
-
-#if defined(__BORLANDC__) && defined(__BCOPT__) && !defined(_RTL_ALLOW_po) && !defined(__FLAT__)
-#pragma option -po-
-#endif
-
-// Can't export a class derived from a non-export class
-#if !defined(_WINDLL) && !defined(WXUSINGDLL)
-
-// #ifdef new
-// #undef new
-// #endif
-
-class WXDLLEXPORT wxDebugStreamBuf: public streambuf
-{
-  public:
-    wxDebugStreamBuf(void);
-    ~wxDebugStreamBuf(void) {}
-
-    int overflow(int i);
-    inline int underflow(void) { return EOF; }
-    int sync(void);
-};
-
-// #if defined(__WXDEBUG__) && wxUSE_GLOBAL_MEMORY_OPERATORS
-// #define new WXDEBUG_NEW
-// #endif
-
-#endif
-
-#if defined(__BORLANDC__) && defined(__BCOPT__) && !defined(_RTL_ALLOW_po) && !defined(__FLAT__)
-#pragma option -po.
-#endif
-
 /*
 #if (!defined(__MINMAX_DEFINED) && !defined(max))
 #define max(a,b)            (((a) > (b)) ? (a) : (b))
@@ -204,6 +164,7 @@ class WXDLLEXPORT wxDebugStreamBuf: public streambuf
 #define __MINMAX_DEFINED 1
 #endif
 */
+
 #define wxMax(a,b)            (((a) > (b)) ? (a) : (b))
 #define wxMin(a,b)            (((a) < (b)) ? (a) : (b))
 
index 127fbc82ed79cf761cf935d280e65bd397ac093c..27d040a4f6f0bd7b953ce63c1958b51c2c241f39 100644 (file)
@@ -17,7 +17,7 @@ BIN_OBJ=\
 test.o
 
 # additional things needed to link
-BIN_LINK= $(THREADS_LINK)
+BIN_LINK=
 
 # additional things needed to compile
 ADD_COMPILE=
index ba9166a894bde501b5b6749b5ab3655f1a5980ae..799888f21822b5473c78b907c6b6787201af2e8f 100644 (file)
@@ -104,10 +104,6 @@ $(GUI_TK_INCLUDE) \
 $(OPENGL_INCLUDE) \
 $(X_CFLAGS)
 
-# -I$(WXBASEDIR)/src/png \
-# -I$(WXBASEDIR)/src/zlib \
-# -I$(WXBASEDIR)/src/gdk_imlib \
-
 WX_LIBS = -L$(GLOBAL_LIB_DIR) $(WX_LINK)
 
 OPENGL_LIBS = $(OPENGL_LIBRARY) $(OPENGL_LINK)
index f516c32e4399c8560b1b65ea978ab08035f5cb32..2b2e7d65acda8e74db286f13cb65709bdf150f49 100644 (file)
@@ -562,54 +562,6 @@ wxFindMenuItemId (wxFrame * frame, const wxString& menuString, const wxString& i
   return menuBar->FindMenuItem (menuString, itemString);
 }
 
-/*
- * wxDebugStreamBuf
- */
-#if !defined(_WINDLL)
-wxDebugStreamBuf::wxDebugStreamBuf(void)
-{
-       // <iostream> usage doesn't need this, and i have no idea how to simulate it.
-#if wxUSE_IOSTREAMH
-       if (allocate())
-         setp(base(),ebuf());
-#endif
-}
-
-int wxDebugStreamBuf::overflow(int WXUNUSED(i))
-{
-  int len = pptr() - pbase();
-  char *txt = new char[len+1];
-  strncpy(txt, pbase(), len);
-  txt[len] = '\0';
-#ifdef __WXMSW__
-  OutputDebugString((LPCSTR)txt);
-#else
-  fprintf(stderr, txt);
-#endif
-  setp(pbase(), epptr());
-  delete[] txt;
-  return EOF;
-}
-
-int wxDebugStreamBuf::sync(void)
-{
-  int len = pptr() - pbase();
-  char *txt = new char[len+1];
-  strncpy(txt, pbase(), len);
-  txt[len] = '\0';
-#ifdef __WXMSW__
-  OutputDebugString((LPCSTR)txt);
-#else
-  fprintf(stderr, txt);
-#endif
-  setp(pbase(), epptr());
-  delete[] txt;
-  return 0;
-}
-
-#endif
-
 /*
 On Fri, 21 Jul 1995, Paul Craven wrote:
 
index 6b3be61991bb2e402403c82e0d25e16d19e60571..13757a06a73386d38564c02b345886ae832f3fd1 100644 (file)
@@ -191,21 +191,21 @@ void wxApp::OnIdle( wxIdleEvent &event )
 {
     static bool inOnIdle = FALSE;
 
-    // Avoid recursion (via ProcessEvent default case)
+    /* Avoid recursion (via ProcessEvent default case) */
     if (inOnIdle)
         return;
 
     inOnIdle = TRUE;
 
-    // 'Garbage' collection of windows deleted with Close().
+    /* 'Garbage' collection of windows deleted with Close(). */
     DeletePendingObjects();
 
-    // flush the logged messages if any
-    wxLog *pLog = wxLog::GetActiveTarget();
-    if (pLog != NULL && pLog->HasPendingMessages())
-        pLog->Flush();
+    /* flush the logged messages if any */
+    wxLog *log = wxLog::GetActiveTarget();
+    if (log != NULL && log->HasPendingMessages())
+        log->Flush();
 
-    // Send OnIdle events to all windows
+    /* Send OnIdle events to all windows */
     bool needMore = SendIdleEvents();
 
     if (needMore)
@@ -372,14 +372,6 @@ int wxEntry( int argc, char *argv[] )
 
     wxClassInfo::InitializeClasses();
 
-  /* Debug stream no longer used
-#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
-
-  streambuf* sBuf = new wxDebugStreamBuf;
-  ostream* oStr = new ostream(sBuf) ;
-  wxDebugContext::SetStream(oStr, sBuf);
-#endif
-*/
 
     if (!wxTheApp)
     {
@@ -474,7 +466,6 @@ int wxEntry( int argc, char *argv[] )
         wxDebugContext::Dump();
         wxDebugContext::PrintStatistics();
     }
-//  wxDebugContext::SetStream(NULL, NULL);
 
 #endif
 
index 482ab6b49648dc011936ae93097131ffbeedd9b9..72994404561dc15534cf8ad07fd9fe1d8f0e882a 100644 (file)
@@ -160,15 +160,10 @@ void wxThread::OnExit()
 }
 
 
-// Automatic initialization
-class wxThreadModule : public wxModule {
-  DECLARE_DYNAMIC_CLASS(wxThreadModule)
-public:
-  bool OnInit();
-  void OnExit();
-};
+IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
 
-bool wxThreadModule::OnInit() {
+bool wxThreadModule::OnInit() 
+{
   wxMainMutex = new wxMutex();
   wxMainMutex->Lock();
   return TRUE;
@@ -180,7 +175,7 @@ void wxThreadModule::OnExit()
   delete wxMainMutex;
 }
 
-IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
+
 
 void wxMutexGuiEnter()
 {
index 2b314bec016e48c203b8d235e98989f663bccafb..dd769527e5acea4ca67597ac049a011019cc339f 100644 (file)
@@ -43,7 +43,7 @@ enum thread_state
 
 static pthread_t p_mainid;
 
-wxMutex *wxMainMutex; // controls access to all GUI functions
+wxMutex *wxMainMutex; /* controls access to all GUI functions */
 
 //--------------------------------------------------------------------
 // common GUI thread code
@@ -182,7 +182,7 @@ void *wxThreadInternal::PthreadStart(void *ptr)
 {
     wxThread *thread = (wxThread *)ptr;
 
-    // Call the main entry
+    /* Call the main entry */
     pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
     void* status = thread->Entry();
 
@@ -200,7 +200,7 @@ wxThreadError wxThread::Create()
     if (p_internal->state != STATE_IDLE)
         return wxTHREAD_RUNNING;
 
-    // Change thread priority
+    /* Change thread priority */
     pthread_attr_init(&a);
     pthread_attr_getschedpolicy(&a, &p);
 
@@ -365,7 +365,7 @@ wxThread::~wxThread()
     delete p_internal;
 }
 
-// The default callback just joins the thread and throws away the result.
+/* The default callback just joins the thread and throws away the result. */
 void wxThread::OnExit()
 {
     Join();
@@ -375,28 +375,22 @@ void wxThread::OnExit()
 // wxThreadModule 
 //--------------------------------------------------------------------
 
-class wxThreadModule : public wxModule 
-{
-  DECLARE_DYNAMIC_CLASS(wxThreadModule)
-  
-public:
-  virtual bool OnInit() 
-    {
-        wxMainMutex = new wxMutex();
-        wxThreadGuiInit();
-        p_mainid = pthread_self();
-       wxMainMutex->Lock();
+IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
 
-       return TRUE;
-    }
+bool wxThreadModule::OnInit() 
+{
+    wxMainMutex = new wxMutex();
+    wxThreadGuiInit();
+    p_mainid = (int)getpid();
+    wxMainMutex->Lock();
+    return TRUE;
+}
 
-  virtual void OnExit() 
-  {
-      wxMainMutex->Unlock();
-      wxThreadGuiExit();
-      delete wxMainMutex;
-  }
-};
+void wxThreadModule::OnExit()
+{
+    wxMainMutex->Unlock();
+    wxThreadGuiExit();
+    delete wxMainMutex;
+}
 
-IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
 
index 3b66071667662b59c8576b6ba135cb181c872d26..f9befcb74efba58e276dbb104af1ba9e46dcefc3 100644 (file)
@@ -238,21 +238,22 @@ void wxThread::OnExit()
 }
 
 // Global initialization
-class wxThreadModule : public wxModule {
-  DECLARE_DYNAMIC_CLASS(wxThreadModule)
-public:
-  virtual bool OnInit() {
+
+IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
+
+bool wxThreadModule::OnInit() 
+{
     wxMainMutex = new wxMutex();
     wxThreadGuiInit();
     p_mainid = (int)getpid();
     wxMainMutex->Lock();
-  }
+    return TRUE;
+}
 
-  virtual void OnExit() {
+void wxThreadModule::OnExit()
+{
     wxMainMutex->Unlock();
     wxThreadGuiExit();
     delete wxMainMutex;
-  }
-};
+}
 
-IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
index 6b3be61991bb2e402403c82e0d25e16d19e60571..13757a06a73386d38564c02b345886ae832f3fd1 100644 (file)
@@ -191,21 +191,21 @@ void wxApp::OnIdle( wxIdleEvent &event )
 {
     static bool inOnIdle = FALSE;
 
-    // Avoid recursion (via ProcessEvent default case)
+    /* Avoid recursion (via ProcessEvent default case) */
     if (inOnIdle)
         return;
 
     inOnIdle = TRUE;
 
-    // 'Garbage' collection of windows deleted with Close().
+    /* 'Garbage' collection of windows deleted with Close(). */
     DeletePendingObjects();
 
-    // flush the logged messages if any
-    wxLog *pLog = wxLog::GetActiveTarget();
-    if (pLog != NULL && pLog->HasPendingMessages())
-        pLog->Flush();
+    /* flush the logged messages if any */
+    wxLog *log = wxLog::GetActiveTarget();
+    if (log != NULL && log->HasPendingMessages())
+        log->Flush();
 
-    // Send OnIdle events to all windows
+    /* Send OnIdle events to all windows */
     bool needMore = SendIdleEvents();
 
     if (needMore)
@@ -372,14 +372,6 @@ int wxEntry( int argc, char *argv[] )
 
     wxClassInfo::InitializeClasses();
 
-  /* Debug stream no longer used
-#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
-
-  streambuf* sBuf = new wxDebugStreamBuf;
-  ostream* oStr = new ostream(sBuf) ;
-  wxDebugContext::SetStream(oStr, sBuf);
-#endif
-*/
 
     if (!wxTheApp)
     {
@@ -474,7 +466,6 @@ int wxEntry( int argc, char *argv[] )
         wxDebugContext::Dump();
         wxDebugContext::PrintStatistics();
     }
-//  wxDebugContext::SetStream(NULL, NULL);
 
 #endif
 
index 482ab6b49648dc011936ae93097131ffbeedd9b9..72994404561dc15534cf8ad07fd9fe1d8f0e882a 100644 (file)
@@ -160,15 +160,10 @@ void wxThread::OnExit()
 }
 
 
-// Automatic initialization
-class wxThreadModule : public wxModule {
-  DECLARE_DYNAMIC_CLASS(wxThreadModule)
-public:
-  bool OnInit();
-  void OnExit();
-};
+IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
 
-bool wxThreadModule::OnInit() {
+bool wxThreadModule::OnInit() 
+{
   wxMainMutex = new wxMutex();
   wxMainMutex->Lock();
   return TRUE;
@@ -180,7 +175,7 @@ void wxThreadModule::OnExit()
   delete wxMainMutex;
 }
 
-IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
+
 
 void wxMutexGuiEnter()
 {
index 2b314bec016e48c203b8d235e98989f663bccafb..dd769527e5acea4ca67597ac049a011019cc339f 100644 (file)
@@ -43,7 +43,7 @@ enum thread_state
 
 static pthread_t p_mainid;
 
-wxMutex *wxMainMutex; // controls access to all GUI functions
+wxMutex *wxMainMutex; /* controls access to all GUI functions */
 
 //--------------------------------------------------------------------
 // common GUI thread code
@@ -182,7 +182,7 @@ void *wxThreadInternal::PthreadStart(void *ptr)
 {
     wxThread *thread = (wxThread *)ptr;
 
-    // Call the main entry
+    /* Call the main entry */
     pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
     void* status = thread->Entry();
 
@@ -200,7 +200,7 @@ wxThreadError wxThread::Create()
     if (p_internal->state != STATE_IDLE)
         return wxTHREAD_RUNNING;
 
-    // Change thread priority
+    /* Change thread priority */
     pthread_attr_init(&a);
     pthread_attr_getschedpolicy(&a, &p);
 
@@ -365,7 +365,7 @@ wxThread::~wxThread()
     delete p_internal;
 }
 
-// The default callback just joins the thread and throws away the result.
+/* The default callback just joins the thread and throws away the result. */
 void wxThread::OnExit()
 {
     Join();
@@ -375,28 +375,22 @@ void wxThread::OnExit()
 // wxThreadModule 
 //--------------------------------------------------------------------
 
-class wxThreadModule : public wxModule 
-{
-  DECLARE_DYNAMIC_CLASS(wxThreadModule)
-  
-public:
-  virtual bool OnInit() 
-    {
-        wxMainMutex = new wxMutex();
-        wxThreadGuiInit();
-        p_mainid = pthread_self();
-       wxMainMutex->Lock();
+IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
 
-       return TRUE;
-    }
+bool wxThreadModule::OnInit() 
+{
+    wxMainMutex = new wxMutex();
+    wxThreadGuiInit();
+    p_mainid = (int)getpid();
+    wxMainMutex->Lock();
+    return TRUE;
+}
 
-  virtual void OnExit() 
-  {
-      wxMainMutex->Unlock();
-      wxThreadGuiExit();
-      delete wxMainMutex;
-  }
-};
+void wxThreadModule::OnExit()
+{
+    wxMainMutex->Unlock();
+    wxThreadGuiExit();
+    delete wxMainMutex;
+}
 
-IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
 
index 3b66071667662b59c8576b6ba135cb181c872d26..f9befcb74efba58e276dbb104af1ba9e46dcefc3 100644 (file)
@@ -238,21 +238,22 @@ void wxThread::OnExit()
 }
 
 // Global initialization
-class wxThreadModule : public wxModule {
-  DECLARE_DYNAMIC_CLASS(wxThreadModule)
-public:
-  virtual bool OnInit() {
+
+IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
+
+bool wxThreadModule::OnInit() 
+{
     wxMainMutex = new wxMutex();
     wxThreadGuiInit();
     p_mainid = (int)getpid();
     wxMainMutex->Lock();
-  }
+    return TRUE;
+}
 
-  virtual void OnExit() {
+void wxThreadModule::OnExit()
+{
     wxMainMutex->Unlock();
     wxThreadGuiExit();
     delete wxMainMutex;
-  }
-};
+}
 
-IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
index f5e0d88bfb526e2164163201013bc9333ca91392..3407dd8fe350d8e8d6e9ea419dd9e9786ecaf44b 100644 (file)
@@ -414,30 +414,24 @@ void wxThread::OnExit()
 // wxThreadModule 
 //--------------------------------------------------------------------
 
-class wxThreadModule : public wxModule 
+IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
+
+bool wxThreadModule::OnInit() 
 {
-  DECLARE_DYNAMIC_CLASS(wxThreadModule)
-  
-public:
-  virtual bool OnInit() 
-    {
-        wxMainMutex = new wxMutex();
-        wxThreadGuiInit();
-        p_mainid = pthread_self();
-       wxMainMutex->Lock();
+    wxMainMutex = new wxMutex();
+    wxThreadGuiInit();
+    p_mainid = pthread_self();
+    wxMainMutex->Lock();
 
-       return TRUE;
-    }
+    return TRUE;
+}
 
-  virtual void OnExit() 
-  {
-      wxMainMutex->Unlock();
-      wxThreadGuiExit();
-      delete wxMainMutex;
-  }
+void wxThreadModule::OnExit()
+{
+    wxMainMutex->Unlock();
+    wxThreadGuiExit();
+    delete wxMainMutex;
 };
 
-IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
-
 #endif
   // wxUSE_THREADS
index 0832f9a2b7042b711709158923e26998bebc299a..56fe00d322a76b32b1ac02c21d4023ea722a549f 100644 (file)
@@ -366,25 +366,7 @@ void wxThread::OnExit()
   Join();
 }
 
-// Automatic initialization
-class wxThreadModule : public wxModule {
-  DECLARE_DYNAMIC_CLASS(wxThreadModule)
-public:
-  virtual bool OnInit() {
-    wxMainMutex = new wxMutex();
-    p_mainid = GetCurrentThread();
-    wxMainMutex->Lock();
-    return TRUE;
-  }
-
-  // Global cleanup
-  virtual void OnExit() {
-    wxMainMutex->Unlock();
-    delete wxMainMutex;
-  }
-};
-
-IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
+// GUI mutex functions
 
 void WXDLLEXPORT wxMutexGuiEnter()
 {
@@ -395,3 +377,22 @@ void WXDLLEXPORT wxMutexGuiLeave()
 {
   wxFAIL_MSG("not implemented");
 }
+
+// Automatic initialization
+
+IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
+
+bool wxThreadModule::OnInit() 
+{
+    wxMainMutex = new wxMutex();
+    p_mainid = GetCurrentThread();
+    wxMainMutex->Lock();
+    return TRUE;
+}
+
+void wxThreadModule::OnExit() 
+{
+    wxMainMutex->Unlock();
+    delete wxMainMutex;
+};
+