Implemented the thread checks on GTK+.
This commit is contained in:
parent
fd770430a9
commit
4815629eef
18
unix/main.c
18
unix/main.c
|
@ -6,6 +6,9 @@ const char **uiprivSysInitErrors(void)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static pthread_t mainThread;
|
||||||
|
static gboolean initialized = FALSE; // TODO deduplicate this from common/init.c
|
||||||
|
|
||||||
int uiprivSysInit(void *options, uiInitError *err)
|
int uiprivSysInit(void *options, uiInitError *err)
|
||||||
{
|
{
|
||||||
GError *gerr = NULL;
|
GError *gerr = NULL;
|
||||||
|
@ -16,16 +19,22 @@ int uiprivSysInit(void *options, uiInitError *err)
|
||||||
g_error_free(gerr);
|
g_error_free(gerr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
mainThread = pthread_self();
|
||||||
|
initialized = TRUE;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiMain(void)
|
void uiMain(void)
|
||||||
{
|
{
|
||||||
|
if (!uiprivCheckInitializedAndThread())
|
||||||
|
return;
|
||||||
gtk_main();
|
gtk_main();
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiQuit(void)
|
void uiQuit(void)
|
||||||
{
|
{
|
||||||
|
if (!uiprivCheckInitializedAndThread())
|
||||||
|
return;
|
||||||
gtk_main_quit();
|
gtk_main_quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,12 +56,21 @@ void uiQueueMain(void (*f)(void *data), void *data)
|
||||||
{
|
{
|
||||||
struct queued *q;
|
struct queued *q;
|
||||||
|
|
||||||
|
if (!initialized) {
|
||||||
|
uiprivProgrammerError(uiprivProgrammerErrorNotInitialized, uiprivFunc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
q = g_new0(struct queued, 1);
|
q = g_new0(struct queued, 1);
|
||||||
q->f = f;
|
q->f = f;
|
||||||
q->data = data;
|
q->data = data;
|
||||||
gdk_threads_add_idle(doqueued, q);
|
gdk_threads_add_idle(doqueued, q);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool uiprivSysCheckThread(void)
|
||||||
|
{
|
||||||
|
return pthread_equal(pthread_self(), mainThread);
|
||||||
|
}
|
||||||
|
|
||||||
void uiprivReportError(const char *prefix, const char *msg, const char *suffix, bool internal)
|
void uiprivReportError(const char *prefix, const char *msg, const char *suffix, bool internal)
|
||||||
{
|
{
|
||||||
g_critical("%s: %s. %s", prefix, msg, suffix);
|
g_critical("%s: %s. %s", prefix, msg, suffix);
|
||||||
|
|
Loading…
Reference in New Issue