00001 /* 00002 Copyright (C) 2004-2006 Grame 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 00018 */ 00019 00020 #include "JackWinProcessSync.h" 00021 #include "JackError.h" 00022 00023 namespace Jack 00024 { 00025 00026 void JackWinProcessSync::Signal() 00027 { 00028 SetEvent(fEvent); 00029 } 00030 00031 void JackWinProcessSync::LockedSignal() 00032 { 00033 WaitForSingleObject(fMutex, INFINITE); 00034 SetEvent(fEvent); 00035 ReleaseMutex(fMutex); 00036 } 00037 00038 void JackWinProcessSync::SignalAll() 00039 { 00040 SetEvent(fEvent); 00041 } 00042 00043 void JackWinProcessSync::LockedSignalAll() 00044 { 00045 WaitForSingleObject(fMutex, INFINITE); 00046 SetEvent(fEvent); 00047 ReleaseMutex(fMutex); 00048 } 00049 00050 void JackWinProcessSync::Wait() 00051 { 00052 ReleaseMutex(fMutex); 00053 WaitForSingleObject(fEvent, INFINITE); 00054 } 00055 00056 void JackWinProcessSync::LockedWait() 00057 { 00058 /* Does it make sense on Windows, use non-locked version for now... */ 00059 Wait(); 00060 } 00061 00062 bool JackWinProcessSync::TimedWait(long usec) 00063 { 00064 ReleaseMutex(fMutex); 00065 DWORD res = WaitForSingleObject(fEvent, usec / 1000); 00066 return (res == WAIT_OBJECT_0); 00067 } 00068 00069 bool JackWinProcessSync::LockedTimedWait(long usec) 00070 { 00071 /* Does it make sense on Windows, use non-locked version for now...*/ 00072 return TimedWait(usec); 00073 } 00074 00075 /* 00076 Code from CAGuard.cpp : does ot sees to work as expected.. 00077 00078 void JackWinProcessSync::Wait() 00079 { 00080 ReleaseMutex(fMutex); 00081 HANDLE handles[] = { fMutex, fEvent }; 00082 DWORD res = WaitForMultipleObjects(2, handles, true, INFINITE); 00083 if ((res != WAIT_OBJECT_0) && (res != WAIT_TIMEOUT)) 00084 jack_error("Wait error err = %d", GetLastError()); 00085 ResetEvent(fEvent); 00086 } 00087 00088 void JackWinProcessSync::LockedWait() 00089 { 00090 WaitForSingleObject(fMutex, INFINITE); 00091 ReleaseMutex(fMutex); 00092 HANDLE handles[] = { fMutex, fEvent }; 00093 DWORD res = WaitForMultipleObjects(2, handles, true, INFINITE); 00094 if ((res != WAIT_OBJECT_0) && (res != WAIT_TIMEOUT)) 00095 jack_error("LockedWait error err = %d", GetLastError()); 00096 ResetEvent(fEvent); 00097 } 00098 00099 bool JackWinProcessSync::TimedWait(long usec) 00100 { 00101 ReleaseMutex(fMutex); 00102 HANDLE handles[] = { fMutex, fEvent }; 00103 DWORD res = WaitForMultipleObjects(2, handles, true, usec / 1000); 00104 if ((res != WAIT_OBJECT_0) && (res != WAIT_TIMEOUT)) 00105 jack_error("Wait error err = %d", GetLastError()); 00106 ResetEvent(fEvent); 00107 } 00108 00109 bool JackWinProcessSync::LockedTimedWait(long usec) 00110 { 00111 WaitForSingleObject(fMutex, INFINITE); 00112 ReleaseMutex(fMutex); 00113 HANDLE handles[] = { fMutex, fEvent }; 00114 DWORD res = WaitForMultipleObjects(2, handles, true, usec / 1000); 00115 if ((res != WAIT_OBJECT_0) && (res != WAIT_TIMEOUT)) 00116 jack_error("LockedTimedWait error err = %d", GetLastError()); 00117 ResetEvent(fEvent); 00118 return (res == WAIT_OBJECT_0); 00119 } 00120 */ 00121 00122 } // end of namespace 00123 00124 00125