Merge branch 'master' into server_no_deadlock
[jack2.git] / windows / JackWinProcessSync.cpp
blob56171fbafbd638c526fdc18d2af85f407404f19f
1 /*
2 Copyright (C) 2004-2006 Grame
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
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 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "JackWinProcessSync.h"
21 #include "JackError.h"
23 namespace Jack
26 void JackWinProcessSync::Signal()
28 SetEvent(fEvent);
31 void JackWinProcessSync::LockedSignal()
33 WaitForSingleObject(fMutex, INFINITE);
34 SetEvent(fEvent);
35 ReleaseMutex(fMutex);
38 void JackWinProcessSync::SignalAll()
40 SetEvent(fEvent);
43 void JackWinProcessSync::LockedSignalAll()
45 WaitForSingleObject(fMutex, INFINITE);
46 SetEvent(fEvent);
47 ReleaseMutex(fMutex);
50 void JackWinProcessSync::Wait()
52 ReleaseMutex(fMutex);
53 WaitForSingleObject(fEvent, INFINITE);
56 void JackWinProcessSync::LockedWait()
58 /* Does it make sense on Windows, use non-locked version for now... */
59 Wait();
62 bool JackWinProcessSync::TimedWait(long usec)
64 ReleaseMutex(fMutex);
65 DWORD res = WaitForSingleObject(fEvent, usec / 1000);
66 return (res == WAIT_OBJECT_0);
69 bool JackWinProcessSync::LockedTimedWait(long usec)
71 /* Does it make sense on Windows, use non-locked version for now...*/
72 return TimedWait(usec);
76 Code from CAGuard.cpp : does ot sees to work as expected..
78 void JackWinProcessSync::Wait()
80 ReleaseMutex(fMutex);
81 HANDLE handles[] = { fMutex, fEvent };
82 DWORD res = WaitForMultipleObjects(2, handles, true, INFINITE);
83 if ((res != WAIT_OBJECT_0) && (res != WAIT_TIMEOUT))
84 jack_error("Wait error err = %d", GetLastError());
85 ResetEvent(fEvent);
88 void JackWinProcessSync::LockedWait()
90 WaitForSingleObject(fMutex, INFINITE);
91 ReleaseMutex(fMutex);
92 HANDLE handles[] = { fMutex, fEvent };
93 DWORD res = WaitForMultipleObjects(2, handles, true, INFINITE);
94 if ((res != WAIT_OBJECT_0) && (res != WAIT_TIMEOUT))
95 jack_error("LockedWait error err = %d", GetLastError());
96 ResetEvent(fEvent);
99 bool JackWinProcessSync::TimedWait(long usec)
101 ReleaseMutex(fMutex);
102 HANDLE handles[] = { fMutex, fEvent };
103 DWORD res = WaitForMultipleObjects(2, handles, true, usec / 1000);
104 if ((res != WAIT_OBJECT_0) && (res != WAIT_TIMEOUT))
105 jack_error("Wait error err = %d", GetLastError());
106 ResetEvent(fEvent);
109 bool JackWinProcessSync::LockedTimedWait(long usec)
111 WaitForSingleObject(fMutex, INFINITE);
112 ReleaseMutex(fMutex);
113 HANDLE handles[] = { fMutex, fEvent };
114 DWORD res = WaitForMultipleObjects(2, handles, true, usec / 1000);
115 if ((res != WAIT_OBJECT_0) && (res != WAIT_TIMEOUT))
116 jack_error("LockedTimedWait error err = %d", GetLastError());
117 ResetEvent(fEvent);
118 return (res == WAIT_OBJECT_0);
122 } // end of namespace