summaryrefslogtreecommitdiff
path: root/libvxi11client/libvxi11client.c
diff options
context:
space:
mode:
Diffstat (limited to 'libvxi11client/libvxi11client.c')
-rw-r--r--libvxi11client/libvxi11client.c29
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;
}