From: Grazvydas Ignotas Date: Mon, 9 Apr 2012 18:39:44 +0000 (+0300) Subject: op_runfbapp: fix thread and fbapp race X-Git-Tag: sz_beta4~3 X-Git-Url: http://git.openpandora.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a635e319f34ed70ff6d49b5b7c4bdaf80d1180b;p=pandora-misc.git op_runfbapp: fix thread and fbapp race --- diff --git a/op_runfbapp.c b/op_runfbapp.c index 8488aaa..495b493 100644 --- a/op_runfbapp.c +++ b/op_runfbapp.c @@ -44,6 +44,15 @@ static struct termios g_kbd_termios_saved; static int g_kbdfd; +static pthread_cond_t g_start_cond = PTHREAD_COND_INITIALIZER; +static pthread_mutex_t g_start_mutex = PTHREAD_MUTEX_INITIALIZER; + +static void signal_main_thread(void) +{ + pthread_mutex_lock(&g_start_mutex); + pthread_cond_signal(&g_start_cond); + pthread_mutex_unlock(&g_start_mutex); +} static Cursor transparent_cursor(Display *display, Window win) { @@ -74,6 +83,7 @@ static void *x11_handler(void *arg) { fprintf(stderr, PFX "(not hiding X): Can't open display: %s\n", XDisplayName(NULL)); + signal_main_thread(); return NULL; } @@ -95,14 +105,17 @@ static void *x11_handler(void *arg) XSelectInput(display, win, ExposureMask); XMapWindow(display, win); XGrabKeyboard(display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime); + XSync(display, False); while (1) { XNextEvent(display, &report); - if (report.type == Expose) + if (report.type == Expose) { + signal_main_thread(); while (XCheckTypedEvent(display, Expose, &report)) ; + } } return NULL; @@ -196,6 +209,8 @@ int main(int argc, char *argv[]) pthread_t tid; int ret; + pthread_mutex_lock(&g_start_mutex); + ret = pthread_create(&tid, NULL, x11_handler, NULL); if (ret != 0) { fprintf(stderr, PFX "pthread_create: %d\n", ret); @@ -203,6 +218,9 @@ int main(int argc, char *argv[]) } pthread_detach(tid); + pthread_cond_wait(&g_start_cond, &g_start_mutex); + pthread_mutex_unlock(&g_start_mutex); + hidecon_start(); do_exec(argv + 1);