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:
parent
286cb97fcf
commit
7b90a8f20d
@ -110,7 +110,7 @@ public:
|
|||||||
{ DoDrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); }
|
{ 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)
|
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,
|
void DrawEllipticArc(const wxPoint& pt, const wxSize& sz,
|
||||||
double sa, double ea)
|
double sa, double ea)
|
||||||
{ DoDrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); }
|
{ DoDrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); }
|
||||||
|
@ -130,6 +130,7 @@ class wxApp: public wxEvtHandler
|
|||||||
wxWindow *m_topWindow;
|
wxWindow *m_topWindow;
|
||||||
|
|
||||||
gint m_idleTag;
|
gint m_idleTag;
|
||||||
|
gint m_wakeUpTimerTag;
|
||||||
unsigned char *m_colorCube;
|
unsigned char *m_colorCube;
|
||||||
|
|
||||||
int argc;
|
int argc;
|
||||||
|
@ -130,6 +130,7 @@ class wxApp: public wxEvtHandler
|
|||||||
wxWindow *m_topWindow;
|
wxWindow *m_topWindow;
|
||||||
|
|
||||||
gint m_idleTag;
|
gint m_idleTag;
|
||||||
|
gint m_wakeUpTimerTag;
|
||||||
unsigned char *m_colorCube;
|
unsigned char *m_colorCube;
|
||||||
|
|
||||||
int argc;
|
int argc;
|
||||||
|
@ -130,10 +130,14 @@ void MyThread::WriteText(const wxString& text)
|
|||||||
|
|
||||||
// before doing any GUI calls we must ensure that this thread is the only
|
// before doing any GUI calls we must ensure that this thread is the only
|
||||||
// one doing it!
|
// one doing it!
|
||||||
wxMutexGuiLocker guiLocker;
|
|
||||||
|
wxMutexGuiEnter();
|
||||||
|
|
||||||
msg << wxTime().FormatTime() << ": " << text;
|
msg << wxTime().FormatTime() << ": " << text;
|
||||||
|
|
||||||
m_frame->WriteText(msg);
|
m_frame->WriteText(msg);
|
||||||
|
|
||||||
|
wxMutexGuiLeave();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyThread::OnExit()
|
void MyThread::OnExit()
|
||||||
|
@ -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
|
/* it's necessary to call ProcessIdle() to update the frames sizes which
|
||||||
// might have been changed (it also will update other things set from
|
might have been changed (it also will update other things set from
|
||||||
// OnUpdateUI() which is a nice (and desired) side effect)
|
OnUpdateUI() which is a nice (and desired) side effect) */
|
||||||
for ( wxWindowList::Node *node = wxTopLevelWindows.GetFirst();
|
for ( wxWindowList::Node *node = wxTopLevelWindows.GetFirst();
|
||||||
node;
|
node;
|
||||||
node = node->GetNext() )
|
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 */
|
/* sent idle event to all who request them */
|
||||||
while (wxTheApp->ProcessIdle()) { }
|
while (wxTheApp->ProcessIdle()) { }
|
||||||
|
|
||||||
@ -192,17 +197,16 @@ gint wxapp_idle_callback( gpointer WXUNUSED(data) )
|
|||||||
emptied */
|
emptied */
|
||||||
g_isIdle = TRUE;
|
g_isIdle = TRUE;
|
||||||
|
|
||||||
/* wake up other threads */
|
/* release lock again */
|
||||||
|
GDK_THREADS_LEAVE ();
|
||||||
wxMutexGuiLeave();
|
|
||||||
wxUsleep(0);
|
|
||||||
wxMutexGuiEnter();
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxapp_install_idle_handler()
|
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
|
/* this routine gets called by all event handlers
|
||||||
indicating that the idle is over. */
|
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
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -230,6 +262,8 @@ wxApp::wxApp()
|
|||||||
|
|
||||||
m_idleTag = gtk_idle_add( wxapp_idle_callback, (gpointer) NULL );
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
wxTimer *timer = (wxTimer*)data;
|
||||||
timer->Notify();
|
timer->Notify();
|
||||||
|
@ -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
|
/* it's necessary to call ProcessIdle() to update the frames sizes which
|
||||||
// might have been changed (it also will update other things set from
|
might have been changed (it also will update other things set from
|
||||||
// OnUpdateUI() which is a nice (and desired) side effect)
|
OnUpdateUI() which is a nice (and desired) side effect) */
|
||||||
for ( wxWindowList::Node *node = wxTopLevelWindows.GetFirst();
|
for ( wxWindowList::Node *node = wxTopLevelWindows.GetFirst();
|
||||||
node;
|
node;
|
||||||
node = node->GetNext() )
|
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 */
|
/* sent idle event to all who request them */
|
||||||
while (wxTheApp->ProcessIdle()) { }
|
while (wxTheApp->ProcessIdle()) { }
|
||||||
|
|
||||||
@ -192,17 +197,16 @@ gint wxapp_idle_callback( gpointer WXUNUSED(data) )
|
|||||||
emptied */
|
emptied */
|
||||||
g_isIdle = TRUE;
|
g_isIdle = TRUE;
|
||||||
|
|
||||||
/* wake up other threads */
|
/* release lock again */
|
||||||
|
GDK_THREADS_LEAVE ();
|
||||||
wxMutexGuiLeave();
|
|
||||||
wxUsleep(0);
|
|
||||||
wxMutexGuiEnter();
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxapp_install_idle_handler()
|
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
|
/* this routine gets called by all event handlers
|
||||||
indicating that the idle is over. */
|
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
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -230,6 +262,8 @@ wxApp::wxApp()
|
|||||||
|
|
||||||
m_idleTag = gtk_idle_add( wxapp_idle_callback, (gpointer) NULL );
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
wxTimer *timer = (wxTimer*)data;
|
||||||
timer->Notify();
|
timer->Notify();
|
||||||
|
@ -47,10 +47,6 @@
|
|||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#endif
|
#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
|
// the key for the pointer to the associated wxThread object
|
||||||
static pthread_key_t gs_keySelf;
|
static pthread_key_t gs_keySelf;
|
||||||
|
|
||||||
#ifndef __WXGTK12__
|
|
||||||
// this mutex must be acquired before any call to a GUI function
|
// this mutex must be acquired before any call to a GUI function
|
||||||
static wxMutex *gs_mutexGui;
|
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
|
// destroy GUI mutex
|
||||||
gs_mutexGui->Unlock();
|
gs_mutexGui->Unlock();
|
||||||
|
|
||||||
delete gs_mutexGui;
|
delete gs_mutexGui;
|
||||||
#endif
|
|
||||||
|
|
||||||
// and free TLD slot
|
// and free TLD slot
|
||||||
(void)pthread_key_delete(gs_keySelf);
|
(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
|
||||||
|
Loading…
Reference in New Issue
Block a user