cIsThread: Added the Stop() method and debugging output in Wait()
This commit is contained in:
parent
eb9d45e906
commit
2baa6634ec
@ -116,36 +116,38 @@ bool cIsThread::Start(void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cIsThread::Stop(void)
|
||||||
|
{
|
||||||
|
if (m_Handle == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_ShouldTerminate = true;
|
||||||
|
Wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cIsThread::Wait(void)
|
bool cIsThread::Wait(void)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
|
||||||
|
|
||||||
if (m_Handle == NULL)
|
if (m_Handle == NULL)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Cannot log, logger may already be stopped:
|
LOGD("Waiting for thread %s to finish", m_ThreadName.c_str());
|
||||||
// LOG("Waiting for thread \"%s\" to terminate.", m_ThreadName.c_str());
|
|
||||||
|
#ifdef _WIN32
|
||||||
int res = WaitForSingleObject(m_Handle, INFINITE);
|
int res = WaitForSingleObject(m_Handle, INFINITE);
|
||||||
m_Handle = NULL;
|
m_Handle = NULL;
|
||||||
// Cannot log, logger may already be stopped:
|
LOGD("Thread %s finished", m_ThreadName.c_str());
|
||||||
// LOG("Thread \"%s\" %s terminated, GLE = %d", m_ThreadName.c_str(), (res == WAIT_OBJECT_0) ? "" : "not", GetLastError());
|
|
||||||
return (res == WAIT_OBJECT_0);
|
return (res == WAIT_OBJECT_0);
|
||||||
|
|
||||||
#else // _WIN32
|
#else // _WIN32
|
||||||
|
|
||||||
if (!m_HasStarted)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// Cannot log, logger may already be stopped:
|
|
||||||
// LOG("Waiting for thread \"%s\" to terminate.", m_ThreadName.c_str());
|
|
||||||
int res = pthread_join(m_Handle, NULL);
|
int res = pthread_join(m_Handle, NULL);
|
||||||
m_HasStarted = false;
|
m_Handle = NULL;
|
||||||
// Cannot log, logger may already be stopped:
|
LOGD("Thread %s finished", m_ThreadName.c_str());
|
||||||
// LOG("Thread \"%s\" %s terminated, errno = %d", m_ThreadName.c_str(), (res == 0) ? "" : "not", errno);
|
|
||||||
return (res == 0);
|
return (res == 0);
|
||||||
|
|
||||||
#endif // else _WIN32
|
#endif // else _WIN32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,9 @@ public:
|
|||||||
/// Starts the thread; returns without waiting for the actual start
|
/// Starts the thread; returns without waiting for the actual start
|
||||||
bool Start(void);
|
bool Start(void);
|
||||||
|
|
||||||
|
/// Signals the thread to terminate and waits until it's finished
|
||||||
|
void Stop(void);
|
||||||
|
|
||||||
/// Waits for the thread to finish. Doesn't signalize the ShouldTerminate flag
|
/// Waits for the thread to finish. Doesn't signalize the ShouldTerminate flag
|
||||||
bool Wait(void);
|
bool Wait(void);
|
||||||
|
|
||||||
@ -70,7 +73,6 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif // else _WIN32
|
#endif // else _WIN32
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user