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.0KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #ifndef __JACKBRIDGE_HPP__
  18. // don't include the whole JACK API in this file
  19. CARLA_EXPORT bool jackbridge_sem_post(void* sem);
  20. CARLA_EXPORT bool jackbridge_sem_timedwait(void* sem, int secs);
  21. #endif
  22. // -----------------------------------------------------------------------------
  23. #if JACKBRIDGE_DUMMY
  24. bool jackbridge_sem_post(void*)
  25. {
  26. return false;
  27. }
  28. bool jackbridge_sem_timedwait(void*, int)
  29. {
  30. return false;
  31. }
  32. #else
  33. #include <semaphore.h>
  34. #ifdef __WINE__
  35. # define _STRUCT_TIMEVAL 1
  36. # define _SYS_SELECT_H 1
  37. # include <bits/types.h>
  38. struct timespec {
  39. __time_t tv_sec; /* Seconds. */
  40. long int tv_nsec; /* Nanoseconds. */
  41. };
  42. #endif
  43. #ifdef CARLA_OS_WIN
  44. # include <sys/time.h>
  45. #else
  46. # include <time.h>
  47. #endif
  48. bool jackbridge_sem_post(void* sem)
  49. {
  50. return (sem_post((sem_t*)sem) == 0);
  51. }
  52. bool jackbridge_sem_timedwait(void* sem, int secs)
  53. {
  54. # ifdef CARLA_OS_MAC
  55. alarm(secs);
  56. return (sem_wait((sem_t*)sem) == 0);
  57. # else
  58. timespec timeout;
  59. # ifdef CARLA_OS_WIN
  60. timeval now;
  61. gettimeofday(&now, nullptr);
  62. timeout.tv_sec = now.tv_sec;
  63. timeout.tv_nsec = now.tv_usec * 1000;
  64. # else
  65. clock_gettime(CLOCK_REALTIME, &timeout);
  66. # endif
  67. timeout.tv_sec += secs;
  68. return (sem_timedwait((sem_t*)sem, &timeout) == 0);
  69. # endif
  70. }
  71. #endif
  72. // -----------------------------------------------------------------------------