summaryrefslogtreecommitdiffstats
path: root/core/Thread.h
blob: 0a09fabc9a9913f2d9f51c6dd20247e7f8f95d22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* $Id: Thread.h,v 1.19 2003/10/09 16:03:51 titer Exp $

   This file is part of the HandBrake source code.
   Homepage: <http://beos.titer.org/handbrake/>.
   It may be used under the terms of the GNU General Public License. */

#ifndef HB_THREAD_H
#define HB_THREAD_H

#include "Common.h"

#if defined( SYS_BEOS )
#  define HB_LOW_PRIORITY    5
#  define HB_NORMAL_PRIORITY 10
#elif defined( SYS_MACOSX )
#  define HB_LOW_PRIORITY    0
#  define HB_NORMAL_PRIORITY 31
#elif defined( SYS_LINUX )
/* Actually unused */
#  define HB_LOW_PRIORITY    0
#  define HB_NORMAL_PRIORITY 0
#endif

class HBThread
{
    public:
                      HBThread( char * name,
                                int priority = HB_LOW_PRIORITY );
        virtual       ~HBThread();
        void          Suspend();
        void          Resume();
        int           GetPid();

    protected:
        void          Run();
        bool          Push( HBFifo * fifo, HBBuffer * buffer );
        HBBuffer *    Pop( HBFifo * fifo );

        volatile bool fDie;
        volatile bool fSuspend;

    private:
        static void   ThreadFunc( HBThread * _this );
        virtual void  DoWork();

        char        * fName;
        int           fPriority;

#if defined( SYS_BEOS )
        int           fThread;
#elif defined( SYS_MACOSX ) || defined( SYS_LINUX )
        pthread_t     fThread;
#endif
        int           fPid;
};

#if defined( SYS_BEOS )
class BLocker;
#endif

class HBLock
{
    public:
                          HBLock();
                          ~HBLock();
        void              Lock();
        void              Unlock();

    private:
#if defined( SYS_BEOS )
        BLocker         * fLocker;
#elif defined( SYS_MACOSX ) || defined( SYS_LINUX )
        pthread_mutex_t   fMutex;
#endif
};

#endif