Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed calls to Event::Wait* that were supposed to be interruptible.

Durring the threading-refactor, there were several places where calls to CThreads::WaitForSingleObject was replaced with calls to the replacement for ::WaitForSingleObject. The CThreads version of the call would return when the thread was stopped. This fix puts back that behavior in the places that were it was originally.

Also incorporated elupus' comments on style and which approach to use.
  • Loading branch information...
commit af1ae88b47a80f7de58deb86a23ad760f3dd5bde 1 parent 8c7bdfa
Jim Carroll authored
View
4 xbmc/cdrip/CDDAReader.cpp
@@ -116,7 +116,7 @@ void CCDDAReader::Process()
while (!m_bStop)
{
// wait until someone called GetData()
- if (m_hReadEvent.Wait())
+ if (AbortableWait(m_hReadEvent) == WAIT_SIGNALED)
{
// event generated by m_hReadEvent, continue
// switch buffer and start reading in this one
@@ -131,7 +131,7 @@ void CCDDAReader::Process()
int CCDDAReader::GetData(BYTE** stream, long& lBytes)
{
// wait until we are sure we have a buffer that is filled
- m_hDataReadyEvent.Wait();
+ AbortableWait(m_hDataReadyEvent);
int iError = m_sRipBuffer[m_iCurrentBuffer].iRipError;
*stream = m_sRipBuffer[m_iCurrentBuffer].pbtStream;
View
3  xbmc/filesystem/FileCache.cpp
@@ -244,8 +244,7 @@ void CFileCache::Process()
m_pCache->EndOfInput();
// The thread event will now also cause the wait of an event to return a false.
- XbmcThreads::CEventGroup group(&m_seekEvent, getStopEvent(), NULL);
- if (group.wait() == &m_seekEvent)
+ if (AbortableWait(m_seekEvent) == WAIT_SIGNALED)
{
m_pCache->ClearEndOfInput();
m_seekEvent.Set(); // hack so that later we realize seek is needed
View
6 xbmc/filesystem/FileRar.cpp
@@ -54,7 +54,7 @@ CFileRarExtractThread::CFileRarExtractThread() : hRunning(true), hQuit(true)
CFileRarExtractThread::~CFileRarExtractThread()
{
hQuit.Set();
- hRestart.Wait();
+ AbortableWait(hRestart);
StopThread();
}
@@ -85,9 +85,9 @@ void CFileRarExtractThread::OnExit()
void CFileRarExtractThread::Process()
{
- while (!hQuit.WaitMSec(1))
+ while (AbortableWait(hQuit,1) != WAIT_SIGNALED)
{
- if (hRestart.WaitMSec(1))
+ if (AbortableWait(hRestart,1) == WAIT_SIGNALED)
{
bool Repeat = false;
m_pExtract->ExtractCurrentFile(m_pCmd,*m_pArc,m_iSize,Repeat);
View
2  xbmc/music/LastFmManager.cpp
@@ -606,7 +606,7 @@ void CLastFmManager::Process()
while (!m_bStop)
{
- m_hWorkerEvent.Wait();
+ AbortableWait(m_hWorkerEvent);
if (m_bStop)
break;
int iNrCachedTracks = m_RadioTrackQueue->size();
View
3  xbmc/network/libscrobbler/scrobbler.cpp
@@ -636,10 +636,9 @@ void CScrobbler::Process()
if (!(m_pHttp = new XFILE::CFileCurl))
return;
}
- XbmcThreads::CEventGroup eventGroup(&m_hEvent, getStopEvent(), NULL);
while (!m_bStop)
{
- eventGroup.wait();
+ AbortableWait(m_hEvent);
if (m_bStop)
break;
View
2  xbmc/pictures/GUIWindowSlideShow.cpp
@@ -91,7 +91,7 @@ void CBackgroundPicLoader::Process()
unsigned int count = 0;
while (!m_bStop)
{ // loop around forever, waiting for the app to call LoadPic
- if (m_loadPic.WaitMSec(10))
+ if (AbortableWait(m_loadPic,10) == WAIT_SIGNALED)
{
if (m_pCallback)
{
View
23 xbmc/threads/Thread.h
@@ -85,7 +85,28 @@ class CThread
volatile bool m_bStop;
HANDLE m_ThreadHandle;
- inline CEvent* getStopEvent() { return &m_StopEvent; }
+ enum WaitResponse { WAIT_INTERRUPTED = -1, WAIT_SIGNALED = 0, WAIT_TIMEDOUT = 1 };
+
+ /**
+ * This call will wait on a CEvent in an interruptible way such that if
+ * stop is called on the thread the wait will return with a respone
+ * indicating what happened.
+ */
+ inline WaitResponse AbortableWait(CEvent& event, int timeoutMillis)
+ {
+ XbmcThreads::CEventGroup group(&event, &m_StopEvent, NULL);
+ CEvent* result = group.wait(timeoutMillis);
+ return result == &event ? WAIT_SIGNALED :
+ (result == NULL ? WAIT_TIMEDOUT : WAIT_INTERRUPTED);
+ }
+
+ inline WaitResponse AbortableWait(CEvent& event)
+ {
+ XbmcThreads::CEventGroup group(&event, &m_StopEvent, NULL);
+ CEvent* result = group.wait();
+ return result == &event ? WAIT_SIGNALED :
+ (result == NULL ? WAIT_TIMEDOUT : WAIT_INTERRUPTED);
+ }
private:
CStdString GetTypeName(void);
View
2  xbmc/win32/WindowHelper.cpp
@@ -77,7 +77,7 @@ void CWHelper::Process()
{
while (( !m_bStop ))
{
- if(WaitForSingleObject(m_hProcess,500) != WAIT_TIMEOUT)
+ if(AbortableWait(m_hProcess,500) == WAIT_SIGNALED)
break;
/*if((m_hwnd != NULL) && (IsIconic(m_hwnd) == TRUE))
break;*/
Please sign in to comment.
Something went wrong with that request. Please try again.