]> git.saurik.com Git - wxWidgets.git/commitdiff
Put wxGTK's threads back to life.
authorRobert Roebling <robert@roebling.de>
Sat, 22 May 1999 08:01:17 +0000 (08:01 +0000)
committerRobert Roebling <robert@roebling.de>
Sat, 22 May 1999 08:01:17 +0000 (08:01 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2538 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/dc.h
include/wx/gtk/app.h
include/wx/gtk1/app.h
samples/thread/test.cpp
src/gtk/app.cpp
src/gtk/timer.cpp
src/gtk1/app.cpp
src/gtk1/timer.cpp
src/unix/threadpsx.cpp

index 4ce01bb4bda7274323574d64e0e91f56a4e2d7c2..52b5a38e83ec966fc084c95beb111e702733d19f 100644 (file)
@@ -110,7 +110,7 @@ public:
         { DoDrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); }
 
     void DrawEllipticArc(long x, long y, long w, long h, double sa, double ea)
         { DoDrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); }
 
     void DrawEllipticArc(long x, long y, long w, long h, double sa, double ea)
-        { DoDrawEllipticArc(x, y, x, y, sa, ea); }
+        { DoDrawEllipticArc(x, y, w, h, sa, ea); }
     void DrawEllipticArc(const wxPoint& pt, const wxSize& sz,
                          double sa, double ea)
         { DoDrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); }
     void DrawEllipticArc(const wxPoint& pt, const wxSize& sz,
                          double sa, double ea)
         { DoDrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); }
index 38f8a5a5d7fc15a779233b4d17260e35a4c3cbe9..958c8a39aef8e72ec0c0408d5b7f5a628434db48 100644 (file)
@@ -130,6 +130,7 @@ class wxApp: public wxEvtHandler
     wxWindow       *m_topWindow;
     
     gint            m_idleTag;
     wxWindow       *m_topWindow;
     
     gint            m_idleTag;
+    gint            m_wakeUpTimerTag;
     unsigned char  *m_colorCube;
 
     int             argc;
     unsigned char  *m_colorCube;
 
     int             argc;
index 38f8a5a5d7fc15a779233b4d17260e35a4c3cbe9..958c8a39aef8e72ec0c0408d5b7f5a628434db48 100644 (file)
@@ -130,6 +130,7 @@ class wxApp: public wxEvtHandler
     wxWindow       *m_topWindow;
     
     gint            m_idleTag;
     wxWindow       *m_topWindow;
     
     gint            m_idleTag;
+    gint            m_wakeUpTimerTag;
     unsigned char  *m_colorCube;
 
     int             argc;
     unsigned char  *m_colorCube;
 
     int             argc;
index c59942db53e71c34cdd01bc8bd056e4122adf8ec..881bcd640c85cc51acf1f5d267debbb535f2697f 100644 (file)
@@ -130,10 +130,14 @@ void MyThread::WriteText(const wxString& text)
 
     // before doing any GUI calls we must ensure that this thread is the only
     // one doing it!
 
     // before doing any GUI calls we must ensure that this thread is the only
     // one doing it!
-    wxMutexGuiLocker guiLocker;
+    
+    wxMutexGuiEnter();
+    
     msg << wxTime().FormatTime() << ": " << text;
 
     m_frame->WriteText(msg);
     msg << wxTime().FormatTime() << ": " << text;
 
     m_frame->WriteText(msg);
+
+    wxMutexGuiLeave();
 }
 
 void MyThread::OnExit()
 }
 
 void MyThread::OnExit()
index 349491360334d7cb067bb4d391e8e6dc431c238a..bf7a03b90e653e9805efe13b48b20475032bf3ab 100644 (file)
@@ -140,9 +140,9 @@ gint wxapp_idle_callback( gpointer WXUNUSED(data) );
 
 bool wxYield()
 {
 
 bool wxYield()
 {
-    // it's necessary to call ProcessIdle() to update the frames sizes which
-    // might have been changed (it also will update other things set from
-    // OnUpdateUI() which is a nice (and desired) side effect)
+    /* it's necessary to call ProcessIdle() to update the frames sizes which
+       might have been changed (it also will update other things set from
+       OnUpdateUI() which is a nice (and desired) side effect) */
     for ( wxWindowList::Node *node = wxTopLevelWindows.GetFirst();
           node;
           node = node->GetNext() )
     for ( wxWindowList::Node *node = wxTopLevelWindows.GetFirst();
           node;
           node = node->GetNext() )
@@ -177,6 +177,11 @@ gint wxapp_idle_callback( gpointer WXUNUSED(data) )
 {
     if (!wxTheApp) return TRUE;
     
 {
     if (!wxTheApp) return TRUE;
     
+    /* when getting called from GDK's idle handler we
+       are no longer within GDK's grab on the GUI
+       thread so we must lock it here ourselves */
+    GDK_THREADS_ENTER ();
+    
     /* sent idle event to all who request them */
     while (wxTheApp->ProcessIdle()) { }
     
     /* sent idle event to all who request them */
     while (wxTheApp->ProcessIdle()) { }
     
@@ -192,17 +197,16 @@ gint wxapp_idle_callback( gpointer WXUNUSED(data) )
        emptied */
     g_isIdle = TRUE;
     
        emptied */
     g_isIdle = TRUE;
     
-    /* wake up other threads */
-
-    wxMutexGuiLeave();
-    wxUsleep(0);
-    wxMutexGuiEnter();
+    /* release lock again */
+    GDK_THREADS_LEAVE ();
 
     return TRUE;
 }
 
 void wxapp_install_idle_handler()
 {
 
     return TRUE;
 }
 
 void wxapp_install_idle_handler()
 {
+    wxASSERT_MSG( wxTheApp->m_idleTag == 0, "attempt to install idle handler twice" );
+
     /* this routine gets called by all event handlers
        indicating that the idle is over. */
 
     /* this routine gets called by all event handlers
        indicating that the idle is over. */
 
@@ -211,6 +215,34 @@ void wxapp_install_idle_handler()
     g_isIdle = FALSE;
 }
 
     g_isIdle = FALSE;
 }
 
+
+static gint wxapp_wakeup_timerout_callback( gpointer WXUNUSED(data) )
+{
+    gtk_timeout_remove( wxTheApp->m_wakeUpTimerTag );
+    wxTheApp->m_wakeUpTimerTag = 0;
+    
+    /* when getting called from GDK's time-out handler 
+       we are no longer within GDK's grab on the GUI
+       thread so we must lock it here ourselves */
+    GDK_THREADS_ENTER ();
+    
+    /* unblock other threads wishing to do some GUI things */
+    wxMutexGuiLeave();
+    
+    /* wake up other threads */
+    wxUsleep( 1 );
+    
+    /* block other thread again  */
+    wxMutexGuiEnter();
+    
+    /* release lock again */
+    GDK_THREADS_LEAVE ();
+    
+    wxTheApp->m_wakeUpTimerTag = gtk_timeout_add( 10, wxapp_wakeup_timerout_callback, (gpointer) NULL );
+    
+    return TRUE;
+}
+
 //-----------------------------------------------------------------------------
 // wxApp
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 // wxApp
 //-----------------------------------------------------------------------------
@@ -229,6 +261,8 @@ wxApp::wxApp()
     m_exitOnFrameDelete = TRUE;
 
     m_idleTag = gtk_idle_add( wxapp_idle_callback, (gpointer) NULL );
     m_exitOnFrameDelete = TRUE;
 
     m_idleTag = gtk_idle_add( wxapp_idle_callback, (gpointer) NULL );
+    
+    m_wakeUpTimerTag = gtk_timeout_add( 10, wxapp_wakeup_timerout_callback, (gpointer) NULL );
 
     m_colorCube = (unsigned char*) NULL;
 }
 
     m_colorCube = (unsigned char*) NULL;
 }
@@ -237,6 +271,8 @@ wxApp::~wxApp()
 {
     if (m_idleTag) gtk_idle_remove( m_idleTag );
 
 {
     if (m_idleTag) gtk_idle_remove( m_idleTag );
 
+    if (m_wakeUpTimerTag) gtk_timeout_remove( m_wakeUpTimerTag );
+    
     if (m_colorCube) free(m_colorCube);
 }
 
     if (m_colorCube) free(m_colorCube);
 }
 
index fb74fc13dc8bc7352e50c127c7339fe1c8773d13..a1a8a8126abdb806e7872bf6927150816b6be095 100644 (file)
@@ -67,7 +67,7 @@ long wxGetCurrentTime()
 
 IMPLEMENT_ABSTRACT_CLASS(wxTimer,wxObject)
 
 
 IMPLEMENT_ABSTRACT_CLASS(wxTimer,wxObject)
 
-gint timeout_callback( gpointer data )
+static gint timeout_callback( gpointer data )
 {
     wxTimer *timer = (wxTimer*)data;
     timer->Notify();
 {
     wxTimer *timer = (wxTimer*)data;
     timer->Notify();
index 349491360334d7cb067bb4d391e8e6dc431c238a..bf7a03b90e653e9805efe13b48b20475032bf3ab 100644 (file)
@@ -140,9 +140,9 @@ gint wxapp_idle_callback( gpointer WXUNUSED(data) );
 
 bool wxYield()
 {
 
 bool wxYield()
 {
-    // it's necessary to call ProcessIdle() to update the frames sizes which
-    // might have been changed (it also will update other things set from
-    // OnUpdateUI() which is a nice (and desired) side effect)
+    /* it's necessary to call ProcessIdle() to update the frames sizes which
+       might have been changed (it also will update other things set from
+       OnUpdateUI() which is a nice (and desired) side effect) */
     for ( wxWindowList::Node *node = wxTopLevelWindows.GetFirst();
           node;
           node = node->GetNext() )
     for ( wxWindowList::Node *node = wxTopLevelWindows.GetFirst();
           node;
           node = node->GetNext() )
@@ -177,6 +177,11 @@ gint wxapp_idle_callback( gpointer WXUNUSED(data) )
 {
     if (!wxTheApp) return TRUE;
     
 {
     if (!wxTheApp) return TRUE;
     
+    /* when getting called from GDK's idle handler we
+       are no longer within GDK's grab on the GUI
+       thread so we must lock it here ourselves */
+    GDK_THREADS_ENTER ();
+    
     /* sent idle event to all who request them */
     while (wxTheApp->ProcessIdle()) { }
     
     /* sent idle event to all who request them */
     while (wxTheApp->ProcessIdle()) { }
     
@@ -192,17 +197,16 @@ gint wxapp_idle_callback( gpointer WXUNUSED(data) )
        emptied */
     g_isIdle = TRUE;
     
        emptied */
     g_isIdle = TRUE;
     
-    /* wake up other threads */
-
-    wxMutexGuiLeave();
-    wxUsleep(0);
-    wxMutexGuiEnter();
+    /* release lock again */
+    GDK_THREADS_LEAVE ();
 
     return TRUE;
 }
 
 void wxapp_install_idle_handler()
 {
 
     return TRUE;
 }
 
 void wxapp_install_idle_handler()
 {
+    wxASSERT_MSG( wxTheApp->m_idleTag == 0, "attempt to install idle handler twice" );
+
     /* this routine gets called by all event handlers
        indicating that the idle is over. */
 
     /* this routine gets called by all event handlers
        indicating that the idle is over. */
 
@@ -211,6 +215,34 @@ void wxapp_install_idle_handler()
     g_isIdle = FALSE;
 }
 
     g_isIdle = FALSE;
 }
 
+
+static gint wxapp_wakeup_timerout_callback( gpointer WXUNUSED(data) )
+{
+    gtk_timeout_remove( wxTheApp->m_wakeUpTimerTag );
+    wxTheApp->m_wakeUpTimerTag = 0;
+    
+    /* when getting called from GDK's time-out handler 
+       we are no longer within GDK's grab on the GUI
+       thread so we must lock it here ourselves */
+    GDK_THREADS_ENTER ();
+    
+    /* unblock other threads wishing to do some GUI things */
+    wxMutexGuiLeave();
+    
+    /* wake up other threads */
+    wxUsleep( 1 );
+    
+    /* block other thread again  */
+    wxMutexGuiEnter();
+    
+    /* release lock again */
+    GDK_THREADS_LEAVE ();
+    
+    wxTheApp->m_wakeUpTimerTag = gtk_timeout_add( 10, wxapp_wakeup_timerout_callback, (gpointer) NULL );
+    
+    return TRUE;
+}
+
 //-----------------------------------------------------------------------------
 // wxApp
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 // wxApp
 //-----------------------------------------------------------------------------
@@ -229,6 +261,8 @@ wxApp::wxApp()
     m_exitOnFrameDelete = TRUE;
 
     m_idleTag = gtk_idle_add( wxapp_idle_callback, (gpointer) NULL );
     m_exitOnFrameDelete = TRUE;
 
     m_idleTag = gtk_idle_add( wxapp_idle_callback, (gpointer) NULL );
+    
+    m_wakeUpTimerTag = gtk_timeout_add( 10, wxapp_wakeup_timerout_callback, (gpointer) NULL );
 
     m_colorCube = (unsigned char*) NULL;
 }
 
     m_colorCube = (unsigned char*) NULL;
 }
@@ -237,6 +271,8 @@ wxApp::~wxApp()
 {
     if (m_idleTag) gtk_idle_remove( m_idleTag );
 
 {
     if (m_idleTag) gtk_idle_remove( m_idleTag );
 
+    if (m_wakeUpTimerTag) gtk_timeout_remove( m_wakeUpTimerTag );
+    
     if (m_colorCube) free(m_colorCube);
 }
 
     if (m_colorCube) free(m_colorCube);
 }
 
index fb74fc13dc8bc7352e50c127c7339fe1c8773d13..a1a8a8126abdb806e7872bf6927150816b6be095 100644 (file)
@@ -67,7 +67,7 @@ long wxGetCurrentTime()
 
 IMPLEMENT_ABSTRACT_CLASS(wxTimer,wxObject)
 
 
 IMPLEMENT_ABSTRACT_CLASS(wxTimer,wxObject)
 
-gint timeout_callback( gpointer data )
+static gint timeout_callback( gpointer data )
 {
     wxTimer *timer = (wxTimer*)data;
     timer->Notify();
 {
     wxTimer *timer = (wxTimer*)data;
     timer->Notify();
index a1764a30c38cc1647896f21ddd50a4324f88ceb1..edd373cdc467c86356acf5a00ba3c8628b69f153 100644 (file)
     #include <sched.h>
 #endif
 
     #include <sched.h>
 #endif
 
-#ifdef __WXGTK12__
-#include "gtk/gtk.h"
-#endif
-
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
@@ -85,10 +81,8 @@ static pthread_t gs_tidMain;
 // the key for the pointer to the associated wxThread object
 static pthread_key_t gs_keySelf;
 
 // the key for the pointer to the associated wxThread object
 static pthread_key_t gs_keySelf;
 
-#ifndef __WXGTK12__
 // this mutex must be acquired before any call to a GUI function
 static wxMutex *gs_mutexGui;
 // this mutex must be acquired before any call to a GUI function
 static wxMutex *gs_mutexGui;
-#endif
 
 // ============================================================================
 // implementation
 
 // ============================================================================
 // implementation
@@ -818,15 +812,11 @@ bool wxThreadModule::OnInit()
         return FALSE;
     }
 
         return FALSE;
     }
 
-#ifndef __WXGTK12__
     gs_mutexGui = new wxMutex();
     gs_mutexGui = new wxMutex();
-#endif
 
     gs_tidMain = pthread_self();
 
 
     gs_tidMain = pthread_self();
 
-#ifndef __WXGTK12__
     gs_mutexGui->Lock();
     gs_mutexGui->Lock();
-#endif
 
     return TRUE;
 }
 
     return TRUE;
 }
@@ -845,12 +835,10 @@ void wxThreadModule::OnExit()
         gs_allThreads[n]->Delete();
     }
 
         gs_allThreads[n]->Delete();
     }
 
-#ifndef __WXGTK12__
     // destroy GUI mutex
     gs_mutexGui->Unlock();
 
     delete gs_mutexGui;
     // destroy GUI mutex
     gs_mutexGui->Unlock();
 
     delete gs_mutexGui;
-#endif
 
     // and free TLD slot
     (void)pthread_key_delete(gs_keySelf);
 
     // and free TLD slot
     (void)pthread_key_delete(gs_keySelf);
@@ -862,20 +850,12 @@ void wxThreadModule::OnExit()
 
 void wxMutexGuiEnter()
 {
 
 void wxMutexGuiEnter()
 {
-#ifdef __WXGTK12__
-  gdk_threads_enter();
-#else
   gs_mutexGui->Lock();
   gs_mutexGui->Lock();
-#endif
 }
 
 void wxMutexGuiLeave()
 {
 }
 
 void wxMutexGuiLeave()
 {
-#ifdef __WXGTK12__
-  gdk_threads_leave();
-#else
   gs_mutexGui->Unlock();
   gs_mutexGui->Unlock();
-#endif
 }
 
 #endif
 }
 
 #endif