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.

132 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. \brief Inter process synchronization using pthread condition variables.
  42. */
  43. class JackPthreadCond : public JackSynchro
  44. {
  45. protected:
  46. JackPthreadCondItem* fSynchro;
  47. void BuildName(const char* name, char* res);
  48. virtual JackPthreadCondArray* GetTable() = 0;
  49. public:
  50. JackPthreadCond(): fSynchro(NULL)
  51. {}
  52. virtual ~JackPthreadCond()
  53. {}
  54. bool Signal();
  55. bool SignalAll();
  56. bool Wait();
  57. bool TimedWait(long usec);
  58. bool Connect(const char* name);
  59. bool ConnectInput(const char* name);
  60. bool ConnectOutput(const char* name);
  61. bool Disconnect();
  62. };
  63. class JackPthreadCondServer : public JackPthreadCond
  64. {
  65. private:
  66. static JackPthreadCondArray* fTable;
  67. static long fCount;
  68. protected:
  69. JackPthreadCondArray* GetTable()
  70. {
  71. return fTable;
  72. }
  73. public:
  74. JackPthreadCondServer();
  75. virtual ~JackPthreadCondServer();
  76. bool Allocate(const char* name, int value);
  77. void Destroy();
  78. };
  79. class JackPthreadCondClient : public JackPthreadCond
  80. {
  81. private:
  82. static JackShmReadWritePtr1<JackPthreadCondArray> fTable;
  83. static long fCount;
  84. protected:
  85. JackPthreadCondArray* GetTable()
  86. {
  87. return fTable;
  88. }
  89. public:
  90. JackPthreadCondClient(int shared_index);
  91. virtual ~JackPthreadCondClient();
  92. };
  93. } // end of namespace
  94. #endif