jack2 codebase
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.

143 lines
2.8KB

  1. /*
  2. Copyright (C) 2004-2008 Grame
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 2.1 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #ifndef __JackProcessSync__
  16. #define __JackProcessSync__
  17. #include "JackPlatformPlug.h"
  18. #include <pthread.h>
  19. #include <sys/time.h>
  20. #include <unistd.h>
  21. namespace Jack
  22. {
  23. /*!
  24. \brief A synchronization primitive built using a condition variable.
  25. */
  26. class JackProcessSync
  27. {
  28. private:
  29. pthread_mutex_t fLock; // Mutex
  30. pthread_cond_t fCond; // Condition variable
  31. public:
  32. JackProcessSync()
  33. {
  34. pthread_mutex_init(&fLock, NULL);
  35. pthread_cond_init(&fCond, NULL);
  36. }
  37. ~JackProcessSync()
  38. {
  39. pthread_mutex_destroy(&fLock);
  40. pthread_cond_destroy(&fCond);
  41. }
  42. bool Allocate(const char* name)
  43. {
  44. return true;
  45. }
  46. bool Connect(const char* name)
  47. {
  48. return true;
  49. }
  50. void Destroy()
  51. {}
  52. bool TimedWait(long usec);
  53. void Wait();
  54. void Signal()
  55. {
  56. pthread_mutex_lock(&fLock);
  57. pthread_cond_signal(&fCond);
  58. pthread_mutex_unlock(&fLock);
  59. }
  60. void SignalAll()
  61. {
  62. //pthread_mutex_lock(&fLock);
  63. pthread_cond_broadcast(&fCond);
  64. //pthread_mutex_unlock(&fLock);
  65. }
  66. };
  67. /*!
  68. \brief A synchronization primitive built using an inter-process synchronization object.
  69. */
  70. class JackInterProcessSync
  71. {
  72. private:
  73. JackSynchro* fSynchro;
  74. public:
  75. JackInterProcessSync(JackSynchro* synchro): fSynchro(synchro)
  76. {}
  77. ~JackInterProcessSync()
  78. {
  79. delete fSynchro;
  80. }
  81. bool Allocate(const char* name)
  82. {
  83. return fSynchro->Allocate(name, "", 0);
  84. }
  85. void Destroy()
  86. {
  87. fSynchro->Destroy();
  88. }
  89. bool Connect(const char* name)
  90. {
  91. return fSynchro->Connect(name, "");
  92. }
  93. bool TimedWait(long usec);
  94. void Wait()
  95. {
  96. fSynchro->Wait();
  97. }
  98. void SignalAll()
  99. {
  100. fSynchro->SignalAll();
  101. }
  102. };
  103. } // end of namespace
  104. #endif