Audio plugin host https://kx.studio/carla
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.

93 lines
1.8KB

  1. /*
  2. * Carla Tests
  3. * Copyright (C) 2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or 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 GPL.txt file
  16. */
  17. #include "carla_utils.hpp"
  18. #include <cassert>
  19. class MyThread : public CarlaThread
  20. {
  21. public:
  22. MyThread(bool wait)
  23. : blockWait(wait)
  24. {
  25. }
  26. protected:
  27. void run()
  28. {
  29. printf("RUN(%i)\n", blockWait);
  30. if (blockWait)
  31. {
  32. for (int i=0; i < 100; i++)
  33. {
  34. carla_msleep(50);
  35. printf("RUN(%i) - BLOCKING\n", blockWait);
  36. }
  37. }
  38. printf("RUN(%i) - FINISHED\n", blockWait);
  39. }
  40. private:
  41. bool blockWait;
  42. };
  43. int main()
  44. {
  45. MyThread t1(false);
  46. MyThread t2(true);
  47. MyThread t3(true);
  48. MyThread t4(true);
  49. MyThread t5(false);
  50. t1.start();
  51. t2.start();
  52. //t3.start();
  53. //t3.waitForStarted();
  54. //t3.stop();
  55. t1.waitForStarted();
  56. t2.waitForStarted();
  57. printf("THREADS STARTED\n");
  58. // test if threds keep working
  59. carla_sleep(1);
  60. printf("THREAD1 STOPPING...\n");
  61. if (t1.isRunning() && ! t1.stop(500))
  62. {
  63. printf("THREAD1 FAILED, TERMINATE\n");
  64. t1.terminate();
  65. }
  66. printf("THREAD2 STOPPING...\n");
  67. if (t2.isRunning() && ! t2.stop(500))
  68. {
  69. printf("THREAD2 FAILED, TERMINATE\n");
  70. t2.terminate();
  71. }
  72. return 0;
  73. }