Tagging the 1.9.8 release of the 'jack2' project.
[jack2.git] / windows / JackWinProcessSync.cpp
blob5f3fa2fde98462ac59bed57e4f59b2c606950871
1 /*
2 Copyright (C) 2004-2008 Grame
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.
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.
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.
21 #include "JackWinProcessSync.h"
22 #include "JackError.h"
24 namespace Jack
27 void JackWinProcessSync::Signal()
29 SetEvent(fEvent);
32 void JackWinProcessSync::LockedSignal()
34 WaitForSingleObject(fMutex, INFINITE);
35 SetEvent(fEvent);
36 ReleaseMutex(fMutex);
39 void JackWinProcessSync::SignalAll()
41 SetEvent(fEvent);
44 void JackWinProcessSync::LockedSignalAll()
46 WaitForSingleObject(fMutex, INFINITE);
47 SetEvent(fEvent);
48 ReleaseMutex(fMutex);
51 void JackWinProcessSync::Wait()
53 ReleaseMutex(fMutex);
54 WaitForSingleObject(fEvent, INFINITE);
57 void JackWinProcessSync::LockedWait()
59 /* Does it make sense on Windows, use non-locked version for now... */
60 Wait();
63 bool JackWinProcessSync::TimedWait(long usec)
65 ReleaseMutex(fMutex);
66 DWORD res = WaitForSingleObject(fEvent, usec / 1000);
67 return (res == WAIT_OBJECT_0);
70 bool JackWinProcessSync::LockedTimedWait(long usec)
72 /* Does it make sense on Windows, use non-locked version for now...*/
73 return TimedWait(usec);
77 Code from APPLE CAGuard.cpp : does not seem to work as expected...
79 void JackWinProcessSync::Wait()
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);
89 void JackWinProcessSync::LockedWait()
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);
100 bool JackWinProcessSync::TimedWait(long usec)
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);
110 bool JackWinProcessSync::LockedTimedWait(long usec)
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);
123 } // end of namespace