Collection of tools useful for audio production
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.

78 lines
1.7KB

  1. /*
  2. * Carla Engine Thread
  3. * Copyright (C) 2012 Filipe Coelho <falktx@falktx.com>
  4. *
  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. * any later version.
  9. *
  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.
  14. *
  15. * For a full copy of the GNU General Public License see the COPYING file
  16. */
  17. #ifndef CARLA_ENGINE_THREAD_HPP
  18. #define CARLA_ENGINE_THREAD_HPP
  19. #include "carla_backend.hpp"
  20. #include <QtCore/QMutex>
  21. #include <QtCore/QThread>
  22. CARLA_BACKEND_START_NAMESPACE
  23. #if 0
  24. } // Fix editor indentation
  25. #endif
  26. class CarlaEngineThread : public QThread
  27. {
  28. public:
  29. CarlaEngineThread(CarlaEngine* const engine, QObject* const parent = nullptr);
  30. ~CarlaEngineThread();
  31. void startNow();
  32. void stopNow();
  33. // ----------------------------------------------
  34. protected:
  35. void run();
  36. // ----------------------------------------------
  37. private:
  38. CarlaEngine* const engine;
  39. QMutex m_mutex;
  40. bool m_stopNow;
  41. // ----------------------------------------------
  42. class ScopedLocker
  43. {
  44. public:
  45. ScopedLocker(CarlaEngineThread* const thread)
  46. : mutex(&thread->m_mutex)
  47. {
  48. mutex->lock();
  49. }
  50. ~ScopedLocker()
  51. {
  52. mutex->unlock();
  53. }
  54. private:
  55. QMutex* const mutex;
  56. };
  57. };
  58. CARLA_BACKEND_END_NAMESPACE
  59. #endif // CARLA_ENGINE_THREAD_HPP