Dmitry Baikov jackmp-time patch: add jack_get_time, jack_time_to_frames, jack_frames_...
[jack2.git] / common / JackThread.h
blob1a7aad001c0037ff1c9403c7144d47c3c0db5dac
1 /*
2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2006 Grame
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef __JackThread__
22 #define __JackThread__
24 #ifdef WIN32
25 #include <windows.h>
26 typedef HANDLE pthread_t;
27 typedef ULONGLONG UInt64;
28 #else
29 #include <pthread.h>
30 typedef unsigned long long UInt64;
31 #endif
33 namespace Jack
36 /*!
37 \brief The base class for runnable objects, that have an <B> Init </B> and <B> Execute </B> method to be called in a thread.
40 class JackRunnableInterface
43 public:
45 JackRunnableInterface()
47 virtual ~JackRunnableInterface()
50 virtual bool Init() /*! Called once when the thread is started */
52 return true;
54 virtual bool Execute() = 0; /*! Must be implemented by subclasses */
57 /*!
58 \brief The thread base class.
61 class JackThread
64 protected:
66 JackRunnableInterface* fRunnable;
67 int fPriority;
68 bool fRealTime;
69 volatile bool fRunning;
70 int fCancellation;
72 public:
74 JackThread(JackRunnableInterface* runnable, int priority, bool real_time, int cancellation):
75 fRunnable(runnable), fPriority(priority), fRealTime(real_time), fRunning(false), fCancellation(cancellation)
77 virtual ~JackThread()
80 virtual int Start() = 0;
81 virtual int StartSync() = 0;
82 virtual int Kill() = 0;
83 virtual int Stop() = 0;
85 virtual int AcquireRealTime() = 0;
86 virtual int AcquireRealTime(int priority) = 0;
87 virtual int DropRealTime() = 0;
89 virtual void SetParams(UInt64 period, UInt64 computation, UInt64 constraint) // Empty implementation, will only make sense on OSX...
92 virtual pthread_t GetThreadID() = 0;
95 } // end of namespace
97 #endif