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.

72 lines
1.6KB

  1. /*
  2. * Carla Engine
  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_utils.hpp"
  20. class CarlaEngine;
  21. class CarlaPlugin;
  22. #include <QtCore/QMutex>
  23. #include <QtCore/QThread>
  24. CARLA_BACKEND_START_NAMESPACE
  25. class CarlaEngineThread : public QThread
  26. {
  27. public:
  28. CarlaEngineThread(CarlaBackend::CarlaEngine* const engine, QObject* const parent = nullptr);
  29. ~CarlaEngineThread();
  30. void startNow();
  31. void stopNow();
  32. protected:
  33. void run();
  34. private:
  35. CarlaBackend::CarlaEngine* const engine;
  36. QMutex mutex;
  37. bool m_stopNow;
  38. // ----------------------------------------------
  39. class ScopedLocker
  40. {
  41. public:
  42. ScopedLocker(CarlaEngineThread* const thread)
  43. : m_thread(thread)
  44. {
  45. m_thread->mutex.lock();
  46. }
  47. ~ScopedLocker()
  48. {
  49. m_thread->mutex.unlock();
  50. }
  51. private:
  52. CarlaEngineThread* const m_thread;
  53. };
  54. };
  55. CARLA_BACKEND_END_NAMESPACE
  56. #endif // CARLA_ENGINE_THREAD_HPP