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.

138 lines
3.4KB

  1. /*
  2. * JackBridge (Part 2, Semaphore + Shared memory functions)
  3. * Copyright (C) 2013-2015 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 "CarlaSemUtils.hpp"
  21. # include "CarlaShmUtils.hpp"
  22. #endif // ! JACKBRIDGE_DUMMY
  23. // -----------------------------------------------------------------------------
  24. bool jackbridge_sem_init(void* sem) noexcept
  25. {
  26. CARLA_SAFE_ASSERT_RETURN(sem != nullptr, false);
  27. #ifndef JACKBRIDGE_DUMMY
  28. return carla_sem_create2(*(carla_sem_t*)sem);
  29. #endif
  30. }
  31. void jackbridge_sem_destroy(void* sem) noexcept
  32. {
  33. CARLA_SAFE_ASSERT_RETURN(sem != nullptr,);
  34. #ifndef JACKBRIDGE_DUMMY
  35. carla_sem_destroy2(*(carla_sem_t*)sem);
  36. #endif
  37. }
  38. bool jackbridge_sem_connect(void* sem) noexcept
  39. {
  40. CARLA_SAFE_ASSERT_RETURN(sem != nullptr, false);
  41. #ifdef JACKBRIDGE_DUMMY
  42. return false;
  43. #else
  44. return carla_sem_connect(*(carla_sem_t*)sem);
  45. #endif
  46. }
  47. void jackbridge_sem_post(void* sem, bool server) noexcept
  48. {
  49. CARLA_SAFE_ASSERT_RETURN(sem != nullptr,);
  50. #ifndef JACKBRIDGE_DUMMY
  51. carla_sem_post(*(carla_sem_t*)sem, server);
  52. #endif
  53. }
  54. bool jackbridge_sem_timedwait(void* sem, uint msecs, bool server) noexcept
  55. {
  56. CARLA_SAFE_ASSERT_RETURN(sem != nullptr, false);
  57. #ifdef JACKBRIDGE_DUMMY
  58. return false;
  59. #else
  60. return carla_sem_timedwait(*(carla_sem_t*)sem, msecs, server);
  61. #endif
  62. }
  63. // -----------------------------------------------------------------------------
  64. bool jackbridge_shm_is_valid(const void* shm) noexcept
  65. {
  66. CARLA_SAFE_ASSERT_RETURN(shm != nullptr, false);
  67. #ifdef JACKBRIDGE_DUMMY
  68. return false;
  69. #else
  70. return carla_is_shm_valid(*(const carla_shm_t*)shm);
  71. #endif
  72. }
  73. void jackbridge_shm_init(void* shm) noexcept
  74. {
  75. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  76. #ifndef JACKBRIDGE_DUMMY
  77. carla_shm_init(*(carla_shm_t*)shm);
  78. #endif
  79. }
  80. void jackbridge_shm_attach(void* shm, const char* name) noexcept
  81. {
  82. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  83. #ifndef JACKBRIDGE_DUMMY
  84. *(carla_shm_t*)shm = carla_shm_attach(name);
  85. #endif
  86. }
  87. void jackbridge_shm_close(void* shm) noexcept
  88. {
  89. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  90. #ifndef JACKBRIDGE_DUMMY
  91. carla_shm_close(*(carla_shm_t*)shm);
  92. #endif
  93. }
  94. void* jackbridge_shm_map(void* shm, uint64_t size) noexcept
  95. {
  96. CARLA_SAFE_ASSERT_RETURN(shm != nullptr, nullptr);
  97. #ifdef JACKBRIDGE_DUMMY
  98. return nullptr;
  99. #else
  100. return carla_shm_map(*(carla_shm_t*)shm, size);
  101. #endif
  102. }
  103. void jackbridge_shm_unmap(void* shm, void* ptr) noexcept
  104. {
  105. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  106. #ifndef JACKBRIDGE_DUMMY
  107. return carla_shm_unmap(*(carla_shm_t*)shm, ptr);
  108. #endif
  109. }
  110. // -----------------------------------------------------------------------------