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 3.2KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
11 years ago
11 years ago
11 years ago
9 years ago
10 years ago
10 years ago
10 years ago
9 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * JackBridge (Part 2, Semaphore functions)
  3. * Copyright (C) 2013-2014 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 "JackBridge.hpp"
  17. #ifdef JACKBRIDGE_DUMMY
  18. # include "CarlaUtils.hpp"
  19. #else
  20. # include <cerrno>
  21. # include "CarlaSemUtils.hpp"
  22. # include "CarlaShmUtils.hpp"
  23. #endif // ! JACKBRIDGE_DUMMY
  24. // -----------------------------------------------------------------------------
  25. bool jackbridge_sem_init(void* sem) noexcept
  26. {
  27. #ifdef JACKBRIDGE_DUMMY
  28. return false;
  29. #else
  30. sem_t* const sema(carla_sem_create());
  31. CARLA_SAFE_ASSERT_RETURN(sema != nullptr, false);
  32. # ifdef CARLA_OS_MAC
  33. std::memcpy(sem, &sema, sizeof(sem_t*));
  34. # else
  35. std::memcpy(sem, sema, sizeof(sem_t));
  36. # endif
  37. return (sema != nullptr);
  38. #endif
  39. }
  40. void jackbridge_sem_destroy(void* sem) noexcept
  41. {
  42. #ifndef JACKBRIDGE_DUMMY
  43. carla_sem_destroy((sem_t*)sem);
  44. #endif
  45. }
  46. bool jackbridge_sem_post(void* sem) noexcept
  47. {
  48. #ifdef JACKBRIDGE_DUMMY
  49. return false;
  50. #else
  51. return carla_sem_post((sem_t*)sem);
  52. #endif
  53. }
  54. bool jackbridge_sem_timedwait(void* sem, uint secs, bool* timedOut) noexcept
  55. {
  56. CARLA_SAFE_ASSERT_RETURN(timedOut != nullptr, false);
  57. #ifdef JACKBRIDGE_DUMMY
  58. return false;
  59. #else
  60. if (carla_sem_timedwait((sem_t*)sem, secs))
  61. {
  62. *timedOut = false;
  63. return true;
  64. }
  65. *timedOut = (errno == ETIMEDOUT);
  66. return false;
  67. #endif
  68. }
  69. // -----------------------------------------------------------------------------
  70. bool jackbridge_shm_is_valid(const void* shm) noexcept
  71. {
  72. CARLA_SAFE_ASSERT_RETURN(shm != nullptr, false);
  73. #ifdef JACKBRIDGE_DUMMY
  74. return false;
  75. #else
  76. return carla_is_shm_valid(*(const shm_t*)shm);
  77. #endif
  78. }
  79. void jackbridge_shm_init(void* shm) noexcept
  80. {
  81. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  82. #ifndef JACKBRIDGE_DUMMY
  83. carla_shm_init(*(shm_t*)shm);
  84. #endif
  85. }
  86. void jackbridge_shm_attach(void* shm, const char* name) noexcept
  87. {
  88. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  89. #ifndef JACKBRIDGE_DUMMY
  90. *(shm_t*)shm = carla_shm_attach(name);
  91. #endif
  92. }
  93. void jackbridge_shm_close(void* shm) noexcept
  94. {
  95. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  96. #ifndef JACKBRIDGE_DUMMY
  97. carla_shm_close(*(shm_t*)shm);
  98. #endif
  99. }
  100. void* jackbridge_shm_map(void* shm, size_t size) noexcept
  101. {
  102. CARLA_SAFE_ASSERT_RETURN(shm != nullptr, nullptr);
  103. #ifdef JACKBRIDGE_DUMMY
  104. return nullptr;
  105. #else
  106. return carla_shm_map(*(shm_t*)shm, size);
  107. #endif
  108. }
  109. // -----------------------------------------------------------------------------