X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fplatform%2Fthreads.cpp;h=46953169c98c5a4e485c87470f1bfcd48e88e235;hb=25701fa60407a0fc0bc1dfcd4049fc01ad9e4fd1;hp=08a4c3b8884c39e9ce775212e8d5665a78175316;hpb=262f3b0529397d1c76ede935b8ef572b013e90d3;p=deb_libcec.git diff --git a/src/lib/platform/threads.cpp b/src/lib/platform/threads.cpp index 08a4c3b..4695316 100644 --- a/src/lib/platform/threads.cpp +++ b/src/lib/platform/threads.cpp @@ -106,7 +106,7 @@ void CCondition::Signal(void) pthread_cond_signal(&m_cond); } -bool CCondition::Wait(CMutex *mutex, int64_t iTimeout) +bool CCondition::Wait(CMutex *mutex, uint32_t iTimeout) { bool bReturn(false); sched_yield(); @@ -114,19 +114,17 @@ bool CCondition::Wait(CMutex *mutex, int64_t iTimeout) { struct timespec abstime; struct timeval now; - if (gettimeofday(&now, NULL) == 0) - { - iTimeout += now.tv_usec / 1000; - abstime.tv_sec = now.tv_sec + (time_t)(iTimeout / 1000); - abstime.tv_nsec = (long)((iTimeout % (unsigned long)1000) * (unsigned long)1000000); - bReturn = (pthread_cond_timedwait(&m_cond, &mutex->m_mutex, &abstime) == 0); - } + gettimeofday(&now, NULL); + iTimeout += now.tv_usec / 1000; + abstime.tv_sec = now.tv_sec + (time_t)(iTimeout / 1000); + abstime.tv_nsec = (int32_t)((iTimeout % (uint32_t)1000) * (uint32_t)1000000); + bReturn = (pthread_cond_timedwait(&m_cond, &mutex->m_mutex, &abstime) == 0); } return bReturn; } -void CCondition::Sleep(int64_t iTimeout) +void CCondition::Sleep(uint32_t iTimeout) { CCondition w; CMutex m; @@ -142,9 +140,7 @@ CThread::CThread(void) : CThread::~CThread(void) { - m_bStop = true; - m_threadCondition.Broadcast(); - pthread_join(m_thread, NULL); + StopThread(); } bool CThread::CreateThread(void) @@ -179,14 +175,19 @@ bool CThread::StopThread(bool bWaitForExit /* = true */) m_bStop = true; m_threadCondition.Broadcast(); - void *retVal; - if (bWaitForExit) - bReturn = (pthread_join(m_thread, &retVal) == 0); + if (m_bRunning) + { + void *retVal; + if (bWaitForExit) + bReturn = (pthread_join(m_thread, &retVal) == 0); + + m_bRunning = false; + } return bReturn; } -bool CThread::Sleep(uint64_t iTimeout) +bool CThread::Sleep(uint32_t iTimeout) { CLockObject lock(&m_threadMutex); return m_bStop ? false :m_threadCondition.Wait(&m_threadMutex, iTimeout);