OSDN Git Service

HandBrake 0.4
[handbrake-jp/handbrake-jp-git.git] / core / Thread.h
1 /* $Id: Thread.h,v 1.19 2003/10/09 16:03:51 titer Exp $
2
3    This file is part of the HandBrake source code.
4    Homepage: <http://beos.titer.org/handbrake/>.
5    It may be used under the terms of the GNU General Public License. */
6
7 #ifndef HB_THREAD_H
8 #define HB_THREAD_H
9
10 #include "Common.h"
11
12 #if defined( SYS_BEOS )
13 #  define HB_LOW_PRIORITY    5
14 #  define HB_NORMAL_PRIORITY 10
15 #elif defined( SYS_MACOSX )
16 #  define HB_LOW_PRIORITY    0
17 #  define HB_NORMAL_PRIORITY 31
18 #elif defined( SYS_LINUX )
19 /* Actually unused */
20 #  define HB_LOW_PRIORITY    0
21 #  define HB_NORMAL_PRIORITY 0
22 #endif
23
24 class HBThread
25 {
26     public:
27                       HBThread( char * name,
28                                 int priority = HB_LOW_PRIORITY );
29         virtual       ~HBThread();
30         void          Suspend();
31         void          Resume();
32         int           GetPid();
33
34     protected:
35         void          Run();
36         bool          Push( HBFifo * fifo, HBBuffer * buffer );
37         HBBuffer *    Pop( HBFifo * fifo );
38
39         volatile bool fDie;
40         volatile bool fSuspend;
41
42     private:
43         static void   ThreadFunc( HBThread * _this );
44         virtual void  DoWork();
45
46         char        * fName;
47         int           fPriority;
48
49 #if defined( SYS_BEOS )
50         int           fThread;
51 #elif defined( SYS_MACOSX ) || defined( SYS_LINUX )
52         pthread_t     fThread;
53 #endif
54         int           fPid;
55 };
56
57 #if defined( SYS_BEOS )
58 class BLocker;
59 #endif
60
61 class HBLock
62 {
63     public:
64                           HBLock();
65                           ~HBLock();
66         void              Lock();
67         void              Unlock();
68
69     private:
70 #if defined( SYS_BEOS )
71         BLocker         * fLocker;
72 #elif defined( SYS_MACOSX ) || defined( SYS_LINUX )
73         pthread_mutex_t   fMutex;
74 #endif
75 };
76
77 #endif