upgrade libvpx+lv2, fix dbl tap play bug, add multi nest/unnest clips, add del top...
[goodguy/cinelerra.git] / cinelerra-5.1 / libzmpeg3 / thread.C
1 #include "thread.h"
2 #include <stdio.h>
3 #include <signal.h>
4
5 void *
6 Thread::ThreadProc (void *param)
7 {
8   Thread *thread = (Thread *) param;
9   int r = mutexLock(thread->mutex);
10   if (r < 0) {
11     thread->running = false;
12     perror ("ThreadProc:mutexLock");
13     return 0;
14   }
15   thread->Proc ();
16   thread->running = false;
17
18   // this unsuspends a waiting "Kill" below
19   r = mutexUnlock (thread->mutex);
20   if (r < 0) {
21     perror("ThreadProc:mutexUnlock");
22   }
23   return 0;
24 }
25
26 void
27 Thread::Run ()
28 {
29   if (!running) {
30     running = true;
31     int r = threadCreate(p,ThreadProc,this);
32     if (r != 0) {
33       running = false;
34       perror ("Thread::Run:threadCreate");
35     }
36   }
37 }
38
39 void
40 Thread::Kill ()
41 {
42   if (running) {
43     running = false;            // signals thread to stop
44     // now wait for clean thread exit (mutex unlock)
45     mutexLock(mutex);
46     mutexUnlock(mutex);
47   }
48 }
49
50 static void sigquit(int sig) {}
51 void
52 Thread::Kill1()
53 {
54   if (running) {
55     void (*ohr)(int sig) = signal(SIGQUIT,sigquit);
56     running = false;            // signals thread to stop
57     // now wait for clean thread exit (mutex unlock)
58     threadKill(p);    // give it a push
59     mutexLock(mutex);
60     mutexUnlock(mutex);
61     signal(SIGQUIT,ohr);
62   }
63 }
64