Install, Readme and Changes files updated.
[Faustine.git] / interpretor / faust-0.9.47mr3 / architecture / osclib / faust / src / threads / TThreads.h
1 /*
2
3 Copyright (C) 2011 Grame
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library 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 GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Grame Research Laboratory, 9 rue du Garet, 69001 Lyon - France
20 research@grame.fr
21
22 */
23
24
25 #ifndef __TThreads__
26 #define __TThreads__
27
28 #ifdef WIN32
29
30 #include <windows.h>
31 #define ThreadAPI(proc, arg) DWORD WINAPI proc (LPVOID arg)
32
33 typedef LPTHREAD_START_ROUTINE ThreadProcPtr;
34 typedef HANDLE ThreadHandle;
35
36 #else
37
38 #include <pthread.h>
39 #define ThreadAPI(proc, arg) void * proc (void * arg)
40
41 typedef void * ( * ThreadProcPtr) (void * ptr);
42 typedef pthread_t ThreadHandle;
43
44 #endif
45
46 //___________________________________________________________________
47 /*!
48 \brief cross platform threads support
49
50 Based on pthread on linux and mac and
51 Windows native threads on Windows
52 */
53 class TThreads
54 {
55 public:
56 enum { kNormalPriority=0 };
57
58 TThreads ();
59 virtual ~TThreads () { quit (); }
60
61 virtual void run() = 0;
62
63 bool start (int priority = kNormalPriority);
64 bool isRunning () const { return fRunning; }
65 void quit();
66
67 void running (bool state) { fRunning = state; }
68
69 private:
70 int SetPriority (int priority);
71
72 bool fRunning;
73 ThreadHandle fThread; // the thread handler
74 };
75
76 #endif