Diff of /portmidi/porttime/ptlinux.c [22b17b] .. [e1c955] Maximize Restore

  Switch to side-by-side view

--- a/portmidi/porttime/ptlinux.c
+++ b/portmidi/porttime/ptlinux.c
@@ -40,6 +40,7 @@
 static int time_started_flag = FALSE;
 static struct timeb time_offset = {0, 0, 0, 0};
 static pthread_t pt_thread_pid;
+static int pt_thread_created = FALSE;
 
 /* note that this is static data -- we only need one copy */
 typedef struct {
@@ -59,7 +60,7 @@
     /* printf("pt_callback_proc_id %d, id %d\n", pt_callback_proc_id,
            parameters->id); */
     if (geteuid() == 0) setpriority(PRIO_PROCESS, 0, -20);
-	while (pt_callback_proc_id == parameters->id) {
+    while (pt_callback_proc_id == parameters->id) {
         /* wait for a multiple of resolution ms */
         struct timeval timeout;
         int delay = mytime++ * parameters->resolution - Pt_Time();
@@ -91,6 +92,7 @@
         res = pthread_create(&pt_thread_pid, NULL, 
                              Pt_CallbackProc, parms);
         if (res != 0) return ptHostError;
+        pt_thread_created = TRUE;
     }
     time_started_flag = TRUE;
     return ptNoError;
@@ -101,7 +103,10 @@
 {
     /* printf("Pt_Stop called\n"); */
     pt_callback_proc_id++;
-    pthread_join(pt_thread_pid, NULL);
+    if (pt_thread_created) {
+        pthread_join(pt_thread_pid, NULL);
+        pt_thread_created = FALSE;
+    }
     time_started_flag = FALSE;
     return ptNoError;
 }
@@ -124,4 +129,10 @@
 }
 
 
+void Pt_Sleep(int32_t duration)
+{
+    usleep(duration * 1000);
+}
 
+
+