Bug fixed in the Makefile.
[Faustine.git] / interpretor / faust-0.9.47mr3 / architecture / osclib / faust / src / threads / winthreads_impl.cpp
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 #ifdef WIN32
24
25 #include <windows.h>
26
27 #include "TThreads.h"
28
29
30 //_____________________________________________________________________
31 static DWORD WINAPI baseThreadProc (LPVOID ptr)
32 {
33 TThreads* thread = (TThreads*)ptr;
34 thread->running (true);
35 thread->run();
36 thread->running (false);
37 return 0;
38 }
39
40 //_____________________________________________________________________
41 TThreads::TThreads () : fThread(0) {}
42
43 //_____________________________________________________________________
44 int TThreads::SetPriority (int priority)
45 {
46 if (!SetThreadPriority (fThread, priority))
47 return TRUE;
48 return FALSE;
49 }
50
51 //_____________________________________________________________________
52 bool TThreads::start (int priority)
53 {
54 DWORD id;
55 fThread = CreateThread(NULL, 0, baseThreadProc, this, 0, &id);
56 if (fThread) {
57 SetPriority (priority);
58 return true;
59 }
60 return false;
61 }
62
63 //_____________________________________________________________________
64 void TThreads::quit ()
65 {
66 if (fThread) {
67 WaitForSingleObject (fThread, 1000);
68 CloseHandle (fThread);
69 fThread = 0;
70 }
71 }
72
73 #endif