Fix GTK threading deadlock

pull/2/head
Timothy Pearson 11 years ago
parent 5df139de98
commit 5aa389f311

@ -100,6 +100,8 @@ public:
exitloop = FALSE; exitloop = FALSE;
shortcut = FALSE; shortcut = FALSE;
singletoolkit = TRUE; singletoolkit = TRUE;
ctx = 0;
ctx_is_default = false;
} }
int looplevel; int looplevel;
@ -129,6 +131,7 @@ public:
// main context // main context
GMainContext *ctx; GMainContext *ctx;
bool ctx_is_default;
}; };
#endif // QEVENTLOOP_GLIB_P_H #endif // QEVENTLOOP_GLIB_P_H

@ -79,8 +79,7 @@ static GSourceFuncs qt_gsource_funcs = {
// forward main loop callbacks to QEventLoop methods! // forward main loop callbacks to QEventLoop methods!
static gboolean qt_gsource_prepare ( GSource *source, static gboolean qt_gsource_prepare ( GSource *source, gint *timeout )
gint *timeout )
{ {
QtGSource * qtGSource = (QtGSource*) source; QtGSource * qtGSource = (QtGSource*) source;
QEventLoop* candidateEventLoop = qtGSource->qeventLoop; QEventLoop* candidateEventLoop = qtGSource->qeventLoop;
@ -95,7 +94,7 @@ static gboolean qt_gsource_prepare ( GSource *source,
} }
} }
static gboolean qt_gsource_check ( GSource *source ) static gboolean qt_gsource_check ( GSource *source )
{ {
QtGSource * qtGSource = (QtGSource*) source; QtGSource * qtGSource = (QtGSource*) source;
QEventLoop* candidateEventLoop = qtGSource->qeventLoop; QEventLoop* candidateEventLoop = qtGSource->qeventLoop;
@ -110,8 +109,7 @@ static gboolean qt_gsource_check ( GSource *source )
} }
} }
static gboolean qt_gsource_dispatch ( GSource *source, static gboolean qt_gsource_dispatch ( GSource *source, GSourceFunc callback, gpointer user_data )
GSourceFunc callback, gpointer user_data )
{ {
Q_UNUSED(callback); Q_UNUSED(callback);
Q_UNUSED(user_data); Q_UNUSED(user_data);
@ -215,6 +213,7 @@ void QEventLoop::init()
// new main context for thread // new main context for thread
d->ctx = g_main_context_new(); d->ctx = g_main_context_new();
g_main_context_push_thread_default(d->ctx); g_main_context_push_thread_default(d->ctx);
d->ctx_is_default = true;
// new GSource // new GSource
QtGSource * qtGSource = (QtGSource*) g_source_new(&qt_gsource_funcs, sizeof(QtGSource)); QtGSource * qtGSource = (QtGSource*) g_source_new(&qt_gsource_funcs, sizeof(QtGSource));
@ -241,9 +240,9 @@ void QEventLoop::init()
d->threadPipe_gPollFD.fd = d->thread_pipe[0]; d->threadPipe_gPollFD.fd = d->thread_pipe[0];
d->threadPipe_gPollFD.events = G_IO_IN | G_IO_HUP | G_IO_ERR; d->threadPipe_gPollFD.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
g_source_add_poll(d->gSource, &d->threadPipe_gPollFD); g_source_add_poll(d->gSource, &d->threadPipe_gPollFD);
#ifdef DEBUG_QT_GLIBMAINLOOP #ifdef DEBUG_QT_GLIBMAINLOOP
printf("inside init(2)\n"); printf("inside init(2)\n");
#endif #endif
@ -375,7 +374,7 @@ bool QEventLoop::processX11Events()
} }
bool QEventLoop::gsourcePrepare(GSource *gs, int * timeout) bool QEventLoop::gsourcePrepare(GSource *gs, int * timeout)
{ {
Q_UNUSED(gs); Q_UNUSED(gs);
@ -428,7 +427,7 @@ bool QEventLoop::gsourcePrepare(GSource *gs, int * timeout)
#ifdef DEBUG_QT_GLIBMAINLOOP #ifdef DEBUG_QT_GLIBMAINLOOP
printf("inside gsourcePrepare(2) canwait=%d\n", canWait); printf("inside gsourcePrepare(2) canwait=%d\n", canWait);
#endif #endif
if ( canWait ) { if ( canWait ) {
emit aboutToBlock(); emit aboutToBlock();
@ -440,7 +439,7 @@ bool QEventLoop::gsourcePrepare(GSource *gs, int * timeout)
(**it)(); (**it)();
} }
#ifdef DEBUG_QT_GLIBMAINLOOP #ifdef DEBUG_QT_GLIBMAINLOOP
printf("inside gsourcePrepare(2.1) canwait=%d\n", canWait); printf("inside gsourcePrepare(2.1) canwait=%d\n", canWait);
#endif #endif
@ -649,4 +648,17 @@ void QEventLoop::appClosingDown()
void QEventLoop::setSingleToolkitEventHandling(bool enabled) { void QEventLoop::setSingleToolkitEventHandling(bool enabled) {
d->singletoolkit = enabled; d->singletoolkit = enabled;
if (!d->singletoolkit) {
if (d->ctx_is_default) {
d->ctx_is_default = false;
g_main_context_pop_thread_default(d->ctx);
}
}
else {
if (!d->ctx_is_default) {
g_main_context_push_thread_default(d->ctx);
d->ctx_is_default = true;
}
}
} }
Loading…
Cancel
Save