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.

127 lines
3.2KB

  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. void jackbridge_sem_post(void* sem) noexcept
  39. {
  40. CARLA_SAFE_ASSERT_RETURN(sem != nullptr,);
  41. #ifndef JACKBRIDGE_DUMMY
  42. carla_sem_post(*(carla_sem_t*)sem);
  43. #endif
  44. }
  45. bool jackbridge_sem_timedwait(void* sem, uint msecs) noexcept
  46. {
  47. CARLA_SAFE_ASSERT_RETURN(sem != nullptr, false);
  48. #ifdef JACKBRIDGE_DUMMY
  49. return false;
  50. #else
  51. return carla_sem_timedwait(*(carla_sem_t*)sem, msecs);
  52. #endif
  53. }
  54. // -----------------------------------------------------------------------------
  55. bool jackbridge_shm_is_valid(const void* shm) noexcept
  56. {
  57. CARLA_SAFE_ASSERT_RETURN(shm != nullptr, false);
  58. #ifdef JACKBRIDGE_DUMMY
  59. return false;
  60. #else
  61. return carla_is_shm_valid(*(const carla_shm_t*)shm);
  62. #endif
  63. }
  64. void jackbridge_shm_init(void* shm) noexcept
  65. {
  66. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  67. #ifndef JACKBRIDGE_DUMMY
  68. carla_shm_init(*(carla_shm_t*)shm);
  69. #endif
  70. }
  71. void jackbridge_shm_attach(void* shm, const char* name) noexcept
  72. {
  73. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  74. #ifndef JACKBRIDGE_DUMMY
  75. *(carla_shm_t*)shm = carla_shm_attach(name);
  76. #endif
  77. }
  78. void jackbridge_shm_close(void* shm) noexcept
  79. {
  80. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  81. #ifndef JACKBRIDGE_DUMMY
  82. carla_shm_close(*(carla_shm_t*)shm);
  83. #endif
  84. }
  85. void* jackbridge_shm_map(void* shm, uint64_t size) noexcept
  86. {
  87. CARLA_SAFE_ASSERT_RETURN(shm != nullptr, nullptr);
  88. #ifdef JACKBRIDGE_DUMMY
  89. return nullptr;
  90. #else
  91. return carla_shm_map(*(carla_shm_t*)shm, size);
  92. #endif
  93. }
  94. void jackbridge_shm_unmap(void* shm, void* ptr) noexcept
  95. {
  96. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  97. #ifndef JACKBRIDGE_DUMMY
  98. return carla_shm_unmap(*(carla_shm_t*)shm, ptr);
  99. #endif
  100. }
  101. // -----------------------------------------------------------------------------