root/trunk/libffado/src/libutil/Thread.h

Revision 864, 3.2 kB (checked in by ppalmers, 16 years ago)

update license to GPLv2 or GPLv3 instead of GPLv2 or any later version. Update copyrights to reflect the new year

Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 /*
25  * Copied from the jackd/jackdmp sources
26  * function names changed in order to avoid naming problems when using this in
27  * a jackd backend.
28  */
29
30 /* Original license:
31  *
32  *  Copyright (C) 2001 Paul Davis
33  *  Copyright (C) 2004-2006 Grame
34  *
35  *  This program is free software; you can redistribute it and/or modify
36  *  it under the terms of the GNU General Public License as published by
37  *  the Free Software Foundation; either version 2 of the License, or
38  *  (at your option) version 3 of the License.
39  *
40  *  This program is distributed in the hope that it will be useful,
41  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
42  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
43  *  GNU General Public License for more details.
44  *
45  *  You should have received a copy of the GNU General Public License
46  *  along with this program; if not, write to the Free Software
47  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
48  *
49  */
50
51 #ifndef __THREAD__
52 #define __THREAD__
53
54 #include "../debugmodule/debugmodule.h"
55
56 #include "Atomic.h"
57 #include <pthread.h>
58
59 namespace Util
60 {
61
62 /*!
63 \brief The base class for runnable objects, that have an <B> Init </B> and <B> Execute </B> method to be called in a thread.
64 */
65
66 class RunnableInterface
67 {
68
69     public:
70
71         RunnableInterface()
72         {}
73         virtual ~RunnableInterface()
74         {}
75
76         virtual bool Init()          /*! Called once when the thread is started */
77         {
78             return true;
79         }
80         virtual bool Execute() = 0;  /*! Must be implemented by subclasses */
81 };
82
83 /*!
84 \brief The thread base class.
85 */
86
87 class Thread
88 {
89
90     protected:
91
92         RunnableInterface* fRunnable;
93
94     public:
95
96         Thread(RunnableInterface* runnable): fRunnable(runnable)
97         {}
98         virtual ~Thread()
99         {}
100
101         virtual int Start() = 0;
102         virtual int Kill() = 0;
103         virtual int Stop() = 0;
104
105         virtual int AcquireRealTime() = 0;
106         virtual int AcquireRealTime(int priority) = 0;
107         virtual int DropRealTime() = 0;
108
109         virtual void SetParams(UInt64 period, UInt64 computation, UInt64 constraint) // Empty implementation, will only make sense on OSX...
110         {}
111
112         virtual pthread_t GetThreadID() = 0;
113
114         virtual void setVerboseLevel(int l)
115             {setDebugLevel(l);};
116     protected:
117             DECLARE_DEBUG_MODULE;
118
119 };
120
121 } // end of namespace
122
123 #endif
Note: See TracBrowser for help on using the browser.