Jack2  1.9.8
JackWinProcessSync.cpp
1 /*
2  Copyright (C) 2004-2008 Grame
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU Lesser General Public License as published by
6  the Free Software Foundation; either version 2.1 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 
18  */
19 
20 
21 #include "JackWinProcessSync.h"
22 #include "JackError.h"
23 
24 namespace Jack
25 {
26 
27 void JackWinProcessSync::Signal()
28 {
29  SetEvent(fEvent);
30 }
31 
32 void JackWinProcessSync::LockedSignal()
33 {
34  WaitForSingleObject(fMutex, INFINITE);
35  SetEvent(fEvent);
36  ReleaseMutex(fMutex);
37 }
38 
39 void JackWinProcessSync::SignalAll()
40 {
41  SetEvent(fEvent);
42 }
43 
44 void JackWinProcessSync::LockedSignalAll()
45 {
46  WaitForSingleObject(fMutex, INFINITE);
47  SetEvent(fEvent);
48  ReleaseMutex(fMutex);
49 }
50 
51 void JackWinProcessSync::Wait()
52 {
53  ReleaseMutex(fMutex);
54  WaitForSingleObject(fEvent, INFINITE);
55 }
56 
57 void JackWinProcessSync::LockedWait()
58 {
59  /* Does it make sense on Windows, use non-locked version for now... */
60  Wait();
61 }
62 
63 bool JackWinProcessSync::TimedWait(long usec)
64 {
65  ReleaseMutex(fMutex);
66  DWORD res = WaitForSingleObject(fEvent, usec / 1000);
67  return (res == WAIT_OBJECT_0);
68 }
69 
70 bool JackWinProcessSync::LockedTimedWait(long usec)
71 {
72  /* Does it make sense on Windows, use non-locked version for now...*/
73  return TimedWait(usec);
74 }
75 
76 /*
77 Code from APPLE CAGuard.cpp : does not seem to work as expected...
78 
79 void JackWinProcessSync::Wait()
80 {
81  ReleaseMutex(fMutex);
82  HANDLE handles[] = { fMutex, fEvent };
83  DWORD res = WaitForMultipleObjects(2, handles, true, INFINITE);
84  if ((res != WAIT_OBJECT_0) && (res != WAIT_TIMEOUT))
85  jack_error("Wait error err = %d", GetLastError());
86  ResetEvent(fEvent);
87 }
88 
89 void JackWinProcessSync::LockedWait()
90 {
91  WaitForSingleObject(fMutex, INFINITE);
92  ReleaseMutex(fMutex);
93  HANDLE handles[] = { fMutex, fEvent };
94  DWORD res = WaitForMultipleObjects(2, handles, true, INFINITE);
95  if ((res != WAIT_OBJECT_0) && (res != WAIT_TIMEOUT))
96  jack_error("LockedWait error err = %d", GetLastError());
97  ResetEvent(fEvent);
98 }
99 
100 bool JackWinProcessSync::TimedWait(long usec)
101 {
102  ReleaseMutex(fMutex);
103  HANDLE handles[] = { fMutex, fEvent };
104  DWORD res = WaitForMultipleObjects(2, handles, true, usec / 1000);
105  if ((res != WAIT_OBJECT_0) && (res != WAIT_TIMEOUT))
106  jack_error("Wait error err = %d", GetLastError());
107  ResetEvent(fEvent);
108 }
109 
110 bool JackWinProcessSync::LockedTimedWait(long usec)
111 {
112  WaitForSingleObject(fMutex, INFINITE);
113  ReleaseMutex(fMutex);
114  HANDLE handles[] = { fMutex, fEvent };
115  DWORD res = WaitForMultipleObjects(2, handles, true, usec / 1000);
116  if ((res != WAIT_OBJECT_0) && (res != WAIT_TIMEOUT))
117  jack_error("LockedTimedWait error err = %d", GetLastError());
118  ResetEvent(fEvent);
119  return (res == WAIT_OBJECT_0);
120 }
121 */
122 
123 } // end of namespace
124 
125 
126