Permalink
Browse files

Change the QMutex to QSemaphore in myth_system

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...
1 parent c548468 commit 7cdfb8eb450c787c40a6b2ee70b7f641b20f6cb9 @Beirdo Beirdo committed Dec 16, 2010
Showing with 8 additions and 6 deletions.
  1. +8 −6 mythtv/libs/libmythdb/mythsystem.cpp
@@ -44,7 +44,7 @@
#ifndef USING_MINGW
typedef struct {
- QMutex mutex;
+ QSemaphore ready;
uint result;
time_t timeout;
bool background;
@@ -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();
@@ -167,8 +167,8 @@ void MythSystemReaper::run(void)
if( pidData->background )
delete pidData;
- else
- pidData->mutex.unlock();
+ else
+ pidData->ready.release(1);
}
}
@@ -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();

0 comments on commit 7cdfb8e

Please sign in to comment.