remove Features5, rework gradient plugin, fix paste_edl track title bug, gl_probe...
[goodguy/cinelerra.git] / cinelerra-5.1 / libzmpeg3 / thread.h
1 #ifndef _included_thread
2 #define _included_thread
3
4 #ifdef TCL_THREADS
5 #include <tcl.h>
6 #define ThreadId Tcl_ThreadId
7 #define tMutex Tcl_Mutex
8 #define mutexInit(m) m = NULL
9 #define mutexDestroy(m) Tcl_MutexFinalize(&m)
10 #define mutexLock(m) (Tcl_MutexLock(&m), 0)
11 #define mutexUnlock(m) (Tcl_MutexUnlock(&m), 0)
12 #define threadCreate(p,fn,dt) Tcl_CreateThread(&p,v##fn,dt,TCL_THREAD_STACK_DEFAULT,0)
13 #define threadKill(p)
14 #else
15 #include <pthread.h>
16 #define ThreadId pthread_t
17 #define tMutex pthread_mutex_t
18 #define mutexInit(m) pthread_mutex_init(&m,0)
19 #define mutexDestroy(m) pthread_mutex_destroy(&m)
20 #define mutexLock(m) pthread_mutex_lock(&m)
21 #define mutexUnlock(m) pthread_mutex_unlock(&m)
22 #define threadCreate(p,fn,dt) pthread_create(&p,0,fn,dt)
23 #define threadKill(p) pthread_kill(p,SIGQUIT)
24 #endif
25
26 class Thread
27 {
28 private:
29   bool running;
30   ThreadId p;
31   tMutex mutex;
32   static void *ThreadProc (void *);
33   friend void vThreadProc (void *param) { ThreadProc(param); }
34 public:  Thread ():running (false)
35   {
36     mutexInit(mutex);
37   }
38   virtual ~ Thread ()
39   {
40     Kill ();
41     mutexDestroy(mutex);
42   }
43   void Run ();
44   void PostKill ()
45   {
46     running = false;
47   }
48   void Kill ();
49   void Kill1();
50   bool Running ()
51   {
52     return running;
53   }
54   virtual void Proc () = 0;
55   void Lock() { mutexLock(mutex); }
56   void Unlock() { mutexUnlock(mutex); }
57 };
58
59 #endif /*  */