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.

106 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. #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. HANDLE handles[] = { fMutex, fEvent };
  43. DWORD res = WaitForMultipleObjects(2, handles, true, INFINITE);
  44. if ((res != WAIT_OBJECT_0) && (res != WAIT_TIMEOUT))
  45. jack_error("Wait error err = %d", GetLastError());
  46. ResetEvent(fEvent);
  47. }
  48. void JackWinProcessSync::LockedWait()
  49. {
  50. /*
  51. Does it make sense on Windows, use non-locked version for now...
  52. WaitForSingleObject(fMutex, INFINITE);
  53. ReleaseMutex(fMutex);
  54. HANDLE handles[] = { fMutex, fEvent };
  55. DWORD res = WaitForMultipleObjects(2, handles, true, INFINITE);
  56. if ((res != WAIT_OBJECT_0) && (res != WAIT_TIMEOUT))
  57. jack_error("LockedWait error err = %d", GetLastError());
  58. ResetEvent(fEvent);
  59. */
  60. Wait();
  61. }
  62. bool JackWinProcessSync::TimedWait(long usec)
  63. {
  64. ReleaseMutex(fMutex);
  65. HANDLE handles[] = { fMutex, fEvent };
  66. DWORD res = WaitForMultipleObjects(2, handles, true, usec / 1000);
  67. if ((res != WAIT_OBJECT_0) && (res != WAIT_TIMEOUT))
  68. jack_error("Wait error err = %d", GetLastError());
  69. ResetEvent(fEvent);
  70. }
  71. bool JackWinProcessSync::LockedTimedWait(long usec)
  72. {
  73. /*
  74. Does it make sense on Windows, use non-locked version for now...
  75. WaitForSingleObject(fMutex, INFINITE);
  76. ReleaseMutex(fMutex);
  77. HANDLE handles[] = { fMutex, fEvent };
  78. DWORD res = WaitForMultipleObjects(2, handles, true, usec / 1000);
  79. if ((res != WAIT_OBJECT_0) && (res != WAIT_TIMEOUT))
  80. jack_error("LockedTimedWait error err = %d", GetLastError());
  81. ResetEvent(fEvent);
  82. return (res == WAIT_OBJECT_0);
  83. */
  84. return TimedWait(usec);
  85. }
  86. } // end of namespace