Dmitry Baikov patch for JackGraphManager.cpp.
[jack2.git] / common / JackThreadedDriver.cpp
bloba315da719c6c90a86a9b7ad90b9774c50461c7d6
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 #ifdef WIN32
22 #pragma warning (disable : 4786)
23 #endif
25 #include "JackThreadedDriver.h"
26 #include "JackError.h"
27 #include "JackGlobals.h"
28 #include "JackClient.h"
29 #include "JackEngineControl.h"
31 namespace Jack
34 JackThreadedDriver::JackThreadedDriver(JackDriverClient* driver)
36 fThread = JackGlobals::MakeThread(this);
37 fDriver = driver;
40 JackThreadedDriver::~JackThreadedDriver()
42 delete fThread;
43 delete fDriver;
46 int JackThreadedDriver::Start()
48 JackLog("JackThreadedDriver::Start\n");
49 int res;
51 if ((res = fDriver->Start()) < 0) {
52 jack_error("Cannot start driver");
53 return res;
55 if ((res = fThread->Start()) < 0) {
56 jack_error("Cannot start thread");
57 return res;
60 if (fDriver->IsRealTime()) {
61 JackLog("JackThreadedDriver::Start IsRealTime\n");
62 // Will do "something" on OSX only...
63 // fThread->SetParams(fDriver->fEngineControl->fPeriod, fDriver->fEngineControl->fComputation, fDriver->fEngineControl->fConstraint);
64 if (fThread->AcquireRealTime(GetEngineControl()->fPriority) < 0) {
65 jack_error("AcquireRealTime error");
69 return 0;
72 int JackThreadedDriver::Stop()
74 JackLog("JackThreadedDriver::Stop\n");
75 int res;
77 if ((res = fThread->Stop()) < 0) { // Stop when the thread cycle is finished
78 jack_error("Cannot stop thread");
79 return res;
81 if ((res = fDriver->Stop()) < 0) {
82 jack_error("Cannot stop driver");
83 return res;
85 return 0;
88 bool JackThreadedDriver::Execute()
90 return (Process() == 0);
93 } // end of namespace