summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaniel <danieruru@gmail.com>2013-01-19 03:32:40 +0900
committerdaniel <danieruru@gmail.com>2013-01-19 03:32:40 +0900
commitd5bd5c44706dffd9977f1cbf9dd6ca4860bbb37d (patch)
tree51d1acaf8ca7e2bfaa8cafb26ec41eff47f3c52f
parent4e01ae716c25937daa7d1c82e6d0da8fdd0ad857 (diff)
use fancy glib stuff to wait for the interrupt thread to start instead of spinning
-rw-r--r--libvxi11client/libvxi11client.c29
-rw-r--r--libvxi11client/perlbits/perlglue.c3
2 files changed, 26 insertions, 6 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;
}
diff --git a/libvxi11client/perlbits/perlglue.c b/libvxi11client/perlbits/perlglue.c
index 902f915..dec97c2 100644
--- a/libvxi11client/perlbits/perlglue.c
+++ b/libvxi11client/perlbits/perlglue.c
@@ -43,6 +43,7 @@ VXI11Context* glue_open(char* address, char* device) {
int glue_start_interrupt_server() {
interruptqueue = g_async_queue_new();
+ g_async_queue_ref(interruptqueue);
return vxi11_start_interrupt_server(interruptcallback);
}
@@ -54,7 +55,7 @@ int glue_stop_interrupt_server() {
freeevent(event);
}
freelast();
- g_free(interruptqueue);
+ g_async_queue_unref(interruptqueue);
return ret;
}