Skip to content

Commit

Permalink
Change the QMutex to QSemaphore in myth_system
Browse files Browse the repository at this point in the history
Seems QMutex must be locked/unlocked in the same thread, or it throws errors.
As we were locking in one thread, and unlocking in another, this caused asserts
when using a debug Qt build.

Based on a patch from Lawrence Rust <lvr@softsystem.co.uk>

Fixes Ticket 9378
  • Loading branch information
Beirdo committed Dec 16, 2010
1 parent a7a0ec5 commit 2425dd9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions mythtv/libs/libmythdb/mythsystem.cpp
Expand Up @@ -44,7 +44,7 @@

#ifndef USING_MINGW
typedef struct {
QMutex mutex;
QSemaphore ready;
uint result;
time_t timeout;
bool background;
Expand Down Expand Up @@ -107,7 +107,7 @@ void MythSystemReaper::run(void)
kill(pid, SIGTERM);
usleep(500);
kill(pid, SIGKILL);
pidData->mutex.unlock();
pidData->ready.release(1);
}
count = m_pidMap.size();
m_mapLock.unlock();
Expand Down Expand Up @@ -167,8 +167,8 @@ void MythSystemReaper::run(void)

if( pidData->background )
delete pidData;
else
pidData->mutex.unlock();
else
pidData->ready.release(1);
}
}

Expand All @@ -178,21 +178,23 @@ uint MythSystemReaper::waitPid( pid_t pid, time_t timeout, bool background,
PidData_t *pidData = new PidData_t;
uint result;

pidData->ready.release(1); // Initialize

if( timeout > 0 )
pidData->timeout = time(NULL) + timeout;
else
pidData->timeout = 0;

pidData->background = background;

pidData->mutex.lock();
pidData->ready.acquire(1);
m_mapLock.lock();
m_pidMap.insert( pid, pidData );
m_mapLock.unlock();

if( !background ) {
/* Now we wait for the thread to see the SIGCHLD */
while( !pidData->mutex.tryLock(100) )
while( !pidData->ready.tryAcquire(1,100) )
if (processEvents)
qApp->processEvents();

Expand Down

0 comments on commit 2425dd9

Please sign in to comment.