Ensure mutexes are always properly unlocked

Error exists with Qt4 and Qt5.  Qt5 generated helpful warnings that made
it easier to debug.
This commit is contained in:
maurerpe
2016-02-21 13:20:46 -05:00
committed by wmayer
parent 8de9436c36
commit 31fd2d1762
3 changed files with 25 additions and 28 deletions

View File

@@ -30,6 +30,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\**************************************************************************/
#include <QMutexLocker>
#include "SignalThread.h"
using namespace SIM::Coin3D::Quarter;
@@ -47,25 +49,23 @@ void
SignalThread::trigger(void)
{
// lock first to make sure the QThread is actually waiting for a signal
this->mutex.lock();
QMutexLocker ml(&this->mutex);
this->waitcond.wakeOne();
this->mutex.unlock();
}
void
SignalThread::stopThread(void)
{
this->mutex.lock();
QMutexLocker ml(&this->mutex);
this->isstopped = true;
this->waitcond.wakeOne();
this->mutex.unlock();
}
void
SignalThread::run(void)
{
this->mutex.lock();
QMutexLocker ml(&this->mutex);
while (!this->isstopped) {
// just wait, and trigger every time we receive a signal
this->waitcond.wait(&this->mutex);
@@ -73,5 +73,4 @@ SignalThread::run(void)
emit triggerSignal();
}
}
this->mutex.unlock();
}