Put wxGTK's threads back to life.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2538 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 1999-05-22 08:01:17 +00:00
parent 286cb97fcf
commit 7b90a8f20d
9 changed files with 98 additions and 40 deletions

View 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)
{ 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); }

View File

@ -130,6 +130,7 @@ class wxApp: public wxEvtHandler
wxWindow *m_topWindow;
gint m_idleTag;
gint m_wakeUpTimerTag;
unsigned char *m_colorCube;
int argc;

View File

@ -130,6 +130,7 @@ class wxApp: public wxEvtHandler
wxWindow *m_topWindow;
gint m_idleTag;
gint m_wakeUpTimerTag;
unsigned char *m_colorCube;
int argc;

View 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!
wxMutexGuiLocker guiLocker;
wxMutexGuiEnter();
msg << wxTime().FormatTime() << ": " << text;
m_frame->WriteText(msg);
wxMutexGuiLeave();
}
void MyThread::OnExit()

View File

@ -140,9 +140,9 @@ gint wxapp_idle_callback( gpointer WXUNUSED(data) );
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() )
@ -177,6 +177,11 @@ gint wxapp_idle_callback( gpointer WXUNUSED(data) )
{
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()) { }
@ -192,17 +197,16 @@ gint wxapp_idle_callback( gpointer WXUNUSED(data) )
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()
{
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. */
@ -211,6 +215,34 @@ void wxapp_install_idle_handler()
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
//-----------------------------------------------------------------------------
@ -230,6 +262,8 @@ wxApp::wxApp()
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;
}
@ -237,6 +271,8 @@ wxApp::~wxApp()
{
if (m_idleTag) gtk_idle_remove( m_idleTag );
if (m_wakeUpTimerTag) gtk_timeout_remove( m_wakeUpTimerTag );
if (m_colorCube) free(m_colorCube);
}

View File

@ -67,7 +67,7 @@ long wxGetCurrentTime()
IMPLEMENT_ABSTRACT_CLASS(wxTimer,wxObject)
gint timeout_callback( gpointer data )
static gint timeout_callback( gpointer data )
{
wxTimer *timer = (wxTimer*)data;
timer->Notify();

View File

@ -140,9 +140,9 @@ gint wxapp_idle_callback( gpointer WXUNUSED(data) );
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() )
@ -177,6 +177,11 @@ gint wxapp_idle_callback( gpointer WXUNUSED(data) )
{
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()) { }
@ -192,17 +197,16 @@ gint wxapp_idle_callback( gpointer WXUNUSED(data) )
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()
{
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. */
@ -211,6 +215,34 @@ void wxapp_install_idle_handler()
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
//-----------------------------------------------------------------------------
@ -230,6 +262,8 @@ wxApp::wxApp()
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;
}
@ -237,6 +271,8 @@ wxApp::~wxApp()
{
if (m_idleTag) gtk_idle_remove( m_idleTag );
if (m_wakeUpTimerTag) gtk_timeout_remove( m_wakeUpTimerTag );
if (m_colorCube) free(m_colorCube);
}

View File

@ -67,7 +67,7 @@ long wxGetCurrentTime()
IMPLEMENT_ABSTRACT_CLASS(wxTimer,wxObject)
gint timeout_callback( gpointer data )
static gint timeout_callback( gpointer data )
{
wxTimer *timer = (wxTimer*)data;
timer->Notify();

View File

@ -47,10 +47,6 @@
#include <sched.h>
#endif
#ifdef __WXGTK12__
#include "gtk/gtk.h"
#endif
// ----------------------------------------------------------------------------
// 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;
#ifndef __WXGTK12__
// this mutex must be acquired before any call to a GUI function
static wxMutex *gs_mutexGui;
#endif
// ============================================================================
// implementation
@ -818,15 +812,11 @@ bool wxThreadModule::OnInit()
return FALSE;
}
#ifndef __WXGTK12__
gs_mutexGui = new wxMutex();
#endif
gs_tidMain = pthread_self();
#ifndef __WXGTK12__
gs_mutexGui->Lock();
#endif
return TRUE;
}
@ -845,12 +835,10 @@ void wxThreadModule::OnExit()
gs_allThreads[n]->Delete();
}
#ifndef __WXGTK12__
// destroy GUI mutex
gs_mutexGui->Unlock();
delete gs_mutexGui;
#endif
// and free TLD slot
(void)pthread_key_delete(gs_keySelf);
@ -862,20 +850,12 @@ void wxThreadModule::OnExit()
void wxMutexGuiEnter()
{
#ifdef __WXGTK12__
gdk_threads_enter();
#else
gs_mutexGui->Lock();
#endif
}
void wxMutexGuiLeave()
{
#ifdef __WXGTK12__
gdk_threads_leave();
#else
gs_mutexGui->Unlock();
#endif
}
#endif