1 |
/* |
---|
2 |
Modifications for Freebob (C) 2006, Pieter Palmers |
---|
3 |
|
---|
4 |
Copied from the jackd/jackdmp sources |
---|
5 |
function names changed in order to avoid naming problems when using this in |
---|
6 |
a jackd backend. |
---|
7 |
|
---|
8 |
Copyright (C) 2001 Paul Davis |
---|
9 |
Copyright (C) 2004-2006 Grame |
---|
10 |
|
---|
11 |
This program is free software; you can redistribute it and/or modify |
---|
12 |
it under the terms of the GNU General Public License as published by |
---|
13 |
the Free Software Foundation; either version 2 of the License, or |
---|
14 |
(at your option) any later version. |
---|
15 |
|
---|
16 |
This program is distributed in the hope that it will be useful, |
---|
17 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 |
GNU General Public License for more details. |
---|
20 |
|
---|
21 |
You should have received a copy of the GNU General Public License |
---|
22 |
along with this program; if not, write to the Free Software |
---|
23 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
24 |
|
---|
25 |
*/ |
---|
26 |
|
---|
27 |
#ifndef __POSIXTHREAD__ |
---|
28 |
#define __POSIXTHREAD__ |
---|
29 |
|
---|
30 |
#include "Thread.h" |
---|
31 |
#include <pthread.h> |
---|
32 |
|
---|
33 |
namespace Util |
---|
34 |
{ |
---|
35 |
|
---|
36 |
/*! |
---|
37 |
\brief The POSIX thread base class. |
---|
38 |
*/ |
---|
39 |
|
---|
40 |
class PosixThread : public Thread |
---|
41 |
{ |
---|
42 |
|
---|
43 |
protected: |
---|
44 |
|
---|
45 |
pthread_t fThread; |
---|
46 |
int fPriority; |
---|
47 |
bool fRealTime; |
---|
48 |
volatile bool fRunning; |
---|
49 |
int fCancellation; |
---|
50 |
|
---|
51 |
static void* ThreadHandler(void* arg); |
---|
52 |
|
---|
53 |
public: |
---|
54 |
|
---|
55 |
PosixThread(RunnableInterface* runnable, bool real_time, int priority, int cancellation) |
---|
56 |
: Thread(runnable), fThread((pthread_t)NULL), fPriority(priority), fRealTime(real_time), fRunning(false), fCancellation(cancellation) |
---|
57 |
{} |
---|
58 |
PosixThread(RunnableInterface* runnable) |
---|
59 |
: Thread(runnable), fThread((pthread_t)NULL), fPriority(0), fRealTime(false), fRunning(false), fCancellation(PTHREAD_CANCEL_DEFERRED) |
---|
60 |
{} |
---|
61 |
PosixThread(RunnableInterface* runnable, int cancellation) |
---|
62 |
: Thread(runnable), fThread((pthread_t)NULL), fPriority(0), fRealTime(false), fRunning(false), fCancellation(cancellation) |
---|
63 |
{} |
---|
64 |
|
---|
65 |
virtual ~PosixThread() |
---|
66 |
{} |
---|
67 |
|
---|
68 |
virtual int Start(); |
---|
69 |
virtual int Kill(); |
---|
70 |
virtual int Stop(); |
---|
71 |
|
---|
72 |
virtual int AcquireRealTime(); |
---|
73 |
virtual int AcquireRealTime(int priority); |
---|
74 |
virtual int DropRealTime(); |
---|
75 |
|
---|
76 |
pthread_t GetThreadID(); |
---|
77 |
|
---|
78 |
protected: |
---|
79 |
|
---|
80 |
}; |
---|
81 |
|
---|
82 |
} // end of namespace |
---|
83 |
|
---|
84 |
|
---|
85 |
#endif |
---|