From da82d0e4858823f9176c19239d4406cf7930af02 Mon Sep 17 00:00:00 2001 From: sletz Date: Sun, 29 Jan 2012 18:19:24 +0000 Subject: [PATCH] Works again on Windows. git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4750 0c269be4-1314-0410-8aa9-9f06e86f4224 --- common/JackMessageBuffer.cpp | 6 +++--- windows/JackWinMutex.cpp | 25 +++++++++++++++++++------ windows/JackWinMutex.h | 15 ++++++++++----- windows/JackWinProcessSync.h | 18 +++++++++++------- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/common/JackMessageBuffer.cpp b/common/JackMessageBuffer.cpp index fd5b5175..a401da63 100644 --- a/common/JackMessageBuffer.cpp +++ b/common/JackMessageBuffer.cpp @@ -32,7 +32,7 @@ JackMessageBuffer::JackMessageBuffer() :fInit(NULL), fInitArg(NULL), fThread(this), - fGuard("JackMessageBuffer"), + fGuard(), fInBuffer(0), fOutBuffer(0), fOverruns(0), @@ -49,7 +49,7 @@ bool JackMessageBuffer::Start() return true; } else { return false; - } + } } bool JackMessageBuffer::Stop() @@ -133,7 +133,7 @@ bool JackMessageBuffer::Create() return false; } } - + return true; } diff --git a/windows/JackWinMutex.cpp b/windows/JackWinMutex.cpp index c567afba..6d3680a6 100644 --- a/windows/JackWinMutex.cpp +++ b/windows/JackWinMutex.cpp @@ -76,19 +76,34 @@ namespace Jack bool JackWinMutex::Lock() { - return (WAIT_OBJECT_0 == WaitForSingleObject(fMutex, INFINITE)); + if (WAIT_OBJECT_0 == WaitForSingleObject(fMutex, INFINITE)) { + return true; + } else { + jack_log("JackWinProcessSync::Lock WaitForSingleObject err = %d", GetLastError()); + return false; + } } bool JackWinMutex::Trylock() { - return (WAIT_OBJECT_0 == WaitForSingleObject(fMutex, 0)); + if (WAIT_OBJECT_0 == WaitForSingleObject(fMutex, 0)) { + return true; + } else { + jack_log("JackWinProcessSync::Lock WaitForSingleObject err = %d", GetLastError()); + return false; + } } bool JackWinMutex::Unlock() { - return (ReleaseMutex(fMutex) != 0); + if (!ReleaseMutex(fMutex)) { + jack_log("JackWinProcessSync::Unlock ReleaseMutex err = %d", GetLastError()); + return false; + } else { + return true; + } } - + bool JackWinCriticalSection::Lock() { EnterCriticalSection(&fSection); @@ -106,8 +121,6 @@ namespace Jack return true; } - - } // namespace diff --git a/windows/JackWinMutex.h b/windows/JackWinMutex.h index ded31f15..acab453d 100644 --- a/windows/JackWinMutex.h +++ b/windows/JackWinMutex.h @@ -71,10 +71,15 @@ class SERVER_EXPORT JackWinMutex JackWinMutex(const char* name = NULL) { - // In recursive mode by default - char buffer[MAX_PATH]; - snprintf(buffer, sizeof(buffer), "%s_%s", "JackWinMutex", name); - fMutex = CreateMutex(NULL, FALSE, buffer); + // In recursive mode by default + if (name) { + char buffer[MAX_PATH]; + snprintf(buffer, sizeof(buffer), "%s_%s", "JackWinMutex", name); + fMutex = CreateMutex(NULL, FALSE, buffer); + } else { + fMutex = CreateMutex(NULL, FALSE, NULL); + } + ThrowIf((fMutex == 0), JackException("JackWinMutex: could not init the mutex")); } @@ -94,7 +99,7 @@ class SERVER_EXPORT JackWinCriticalSection protected: - LPCRITICAL_SECTION fSection; + CRITICAL_SECTION fSection; public: diff --git a/windows/JackWinProcessSync.h b/windows/JackWinProcessSync.h index 25cb4ec3..4e95a8d8 100644 --- a/windows/JackWinProcessSync.h +++ b/windows/JackWinProcessSync.h @@ -15,8 +15,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - +*/ #ifndef __JackWinProcessSync__ #define __JackWinProcessSync__ @@ -39,12 +38,17 @@ class JackWinProcessSync : public JackWinMutex public: - JackWinProcessSync(const char* name = NULL):JackWinMutex() + JackWinProcessSync(const char* name = NULL):JackWinMutex(name) { - char buffer[MAX_PATH]; - snprintf(buffer, sizeof(buffer), "%s_%s", "WinProcessSync", name); - //fEvent = CreateEvent(NULL, TRUE, FALSE, buffer); // Needs ResetEvent - fEvent = CreateEvent(NULL, FALSE, FALSE, NULL); // Audo-reset event + if (name) { + char buffer[MAX_PATH]; + snprintf(buffer, sizeof(buffer), "%s_%s", "JackWinProcessSync", name); + //fEvent = CreateEvent(NULL, TRUE, FALSE, buffer); // Needs ResetEvent + fEvent = CreateEvent(NULL, FALSE, FALSE, buffer); // Auto-reset event + } else { + fEvent = CreateEvent(NULL, FALSE, FALSE, NULL); // Auto-reset event + } + ThrowIf((fEvent == 0), JackException("JackWinProcessSync: could not init the event")); } virtual ~JackWinProcessSync()