From d7470105d700b1bd42ea0b406b46dc14d7a1c075 Mon Sep 17 00:00:00 2001 From: sletz Date: Tue, 27 May 2008 12:39:57 +0000 Subject: [PATCH] Correct thread init phase git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2359 0c269be4-1314-0410-8aa9-9f06e86f4224 --- common/JackPosixThread.cpp | 8 ++++++-- common/JackThread.h | 2 +- common/JackThreadedDriver.cpp | 1 + windows/JackWinThread.cpp | 8 ++++++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/common/JackPosixThread.cpp b/common/JackPosixThread.cpp index b0c06c91..a6c4d0fd 100644 --- a/common/JackPosixThread.cpp +++ b/common/JackPosixThread.cpp @@ -36,9 +36,11 @@ void* JackPosixThread::ThreadHandler(void* arg) jack_error("pthread_setcanceltype err = %s", strerror(err)); } + set_threaded_log_function(); + // Signal creation thread when started with StartSync jack_log("ThreadHandler: start"); - obj->fStatus = kRunning; + obj->fStatus = kIniting; // Call Init method if (!runnable->Init()) { @@ -46,6 +48,8 @@ void* JackPosixThread::ThreadHandler(void* arg) return 0; } + obj->fStatus = kRunning; + // If Init succeed, start the thread loop bool res = true; while (obj->fStatus == kRunning && res) { @@ -78,7 +82,7 @@ int JackPosixThread::StartSync() return -1; } else { int count = 0; - while (fStatus != kRunning && ++count < 1000) { + while (fStatus == kStarting && ++count < 1000) { JackSleep(1000); } return (count == 1000) ? -1 : 0; diff --git a/common/JackThread.h b/common/JackThread.h index cf30f07f..7d47d655 100644 --- a/common/JackThread.h +++ b/common/JackThread.h @@ -62,7 +62,7 @@ class JackThread { public: - enum kThreadState {kIdle, kStarting, kRunning}; + enum kThreadState {kIdle, kStarting, kIniting, kRunning}; protected: diff --git a/common/JackThreadedDriver.cpp b/common/JackThreadedDriver.cpp index 0961bbfa..94b32f35 100644 --- a/common/JackThreadedDriver.cpp +++ b/common/JackThreadedDriver.cpp @@ -68,6 +68,7 @@ int JackThreadedDriver::Stop() // Kill the thread in Init phase case JackThread::kStarting: + case JackThread::kIniting: if (fThread->Kill() < 0) { jack_error("Cannot kill thread"); return -1; diff --git a/windows/JackWinThread.cpp b/windows/JackWinThread.cpp index 30857492..3e7c6e13 100644 --- a/windows/JackWinThread.cpp +++ b/windows/JackWinThread.cpp @@ -31,9 +31,11 @@ DWORD WINAPI JackWinThread::ThreadHandler(void* arg) JackWinThread* obj = (JackWinThread*)arg; JackRunnableInterface* runnable = obj->fRunnable; + set_threaded_log_function(); + // Signal creation thread when started with StartSync jack_log("ThreadHandler: start"); - obj->fStatus = kRunning; + obj->fStatus = kIniting; // Call Init method if (!runnable->Init()) { @@ -41,6 +43,8 @@ DWORD WINAPI JackWinThread::ThreadHandler(void* arg) return 0; } + obj->fStatus = kRunning; + // If Init succeed, start the thread loop bool res = true; while (obj->fStatus == kRunning && res) { @@ -87,7 +91,7 @@ int JackWinThread::StartSync() return -1; } else { int count = 0; - while (fStatus != kRunning && ++count < 1000) { + while (fStatus == kStarting && ++count < 1000) { JackSleep(1000); } return (count == 1000) ? -1 : 0;