Jack2 1.9.6

JackWinProcessSync.cpp

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