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.

134 lines
2.7KB

  1. /*
  2. Copyright (C) 2004-2005 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 __JackPthreadCond__
  16. #define __JackPthreadCond__
  17. #include "JackSynchro.h"
  18. #include "JackShmMem.h"
  19. #include <pthread.h>
  20. #include <sys/time.h>
  21. #include <time.h>
  22. #include <stdio.h>
  23. #include <assert.h>
  24. #define MAX_ITEM 8
  25. namespace Jack
  26. {
  27. struct JackPthreadCondItem
  28. {
  29. char fName[SYNC_MAX_NAME_SIZE];
  30. pthread_mutex_t fLock;
  31. pthread_cond_t fCond;
  32. };
  33. struct JackPthreadCondArray : public JackShmMem
  34. {
  35. JackPthreadCondItem fTable[MAX_ITEM];
  36. JackPthreadCondArray();
  37. virtual ~JackPthreadCondArray()
  38. {}
  39. }
  40. ;
  41. /*!
  42. \brief Inter process synchronization using pthread condition variables.
  43. */
  44. class JackPthreadCond : public JackSynchro
  45. {
  46. protected:
  47. JackPthreadCondItem* fSynchro;
  48. void BuildName(const char* name, char* res);
  49. virtual JackPthreadCondArray* GetTable() = 0;
  50. public:
  51. JackPthreadCond(): fSynchro(NULL)
  52. {}
  53. virtual ~JackPthreadCond()
  54. {}
  55. bool Signal();
  56. bool SignalAll();
  57. bool Wait();
  58. bool TimedWait(long usec);
  59. bool Connect(const char* name);
  60. bool ConnectInput(const char* name);
  61. bool ConnectOutput(const char* name);
  62. bool Disconnect();
  63. };
  64. class JackPthreadCondServer : public JackPthreadCond
  65. {
  66. private:
  67. static JackPthreadCondArray* fTable;
  68. static long fCount;
  69. protected:
  70. JackPthreadCondArray* GetTable()
  71. {
  72. return fTable;
  73. }
  74. public:
  75. JackPthreadCondServer();
  76. virtual ~JackPthreadCondServer();
  77. bool Allocate(const char* name, int value);
  78. void Destroy();
  79. };
  80. class JackPthreadCondClient : public JackPthreadCond
  81. {
  82. private:
  83. static JackShmReadWritePtr1<JackPthreadCondArray> fTable;
  84. static long fCount;
  85. protected:
  86. JackPthreadCondArray* GetTable()
  87. {
  88. return fTable;
  89. }
  90. public:
  91. JackPthreadCondClient(int shared_index);
  92. virtual ~JackPthreadCondClient();
  93. };
  94. } // end of namespace
  95. #endif