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.

JackBridge2.cpp 2.6KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * JackBridge (Part 2, Semaphore functions)
  3. * Copyright (C) 2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "CarlaDefines.h"
  17. #include "JackBridge.hpp"
  18. #ifdef CARLA_OS_MAC
  19. # include <unistd.h>
  20. #endif
  21. #ifndef JACKBRIDGE_HPP_INCLUDED
  22. // don't include the whole JACK API in this file
  23. CARLA_EXPORT bool jackbridge_sem_init(void* sem) noexcept;
  24. CARLA_EXPORT bool jackbridge_sem_destroy(void* sem) noexcept;
  25. CARLA_EXPORT bool jackbridge_sem_post(void* sem) noexcept;
  26. CARLA_EXPORT bool jackbridge_sem_timedwait(void* sem, int secs);
  27. #endif
  28. // -----------------------------------------------------------------------------
  29. #ifdef JACKBRIDGE_DUMMY
  30. bool jackbridge_sem_init(void*) noexcept
  31. {
  32. return false;
  33. }
  34. bool jackbridge_sem_destroy(void*) noexcept
  35. {
  36. return false;
  37. }
  38. bool jackbridge_sem_post(void*) noexcept
  39. {
  40. return false;
  41. }
  42. bool jackbridge_sem_timedwait(void*, int)
  43. {
  44. return false;
  45. }
  46. #else //JACKBRIDGE_DUMMY
  47. #include <ctime>
  48. #include <sys/time.h>
  49. #include <sys/types.h>
  50. #include <semaphore.h>
  51. bool jackbridge_sem_init(void* sem) noexcept
  52. {
  53. return (sem_init((sem_t*)sem, 1, 0) == 0);
  54. }
  55. bool jackbridge_sem_destroy(void* sem) noexcept
  56. {
  57. return (sem_destroy((sem_t*)sem) == 0);
  58. }
  59. bool jackbridge_sem_post(void* sem) noexcept
  60. {
  61. return (sem_post((sem_t*)sem) == 0);
  62. }
  63. bool jackbridge_sem_timedwait(void* sem, int secs)
  64. {
  65. # ifdef CARLA_OS_MAC
  66. alarm(secs);
  67. return (sem_wait((sem_t*)sem) == 0);
  68. # else
  69. timespec timeout;
  70. # ifdef CARLA_OS_WIN
  71. timeval now;
  72. gettimeofday(&now, nullptr);
  73. timeout.tv_sec = now.tv_sec;
  74. timeout.tv_nsec = now.tv_usec * 1000;
  75. # else
  76. clock_gettime(CLOCK_REALTIME, &timeout);
  77. # endif
  78. timeout.tv_sec += secs;
  79. return (sem_timedwait((sem_t*)sem, &timeout) == 0);
  80. # endif
  81. }
  82. #endif // JACKBRIDGE_DUMMY
  83. // -----------------------------------------------------------------------------