From 758a40d8fa03aece6659ae34101cbff3cd2be83e Mon Sep 17 00:00:00 2001 From: sletz Date: Mon, 11 Sep 2006 10:25:52 +0000 Subject: [PATCH] Correct crash bug when closing clients on Windows due to multi-threading synchronization issues. git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@1235 0c269be4-1314-0410-8aa9-9f06e86f4224 --- ChangeLog | 39 ++++++----- windows/JackWinThread.cpp | 141 +++++++++++++++++++++++++------------- 2 files changed, 112 insertions(+), 68 deletions(-) diff --git a/ChangeLog b/ChangeLog index f3ed5be2..d33a6249 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,19 +1,20 @@ ---------------------------- - Jackdmp changes log ---------------------------- - -2006-09-11 Stephane Letz - - * Handling of LoopBack driver only when really needed. - -2006-09-06 Stephane Letz - - * Correct coreaudio driver (input was not working since 0.55 version). - -2006-09-04 Stephane Letz - - * Correct Windows VC++ projects. - -2006-09-03 Stephane Letz - - * First import of version 0.58 code +--------------------------- + Jackdmp changes log +--------------------------- + +2006-09-11 Stephane Letz + + * Handling of LoopBack driver only when really needed. + * Correct crash bug when closing clients on Windows due to multi-threading synchronization issues. + +2006-09-06 Stephane Letz + + * Correct coreaudio driver (input was not working since 0.55 version). + +2006-09-04 Stephane Letz + + * Correct Windows VC++ projects. + +2006-09-03 Stephane Letz + + * First import of version 0.58 code diff --git a/windows/JackWinThread.cpp b/windows/JackWinThread.cpp index 23a121c6..b3599470 100644 --- a/windows/JackWinThread.cpp +++ b/windows/JackWinThread.cpp @@ -68,55 +68,98 @@ JackWinThread::~JackWinThread() CloseHandle(fEvent); } -int JackWinThread::Start() -{ - fRunning = true; - StartSync(): -} - -int JackWinThread::StartSync() -{ - DWORD id; - - if (fRealTime) { - - JackLog("Create RT thread\n"); - fThread = CreateThread(NULL, 0, ThreadHandler, (void*)this, 0, &id); - - if (fThread == NULL) { - jack_error("Cannot create thread error = %d", GetLastError()); - return -1; - } - - if (WaitForSingleObject(fEvent, 3000) != WAIT_OBJECT_0) { // wait 3 sec - jack_error("Thread has not started"); - return -1; - } - - if (!SetThreadPriority(fThread, THREAD_PRIORITY_TIME_CRITICAL)) { - jack_error("Cannot set priority class = %d", GetLastError()); - return -1; - } - - return 0; - - } else { - - JackLog("Create non RT thread\n"); - fThread = CreateThread(NULL, 0, ThreadHandler, (void*)this, 0, &id); - - if (fThread == NULL) { - jack_error("Cannot create thread error = %d", GetLastError()); - return -1; - } - - if (WaitForSingleObject(fEvent, 3000) != WAIT_OBJECT_0) { // wait 3 sec - jack_error("Thread has not started"); - return -1; - } - - return 0; - } +int JackWinThread::Start() +{ + DWORD id; + + fEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + if (fEvent == NULL) { + jack_error("Cannot create event error = %d", GetLastError()); + return -1; + } + + fRunning = true; + + if (fRealTime) { + + JackLog("Create RT thread\n"); + fThread = CreateThread(NULL, 0, ThreadHandler, (void*)this, 0, &id); + + if (fThread == NULL) { + jack_error("Cannot create thread error = %d", GetLastError()); + return -1; + } + + if (!SetThreadPriority(fThread, THREAD_PRIORITY_TIME_CRITICAL)) { + jack_error("Cannot set priority class = %d", GetLastError()); + return -1; + } + + return 0; + + } else { + + JackLog("Create non RT thread\n"); + fThread = CreateThread(NULL, 0, ThreadHandler, (void*)this, 0, &id); + + if (fThread == NULL) { + jack_error("Cannot create thread error = %d", GetLastError()); + return -1; + } + + return 0; + } +} + +int JackWinThread::StartSync() +{ + DWORD id; + + fEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + if (fEvent == NULL) { + jack_error("Cannot create event error = %d", GetLastError()); + return -1; + } + + if (fRealTime) { + + JackLog("Create RT thread\n"); + fThread = CreateThread(NULL, 0, ThreadHandler, (void*)this, 0, &id); + + if (fThread == NULL) { + jack_error("Cannot create thread error = %d", GetLastError()); + return -1; + } + + if (WaitForSingleObject(fEvent, 3000) != WAIT_OBJECT_0) { // wait 3 sec + jack_error("Thread has not started"); + return -1; + } + + if (!SetThreadPriority(fThread, THREAD_PRIORITY_TIME_CRITICAL)) { + jack_error("Cannot set priority class = %d", GetLastError()); + return -1; + } + + return 0; + + } else { + + JackLog("Create non RT thread\n"); + fThread = CreateThread(NULL, 0, ThreadHandler, (void*)this, 0, &id); + + if (fThread == NULL) { + jack_error("Cannot create thread error = %d", GetLastError()); + return -1; + } + + if (WaitForSingleObject(fEvent, 3000) != WAIT_OBJECT_0) { // wait 3 sec + jack_error("Thread has not started"); + return -1; + } + + return 0; + } } // voir http://www.microsoft.com/belux/msdn/nl/community/columns/ldoc/multithread1.mspx