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

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