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.

76 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. class CarlaEngine;
  24. class CarlaEngineThread : public QThread
  25. {
  26. public:
  27. CarlaEngineThread(CarlaEngine* const engine, QObject* const parent = nullptr);
  28. ~CarlaEngineThread();
  29. void startNow();
  30. void stopNow();
  31. // ----------------------------------------------
  32. protected:
  33. void run();
  34. // ----------------------------------------------
  35. private:
  36. CarlaEngine* const engine;
  37. QMutex m_mutex;
  38. bool m_stopNow;
  39. // ----------------------------------------------
  40. class ScopedLocker
  41. {
  42. public:
  43. ScopedLocker(CarlaEngineThread* const thread)
  44. : mutex(&thread->m_mutex)
  45. {
  46. mutex->lock();
  47. }
  48. ~ScopedLocker()
  49. {
  50. mutex->unlock();
  51. }
  52. private:
  53. QMutex* const mutex;
  54. };
  55. };
  56. CARLA_BACKEND_END_NAMESPACE
  57. #endif // CARLA_ENGINE_THREAD_HPP