jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.5KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2004-2008 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #if defined(HAVE_CONFIG_H)
  17. #include "config.h"
  18. #endif
  19. #ifdef WIN32
  20. #pragma warning (disable : 4786)
  21. #endif
  22. #include "JackWaitThreadedDriver.h"
  23. #include "JackGlobals.h"
  24. #include "JackClient.h"
  25. #include "JackEngineControl.h"
  26. #include "JackException.h"
  27. #include "JackError.h"
  28. namespace Jack
  29. {
  30. bool JackWaitThreadedDriver::Init()
  31. {
  32. return (fStarter.Start() == 0);
  33. }
  34. bool JackWaitThreadedDriver::Execute()
  35. {
  36. try {
  37. // Process a null cycle until NetDriver has started
  38. while (!fStarter.fRunning && fThread.GetStatus() == JackThread::kRunning) {
  39. fDriver->ProcessNull();
  40. }
  41. // Set RT
  42. if (fDriver->IsRealTime()) {
  43. jack_log("JackWaitThreadedDriver::Init IsRealTime");
  44. // Will do "something" on OSX only...
  45. fThread.SetParams(GetEngineControl()->fPeriod, GetEngineControl()->fComputation, GetEngineControl()->fConstraint);
  46. if (fThread.AcquireRealTime(GetEngineControl()->fPriority) < 0) {
  47. jack_error("AcquireRealTime error");
  48. } else {
  49. set_threaded_log_function();
  50. }
  51. }
  52. // Switch to keep running even in case of error
  53. while (fThread.GetStatus() == JackThread::kRunning) {
  54. fDriver->Process();
  55. }
  56. return false;
  57. } catch (JackDriverException e) {
  58. e.PrintMessage();
  59. jack_log("Driver is restarted");
  60. fThread.DropRealTime();
  61. // Thread in kIniting status again...
  62. fThread.SetStatus(JackThread::kIniting);
  63. if (Init()) {
  64. // Thread in kRunning status again...
  65. fThread.SetStatus(JackThread::kRunning);
  66. return true;
  67. } else {
  68. return false;
  69. }
  70. }
  71. }
  72. } // end of namespace