diff options
author | daniel <danieruru@gmail.com> | 2013-01-19 03:32:40 +0900 |
---|---|---|
committer | daniel <danieruru@gmail.com> | 2013-01-19 03:32:40 +0900 |
commit | d5bd5c44706dffd9977f1cbf9dd6ca4860bbb37d (patch) | |
tree | 51d1acaf8ca7e2bfaa8cafb26ec41eff47f3c52f /libvxi11client/libvxi11client.c | |
parent | 4e01ae716c25937daa7d1c82e6d0da8fdd0ad857 (diff) |
use fancy glib stuff to wait for the interrupt thread to start instead of spinning
Diffstat (limited to 'libvxi11client/libvxi11client.c')
-rw-r--r-- | libvxi11client/libvxi11client.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/libvxi11client/libvxi11client.c b/libvxi11client/libvxi11client.c index f2de6bb..3233cf0 100644 --- a/libvxi11client/libvxi11client.c +++ b/libvxi11client/libvxi11client.c @@ -29,6 +29,8 @@ static GThread* interruptthread; static void (*interruptcallback)(char*) = NULL; static bool interruptserverstarted = false; static unsigned int interruptserverport = -1; +static GMutex* mutex; +static GCond* cond; void * device_intr_srq_1_svc(Device_SrqParms *argp, struct svc_req *rqstp) { @@ -374,7 +376,11 @@ static gpointer interruptthreadfunc(gpointer data) { fprintf(stderr, "%s", "unable to register (DEVICE_INTR, DEVICE_INTR_VERSION, tcp).\n"); return 0; } - *((unsigned int*) data) = transp->xp_port; + + interruptserverport = transp->xp_port; + g_mutex_lock(mutex); + g_cond_signal(cond); + g_mutex_unlock(mutex); int i; struct pollfd *my_pollfd = NULL; @@ -426,13 +432,26 @@ int vxi11_start_interrupt_server(void (*callback)(char* handle)) { interruptcallback = callback; interruptserverstarted = true; g_thread_init(NULL); - interruptthread = g_thread_create(interruptthreadfunc, &interruptserverport, true, NULL); + mutex = g_mutex_new(); + cond = g_cond_new(); + g_mutex_lock(mutex); + interruptthread = g_thread_create(interruptthreadfunc, NULL, true, NULL); if (interruptthread == NULL) return 0; - while (interruptserverport == -1) { // spin - usleep(200); - }; +#ifdef DEBUG + printf("Waiting for interrupt server to start\n"); +#endif + g_cond_wait(cond, mutex); + g_mutex_unlock(mutex); + g_cond_free(cond); + g_mutex_free(mutex); + cond = NULL; + mutex = NULL; + + if (interruptserverport == -1) + return 0; + return 1; } |