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.

85 lines
2.0KB

  1. /*
  2. * JackBridge (Part 2, Semaphore functions)
  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 Lesser General Public
  7. * License as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * For a full copy of the license see the LGPL.txt file
  15. */
  16. #include "CarlaDefines.hpp"
  17. // don't include the whole JACK API in this file
  18. CARLA_EXPORT bool jackbridge_sem_post(void* sem);
  19. CARLA_EXPORT bool jackbridge_sem_timedwait(void* sem, int secs);
  20. // -----------------------------------------------------------------------------
  21. #if JACKBRIDGE_DUMMY
  22. bool jackbridge_sem_post(void*)
  23. {
  24. return false;
  25. }
  26. bool jackbridge_sem_timedwait(void*, int)
  27. {
  28. return false;
  29. }
  30. #else
  31. #include <semaphore.h>
  32. #ifdef __WINE__
  33. # define _STRUCT_TIMEVAL 1
  34. # define _SYS_SELECT_H 1
  35. # include <bits/types.h>
  36. struct timespec {
  37. __time_t tv_sec; /* Seconds. */
  38. long int tv_nsec; /* Nanoseconds. */
  39. };
  40. #endif
  41. #ifdef CARLA_OS_WIN
  42. # include <sys/time.h>
  43. #else
  44. # include <time.h>
  45. #endif
  46. bool jackbridge_sem_post(void* sem)
  47. {
  48. return (sem_post((sem_t*)sem) == 0);
  49. }
  50. bool jackbridge_sem_timedwait(void* sem, int secs)
  51. {
  52. # ifdef CARLA_OS_MAC
  53. alarm(secs);
  54. return (sem_wait((sem_t*)sem) == 0);
  55. # else
  56. timespec timeout;
  57. # ifdef CARLA_OS_WIN
  58. timeval now;
  59. gettimeofday(&now, nullptr);
  60. timeout.tv_sec = now.tv_sec;
  61. timeout.tv_nsec = now.tv_usec * 1000;
  62. # else
  63. clock_gettime(CLOCK_REALTIME, &timeout);
  64. # endif
  65. timeout.tv_sec += secs;
  66. return (sem_timedwait((sem_t*)sem, &timeout) == 0);
  67. # endif
  68. }
  69. #endif
  70. // -----------------------------------------------------------------------------