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.

127 lines
3.2KB

  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. #include "JackWinProcessSync.h"
  16. #include "JackError.h"
  17. namespace Jack
  18. {
  19. void JackWinProcessSync::Signal()
  20. {
  21. SetEvent(fEvent);
  22. }
  23. void JackWinProcessSync::LockedSignal()
  24. {
  25. WaitForSingleObject(fMutex, INFINITE);
  26. SetEvent(fEvent);
  27. ReleaseMutex(fMutex);
  28. }
  29. void JackWinProcessSync::SignalAll()
  30. {
  31. SetEvent(fEvent);
  32. }
  33. void JackWinProcessSync::LockedSignalAll()
  34. {
  35. WaitForSingleObject(fMutex, INFINITE);
  36. SetEvent(fEvent);
  37. ReleaseMutex(fMutex);
  38. }
  39. void JackWinProcessSync::Wait()
  40. {
  41. ReleaseMutex(fMutex);
  42. WaitForSingleObject(fEvent, INFINITE);
  43. }
  44. void JackWinProcessSync::LockedWait()
  45. {
  46. /* Does it make sense on Windows, use non-locked version for now... */
  47. Wait();
  48. }
  49. bool JackWinProcessSync::TimedWait(long usec)
  50. {
  51. ReleaseMutex(fMutex);
  52. DWORD res = WaitForSingleObject(fEvent, usec / 1000);
  53. return (res == WAIT_OBJECT_0);
  54. }
  55. bool JackWinProcessSync::LockedTimedWait(long usec)
  56. {
  57. /* Does it make sense on Windows, use non-locked version for now...*/
  58. return TimedWait(usec);
  59. }
  60. /*
  61. Code from CAGuard.cpp : does ot sees to work as expected..
  62. void JackWinProcessSync::Wait()
  63. {
  64. ReleaseMutex(fMutex);
  65. HANDLE handles[] = { fMutex, fEvent };
  66. DWORD res = WaitForMultipleObjects(2, handles, true, INFINITE);
  67. if ((res != WAIT_OBJECT_0) && (res != WAIT_TIMEOUT))
  68. jack_error("Wait error err = %d", GetLastError());
  69. ResetEvent(fEvent);
  70. }
  71. void JackWinProcessSync::LockedWait()
  72. {
  73. WaitForSingleObject(fMutex, INFINITE);
  74. ReleaseMutex(fMutex);
  75. HANDLE handles[] = { fMutex, fEvent };
  76. DWORD res = WaitForMultipleObjects(2, handles, true, INFINITE);
  77. if ((res != WAIT_OBJECT_0) && (res != WAIT_TIMEOUT))
  78. jack_error("LockedWait error err = %d", GetLastError());
  79. ResetEvent(fEvent);
  80. }
  81. bool JackWinProcessSync::TimedWait(long usec)
  82. {
  83. ReleaseMutex(fMutex);
  84. HANDLE handles[] = { fMutex, fEvent };
  85. DWORD res = WaitForMultipleObjects(2, handles, true, usec / 1000);
  86. if ((res != WAIT_OBJECT_0) && (res != WAIT_TIMEOUT))
  87. jack_error("Wait error err = %d", GetLastError());
  88. ResetEvent(fEvent);
  89. }
  90. bool JackWinProcessSync::LockedTimedWait(long usec)
  91. {
  92. WaitForSingleObject(fMutex, INFINITE);
  93. ReleaseMutex(fMutex);
  94. HANDLE handles[] = { fMutex, fEvent };
  95. DWORD res = WaitForMultipleObjects(2, handles, true, usec / 1000);
  96. if ((res != WAIT_OBJECT_0) && (res != WAIT_TIMEOUT))
  97. jack_error("LockedTimedWait error err = %d", GetLastError());
  98. ResetEvent(fEvent);
  99. return (res == WAIT_OBJECT_0);
  100. }
  101. */
  102. } // end of namespace