Jack2 1.9.6

JackWaitThreadedDriver.cpp

00001 /*
00002  Copyright (C) 2001 Paul Davis
00003  Copyright (C) 2004-2008 Grame
00004 
00005  This program is free software; you can redistribute it and/or modify
00006  it under the terms of the GNU General Public License as published by
00007  the Free Software Foundation; either version 2 of the License, or
00008  (at your option) any later version.
00009 
00010  This program is distributed in the hope that it will be useful,
00011  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  GNU General Public License for more details.
00014 
00015  You should have received a copy of the GNU General Public License
00016  along with this program; if not, write to the Free Software
00017  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 */
00020 
00021 #include "JackSystemDeps.h"
00022 #include "JackWaitThreadedDriver.h"
00023 #include "JackGlobals.h"
00024 #include "JackClient.h"
00025 #include "JackEngineControl.h"
00026 #include "JackException.h"
00027 #include "JackError.h"
00028 
00029 namespace Jack
00030 {
00031 
00032 bool JackWaitThreadedDriver::Init()
00033 {
00034     return (fStarter.Start() == 0);
00035 }
00036 
00037 bool JackWaitThreadedDriver::Execute()
00038 {
00039     try {
00040         // Process a null cycle until NetDriver has started
00041         while (!fStarter.fRunning && fThread.GetStatus() == JackThread::kRunning) {
00042             fDriver->ProcessNull();
00043         }
00044 
00045         // Set RT
00046         if (fDriver->IsRealTime()) {
00047             jack_log("JackWaitThreadedDriver::Init IsRealTime");
00048             // Will do "something" on OSX only...
00049             GetEngineControl()->fPeriod = GetEngineControl()->fConstraint = GetEngineControl()->fPeriodUsecs * 1000;
00050             fThread.SetParams(GetEngineControl()->fPeriod, GetEngineControl()->fComputation, GetEngineControl()->fConstraint);
00051             if (fThread.AcquireSelfRealTime(GetEngineControl()->fServerPriority) < 0) {
00052                 jack_error("AcquireSelfRealTime error");
00053             } else {
00054                 set_threaded_log_function();
00055             }
00056         }
00057 
00058         // Switch to keep running even in case of error
00059         while (fThread.GetStatus() == JackThread::kRunning) {
00060             fDriver->Process();
00061         }
00062         return false;
00063     } catch (JackNetException& e) {
00064         e.PrintMessage();
00065         jack_info("Driver is restarted");
00066         fThread.DropSelfRealTime();
00067         // Thread in kIniting status again...
00068         fThread.SetStatus(JackThread::kIniting);
00069         if (Init()) {
00070             // Thread in kRunning status again...
00071             fThread.SetStatus(JackThread::kRunning);
00072             return true;
00073         } else {
00074             return false;
00075         }
00076         }
00077 }
00078 
00079 } // end of namespace