Skip to content

Commit

Permalink
Remove potential deadlock on MythSystem IO threads.
Browse files Browse the repository at this point in the history
This performs finer grained locking against the file descriptor type map
in the IO handling mechanisms for MythSystem. If the read thread wakes
up and has data to process at the exact moment the external thread is
handing off a newly started child to the manager for handling, the two
may hit fdLock and MythSystemIOHandler::m_pLock from opposite
directions, deadlocking both threads.

Fixes #11066

Signed-off-by: Raymond Wagner <rwagner@mythtv.org>
  • Loading branch information
jkt628 authored and wagnerrp committed Sep 3, 2012
1 parent 127b32e commit b5fbc74
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions mythtv/libs/libmythbase/system-unix.cpp
Expand Up @@ -444,7 +444,6 @@ void MythSystemManager::append(MythSystemUnix *ms)
m_pMap.insert(ms->m_pid, ms);
m_mapLock.unlock();

fdLock.lock();
if( ms->GetSetting("UseStdin") )
writeThread->insert(ms->m_stdpipe[0], ms->GetBuffer(0));

Expand All @@ -453,7 +452,9 @@ void MythSystemManager::append(MythSystemUnix *ms)
FDType_t *fdType = new FDType_t;
fdType->ms = ms;
fdType->type = 1;
fdLock.lock();
fdMap.insert( ms->m_stdpipe[1], fdType );
fdLock.unlock();
readThread->insert(ms->m_stdpipe[1], ms->GetBuffer(1));
}

Expand All @@ -462,10 +463,11 @@ void MythSystemManager::append(MythSystemUnix *ms)
FDType_t *fdType = new FDType_t;
fdType->ms = ms;
fdType->type = 2;
fdLock.lock();
fdMap.insert( ms->m_stdpipe[2], fdType );
fdLock.unlock();
readThread->insert(ms->m_stdpipe[2], ms->GetBuffer(2));
}
fdLock.unlock();
}

void MythSystemManager::jumpAbort(void)
Expand Down
6 changes: 4 additions & 2 deletions mythtv/libs/libmythbase/system-windows.cpp
Expand Up @@ -402,7 +402,6 @@ void MythSystemManager::append(MythSystemWindows *ms)
ChildListRebuild();
m_mapLock.unlock();

fdLock.lock();
if( ms->GetSetting("UseStdin") )
writeThread->insert(ms->m_stdpipe[0], ms->GetBuffer(0));

Expand All @@ -411,7 +410,9 @@ void MythSystemManager::append(MythSystemWindows *ms)
FDType_t *fdType = new FDType_t;
fdType->ms = ms;
fdType->type = 1;
fdLock.lock();
fdMap.insert( ms->m_stdpipe[1], fdType );
fdLock.unlock();
readThread->insert(ms->m_stdpipe[1], ms->GetBuffer(1));
}

Expand All @@ -420,10 +421,11 @@ void MythSystemManager::append(MythSystemWindows *ms)
FDType_t *fdType = new FDType_t;
fdType->ms = ms;
fdType->type = 2;
fdLock.lock();
fdMap.insert( ms->m_stdpipe[2], fdType );
fdLock.unlock();
readThread->insert(ms->m_stdpipe[2], ms->GetBuffer(2));
}
fdLock.unlock();
}

void MythSystemManager::jumpAbort(void)
Expand Down

0 comments on commit b5fbc74

Please sign in to comment.