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.

136 lines
2.8KB

  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 SignalAll()
  56. {
  57. //pthread_mutex_lock(&fLock);
  58. pthread_cond_broadcast(&fCond);
  59. //pthread_mutex_unlock(&fLock);
  60. }
  61. };
  62. /*!
  63. \brief A synchronization primitive built using an inter-process synchronization object.
  64. */
  65. class JackInterProcessSync : public JackSyncInterface
  66. {
  67. private:
  68. JackSynchro* fSynchro;
  69. public:
  70. JackInterProcessSync(JackSynchro* synchro): fSynchro(synchro)
  71. {}
  72. virtual ~JackInterProcessSync()
  73. {
  74. delete fSynchro;
  75. }
  76. bool Allocate(const char* name)
  77. {
  78. return fSynchro->Allocate(name, "", 0);
  79. }
  80. void Destroy()
  81. {
  82. fSynchro->Destroy();
  83. }
  84. bool Connect(const char* name)
  85. {
  86. return fSynchro->Connect(name, "");
  87. }
  88. bool TimedWait(long usec);
  89. void Wait()
  90. {
  91. fSynchro->Wait();
  92. }
  93. void SignalAll()
  94. {
  95. fSynchro->SignalAll();
  96. }
  97. };
  98. } // end of namespace
  99. #endif