Beispiel #1
0
void fight::on_attack2_clicked()
{

    currentEnemy->setHitPoints(currentEnemy->getHitPoints() - currentPlayer->getPower()) ;
    ui->actionsDoneLabel->setText("You aim for the head!");
    if (currentEnemy->getHitPoints() <= 0)
    {
        QMessageBox::information( this, tr("You have won!"), tr("You're battle is done here,\nGo on your quest!") );
        accept();
        this->close();
    } else {
        QMutex mut;
        mut.tryLock(2000);
        mut.unlock();

        ui->actionsDoneLabel->setText("The enemy attacked!");

        currentPlayer->setHitPoints(currentPlayer->getHitPoints() - currentEnemy->getPower()) ;
        if (currentPlayer->getHitPoints() <= 0)
        {
            QMessageBox::information( this, tr("You have lost! D:"), tr("You're quest has ended,\nChoose a new character\n and begin your quest again") );
            accept();
            this->close();
            //NewMainWindow.close(); you cant call a function like this
        }
    }

}
Beispiel #2
0
void MdiChild::checkModifiedFromOutside()
{
    static QMutex mutex;
    if (!mutex.tryLock())
        return;
    QDateTime t=QFileInfo(curFile).lastModified();
    if ((curFileDate!=QDateTime())&&(QFileInfo(curFile).lastModified()!=curFileDate)) {
        if (QMessageBox::Yes==
                QMessageBox::question(this,
                                      "File modified",
                                      QString("The file %1 has been modified outside the editor. Would you like to reload it?").arg(curFile),
                                      QMessageBox::Yes|QMessageBox::No))
        {
            QFile file(curFile);
            if (!file.open(QFile::ReadOnly | QFile::Text)) {
                QMessageBox::warning(this, tr("UVE"),
                                     tr("Cannot read file %1:\n%2.")
                                     .arg(curFile)
                                     .arg(file.errorString()));
            }
           else {
                QTextStream in(&file);
                QApplication::setOverrideCursor(Qt::WaitCursor);
                setText(in.readAll());
                QApplication::restoreOverrideCursor();
                setCurrentFile(curFile);
            }
        }
        else {
            curFileDate=QFileInfo(curFile).lastModified();
        }
    }
    mutex.unlock();
}
Beispiel #3
0
void MainWindow::update_graph() {
  static QMutex mutex;
  if (!mutex.tryLock()) {
    return;
  }
  // generate some data:
  QVector<double> x(40), y(40);   // initialize with entries 0..100
  tcp_grapher g(1000, 0.4, ui->alpha_value->value(), ui->beta_value->value());
  for (int i = 0; i < 40; ++i) {
    x[i] = i;
    y[i] = g.get_next();
  }
  // create graph and assign data to it:
  ui->tcp_graph->addGraph();
  ui->tcp_graph->graph(0)->setData(x, y);
  // give the axes some labels:
  ui->tcp_graph->xAxis->setLabel("time (rtt)");
  ui->tcp_graph->xAxis->setTicks(false);
  ui->tcp_graph->yAxis->setLabel("cwnd");
  ui->tcp_graph->yAxis->setTicks(false);
  // set axes ranges, so we see all data:
  ui->tcp_graph->xAxis->setRange(0, x.size());
  ui->tcp_graph->yAxis->setRange(0, g.get_max_window());
  ui->tcp_graph->replot();
  mutex.unlock();
}
Beispiel #4
0
void fight::on_attack3_clicked()
{

    currentEnemy->setHitPoints(currentEnemy->getHitPoints() - currentPlayer->getPower()) ;
    ui->actionsDoneLabel->setText("You aim for the leg!");
    if (currentEnemy->getHitPoints() <= 0)
    {
        QMessageBox::information( this, tr("You have won!"), tr("You're battle is done here,\nGo on your quest!") );
        accept();
        this->close();
    } else { 
        QMutex mut;
        mut.tryLock(2000);
        mut.unlock();

        ui->actionsDoneLabel->setText("The enemy attacked!");

        currentPlayer->setHitPoints(currentPlayer->getHitPoints() - currentEnemy->getPower()) ;
        if (currentPlayer->getHitPoints() <= 0)
        {
            QMessageBox::information( this, tr("You have lost! D:"), tr("You're quest has ended,\nChoose a new character\n and begin your quest again") );
            accept();
            this->close();
            ///static_cast<NewMainWindow*>(*parent())->close(); lets make this easier... set a flag then get the flag outside
        }
    }

}
Beispiel #5
0
            void run()
            {
                testsTurn.release();

                threadsTurn.acquire();
                QVERIFY(!normalMutex.tryLock());
                testsTurn.release();

                threadsTurn.acquire();
                QVERIFY(normalMutex.tryLock());
                QVERIFY(lockCount.testAndSetRelaxed(0, 1));
                QVERIFY(!normalMutex.tryLock());
                QVERIFY(lockCount.testAndSetRelaxed(1, 0));
                normalMutex.unlock();
                testsTurn.release();

                threadsTurn.acquire();
                QTime timer;
                timer.start();
                QVERIFY(!normalMutex.tryLock(1000));
                QVERIFY(timer.elapsed() >= 1000);
                testsTurn.release();

                threadsTurn.acquire();
                timer.start();
                QVERIFY(normalMutex.tryLock(1000));
                QVERIFY(timer.elapsed() <= 1000);
                QVERIFY(lockCount.testAndSetRelaxed(0, 1));
                timer.start();
                QVERIFY(!normalMutex.tryLock(1000));
                QVERIFY(timer.elapsed() >= 1000);
                QVERIFY(lockCount.testAndSetRelaxed(1, 0));
                normalMutex.unlock();
                testsTurn.release();

                threadsTurn.acquire();
                QVERIFY(!normalMutex.tryLock(0));
                testsTurn.release();

                threadsTurn.acquire();
                timer.start();
                QVERIFY(normalMutex.tryLock(0));
                QVERIFY(timer.elapsed() < 1000);
                QVERIFY(lockCount.testAndSetRelaxed(0, 1));
                QVERIFY(!normalMutex.tryLock(0));
                QVERIFY(lockCount.testAndSetRelaxed(1, 0));
                normalMutex.unlock();
                testsTurn.release();

                threadsTurn.acquire();
            }
 void run()
 {
     QTime t;
     t.start();
     do {
         if (mutex.tryLock())
             mutex.unlock();
     } while (t.elapsed() < one_minute/2);
 }
Beispiel #7
0
 void run()
 {
     QTime t;
     t.start();
     do {
         if (mutex.tryLock())
             mutex.unlock();
     } while (t.elapsed() < 20000);
 }
// Wake from executive wait condition (RT-safe).
void qmidinetJackMidiThread::sync (void)
{
	if (m_mutex.tryLock()) {
		m_cond.wakeAll();
		m_mutex.unlock();
	}
#ifdef CONFIG_DEBUG
	else qDebug("qmidinetJackMidiThread[%p]::sync(): tryLock() failed.", this);
#endif
}
Beispiel #9
0
 ProgressTaskInfoPtr findTask(const NodePtr& node) const
 {
     assert(!tasksMutex.tryLock());
     
     for (TasksMap::const_iterator it = tasks.begin(); it!=tasks.end(); ++it) {
         if (it->first.lock() == node) {
             return it->second;
         }
     }
     return ProgressTaskInfoPtr();
 }
Beispiel #10
0
    ProgressTaskInfoPtr findTask(const TableItemConstPtr& item) const
    {
        assert( !tasksMutex.tryLock() );

        for (TasksMap::const_iterator it = tasks.begin(); it != tasks.end(); ++it) {
            if (it->second->getTableItem() == item) {
                return it->second;
            }
        }

        return ProgressTaskInfoPtr();
    }
Beispiel #11
0
    NodeInfosMap::iterator findNode(const NodePtr& node)
    {
        //Private, shouldn't lock
        assert( !lock.tryLock() );

        for (NodeInfosMap::iterator it = nodeInfos.begin(); it != nodeInfos.end(); ++it) {
            if (it->first.lock() == node) {
                return it;
            }
        }

        return nodeInfos.end();
    }
 void EditorWidgetBase::setDrawOffsetInternal(VSQ_NS::tick_t drawOffset) {
     static QMutex mutex;
     if (mutex.tryLock()) {
         int xScrollTo = -controllerAdapter->getXFromTick(drawOffset);
         QScrollBar *scrollBar = ui->mainContent->horizontalScrollBar();
         int maxValue = scrollBar->maximum() + scrollBar->pageStep();
         int minValue = scrollBar->minimum();
         int contentWidth = static_cast<int>(ui->mainContent->getSceneWidth());
         int value = static_cast<int>(minValue
                 + (minValue - maxValue) * static_cast<double>(xScrollTo) / contentWidth);
         if (scrollBar->value() != value) scrollBar->setValue(value);
         mutex.unlock();
     }
 }
Beispiel #13
0
 ProgressTaskInfoPtr findTask(const TableItem* item) const
 {
     assert(!tasksMutex.tryLock());
     
     for (TasksMap::const_iterator it = tasks.begin(); it!=tasks.end(); ++it) {
         std::vector<TableItem*> items;
         it->second->getTableItems(&items);
         for (std::size_t i = 0; i < items.size(); ++i) {
             if (items[i] == item) {
                 return it->second;
             }
         }
     }
     return ProgressTaskInfoPtr();
 }
Beispiel #14
0
 void run()
 {
     while (t.elapsed() < one_minute) {
         mutex.lock();
         Q_ASSERT(!sentinel.ref());
         Q_ASSERT(sentinel.deref());
         lockCount.ref();
         mutex.unlock();
         if (mutex.tryLock()) {
             Q_ASSERT(!sentinel.ref());
             Q_ASSERT(sentinel.deref());
             lockCount.ref();
             mutex.unlock();
         }
     }
 }
 void run()
 {
     while (t.elapsed() < one_minute) {
         mutex.lock();
         if (sentinel.ref()) ++errorCount;
         if (!sentinel.deref()) ++errorCount;
         lockCount.ref();
         mutex.unlock();
         if (mutex.tryLock()) {
             if (sentinel.ref()) ++errorCount;
             if (!sentinel.deref()) ++errorCount;
             lockCount.ref();
             mutex.unlock();
         }
     }
 }
/*
 * Make a window blink (to draw user's attention)
 */
void lamexp_blink_window(QWidget *poWindow, unsigned int count, unsigned int delay)
{
	static QMutex blinkMutex;

	const double maxOpac = 1.0;
	const double minOpac = 0.3;
	const double delOpac = 0.1;

	if(!blinkMutex.tryLock())
	{
		qWarning("Blinking is already in progress, skipping!");
		return;
	}
	
	try
	{
		const int steps = static_cast<int>(ceil(maxOpac - minOpac) / delOpac);
		const int sleep = static_cast<int>(floor(static_cast<double>(delay) / static_cast<double>(steps)));
		const double opacity = poWindow->windowOpacity();
	
		for(unsigned int i = 0; i < count; i++)
		{
			for(double x = maxOpac; x >= minOpac; x -= delOpac)
			{
				poWindow->setWindowOpacity(x);
				QApplication::processEvents();
				lamexp_sleep(sleep);
			}

			for(double x = minOpac; x <= maxOpac; x += delOpac)
			{
				poWindow->setWindowOpacity(x);
				QApplication::processEvents();
				lamexp_sleep(sleep);
			}
		}

		poWindow->setWindowOpacity(opacity);
		QApplication::processEvents();
		blinkMutex.unlock();
	}
	catch(...)
	{
		blinkMutex.unlock();
		qWarning("Exception error while blinking!");
	}
}
Beispiel #17
0
void TrackCollection::callSync(func lambda, QString where) {
    QMutex mutex;
    //SleepableQThread::sleep(5);
    mutex.lock();
    callAsync( [&mutex, &lambda] (void) {
        lambda();
        //SleepableQThread::sleep(5);
        mutex.unlock();
    }, where);

    while (!mutex.tryLock(5)) {
        MainExecuter::getInstance().call();
        // DBG() << "Start animation";
        // animationIsShowed = true;
    }
    mutex.unlock(); // QMutexes should be always destroyed in unlocked state.
}
Beispiel #18
0
static PyObject *meth_QMutex_tryLock(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        QMutex *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QMutex, &sipCpp))
        {
            bool sipRes;

            Py_BEGIN_ALLOW_THREADS
            sipRes = sipCpp->tryLock();
            Py_END_ALLOW_THREADS

            return PyBool_FromLong(sipRes);
        }
    }
void cCustomTitleModelItem::paint(QPainter *painter,const QStyleOptionViewItem &option,const QModelIndex &index) const {
    if (!CustomTitleModelTableLockPaint.tryLock()) return;
    if ((!Table->ApplicationConfig)||(Table->InModifTable)) return;

    int             CurIndex=index.row()*Table->columnCount()+index.column();
    QModelIndexList SelList =Table->selectionModel()->selectedIndexes();
    int             CurSelIndex=SelList.count()>0?SelList[0].row()*Table->columnCount()+SelList[0].column():-1;

    if ((CurIndex==CurSelIndex)&&(CurIndex<Table->ModelTable->List.count())) painter->fillRect(option.rect,Qt::blue); else painter->fillRect(option.rect,Qt::white);

    if ((CurIndex>=0)&&(CurIndex<Table->ModelTable->List.count())) {

        painter->drawImage(option.rect.left()+10,option.rect.top()+10,
                           Table->ModelTable->List[CurIndex]->PrepareImage((Table->TimerPosition % Table->ModelTable->List[CurIndex]->Duration),NULL,Table->CurrentSlide));

        QString ModelDuration=QTime(0,0,0,0).addMSecs(Table->ModelTable->List[CurIndex]->Duration).toString("mm:ss.zzz");
        int    FontFactor=((Table->ApplicationConfig->TimelineHeight-TIMELINEMINHEIGH)/20)*10;
        QFont  font= QApplication::font();
        QPen   Pen;

        painter->setFont(font);
        #ifdef Q_OS_WIN
        font.setPointSizeF(double(110+FontFactor)/double(painter->fontMetrics().boundingRect("0").height()));                  // Scale font
        #else
        font.setPointSizeF((double(140+FontFactor)/double(painter->fontMetrics().boundingRect("0").height()))*ScreenFontAdjust);// Scale font
        #endif
        painter->setFont(font);

        Pen.setWidth(1);
        Pen.setStyle(Qt::SolidLine);
        Pen.setColor(Qt::black);
        painter->setPen(Pen);
        painter->drawText(QRect(option.rect.left()+1,option.rect.top()+1,option.rect.width()-1,option.rect.height()-1),ModelDuration,Qt::AlignCenter|Qt::AlignBottom);
        Pen.setColor(Qt::white);
        painter->setPen(Pen);
        painter->drawText(QRect(option.rect.left(),option.rect.top(),option.rect.width()-1,option.rect.height()-1),ModelDuration,Qt::AlignCenter|Qt::AlignBottom);
    }
    CustomTitleModelTableLockPaint.unlock();
}
void SyncContactsThread::run()
{
    m_bStop = false;

    QMutex *mutex = &(g_pContactManager->m_LoadContactsMutex);

    if (mutex->tryLock(5000)==false)
    { // wait 5 seconds max.
        emit loadingContactsFinished(false, "Mutex lock failed.");
        return;
    }

    {
        // we remove connection at the end, so finish with QSqlDatabase object in this scope
        QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", SQLITE_DB_CONNECTION_NAME);
        db.setDatabaseName(DBPath);
        db.open();
    }

    QString resultErrorMessage;
    bool bContactsLoadedSuccessfully = true;

    if (global::IsOutlookInstalled()) {
        bContactsLoadedSuccessfully = false;

        QString db_path= g_pContactManager->getDBPath();
        QString log_path = g_AppSettingsFolderPath + "/outcall.log";

        //if outlook x64
        if (true/*IsOutlook64bit()*/) // always use helper app to avoid potential crashing in outcall
        {
            bool b64 = global::IsOutlook64bit();
            QString helper_path;
            if (b64)
                helper_path = g_AppDirPath + "/Outlook/x64/outlook_helper_x64.exe";
            else
                helper_path = g_AppDirPath + "/Outlook/outlook_helper.exe";

            QStringList arguments;
            QString exchange = "true";
            arguments << QString("LoadContacts").toLatin1().data() << db_path.toLatin1().data() << log_path.toLatin1().data() << exchange;

            //HelperProcess outlookHelperProcess(helper_path, arguments);
            QProcess outlookHelperProcess;
            if (b64)
                outlookHelperProcess.setWorkingDirectory(g_AppDirPath + "/Outlook/x64");
            else
                outlookHelperProcess.setWorkingDirectory(g_AppDirPath + "/Outlook");

            outlookHelperProcess.start(helper_path, arguments);
            if (!outlookHelperProcess.waitForStarted(10000)) {
                if (b64)
                    resultErrorMessage = "Outlook helper x64 could not be started.";
                else
                    resultErrorMessage = "Outlook helper could not be started.";
            } else {
                while (!m_bStop) {
                    if (outlookHelperProcess.waitForFinished(1000))
                        break;
                }
                if (m_bStop) {
                    outlookHelperProcess.kill();
                    resultErrorMessage = "Cancelled";
                } else {
                    resultErrorMessage = QString(outlookHelperProcess.readAllStandardOutput());

                    if (resultErrorMessage=="_ok_") {
                        bContactsLoadedSuccessfully = true;
                        resultErrorMessage = "";
                    }
                    else if (resultErrorMessage.isEmpty()) {
                        resultErrorMessage = tr("Unknown error. Check log files for more information.");
                    }

                    /*if (resultErrorMessage.isEmpty())
                        bContactsLoadedSuccessfully = true;*/
                }
            }
        }
    }

    QSqlDatabase::removeDatabase(SQLITE_DB_CONNECTION_NAME); // free resources
    mutex->unlock();

    emit loadingContactsFinished(bContactsLoadedSuccessfully, resultErrorMessage);
}
            void run()
            {
                testsTurn.release();

                // TEST 1: thread can't acquire lock
                threadsTurn.acquire();
                QVERIFY(!normalMutex.tryLock());
                testsTurn.release();

                // TEST 2: thread can acquire lock
                threadsTurn.acquire();
                QVERIFY(normalMutex.tryLock());
                QVERIFY(lockCount.testAndSetRelaxed(0, 1));
                QVERIFY(!normalMutex.tryLock());
                QVERIFY(lockCount.testAndSetRelaxed(1, 0));
                normalMutex.unlock();
                testsTurn.release();

                // TEST 3: thread can't acquire lock, timeout = waitTime
                threadsTurn.acquire();
                QTime timer;
                timer.start();
                QVERIFY(!normalMutex.tryLock(waitTime));
                QVERIFY(timer.elapsed() >= waitTime);
                testsTurn.release();

                // TEST 4: thread can acquire lock, timeout = waitTime
                threadsTurn.acquire();
                timer.start();
                QVERIFY(normalMutex.tryLock(waitTime));
                QVERIFY(timer.elapsed() <= waitTime);
                QVERIFY(lockCount.testAndSetRelaxed(0, 1));
                timer.start();
                // it's non-recursive, so the following lock needs to fail
                QVERIFY(!normalMutex.tryLock(waitTime));
                QVERIFY(timer.elapsed() >= waitTime);
                QVERIFY(lockCount.testAndSetRelaxed(1, 0));
                normalMutex.unlock();
                testsTurn.release();

                // TEST 5: thread can't acquire lock, timeout = 0
                threadsTurn.acquire();
                QVERIFY(!normalMutex.tryLock(0));
                testsTurn.release();

                // TEST 6: thread can acquire lock, timeout = 0
                threadsTurn.acquire();
                timer.start();
                QVERIFY(normalMutex.tryLock(0));
                QVERIFY(timer.elapsed() < waitTime);
                QVERIFY(lockCount.testAndSetRelaxed(0, 1));
                QVERIFY(!normalMutex.tryLock(0));
                QVERIFY(lockCount.testAndSetRelaxed(1, 0));
                normalMutex.unlock();
                testsTurn.release();

                // TEST 7 overflow: thread can acquire lock, timeout = 3000 (QTBUG-24795)
                threadsTurn.acquire();
                timer.start();
                QVERIFY(normalMutex.tryLock(3000));
                QVERIFY(timer.elapsed() < 3000);
                normalMutex.unlock();
                testsTurn.release();

                threadsTurn.acquire();
            }
 void run() {
     tryLockResult = mut.tryLock(timeout);
     mut.unlock();
 }
/**
 * @brief AgentCluster::sleep Pauses the current thread for a designated amount of time.
 * @param milliseconds Milliseconds to pause for.
 */
void AgentCluster::sleep(int milliseconds) {
    QMutex mut;
    mut.lock();
    mut.tryLock(milliseconds);
    mut.unlock();
}
Beispiel #24
0
//from http://jpassing.com/2008/03/12/walking-the-stack-of-the-current-thread/
//     http://www.codeproject.com/Articles/11132/Walking-the-callstack
//alternative: __builtin_return_address, but it is said to not work so well
QString getBacktrace(){
	if (!backtraceMutex.tryLock()) return "locked";
	
	//init crap
	HANDLE process =  GetCurrentProcess();
	HANDLE thread = GetCurrentThread();
	
	QStringList result(initDebugHelp());

	CONTEXT context;
	ZeroMemory( &context, sizeof( CONTEXT ) );
	STACKFRAME64 stackFrame;
#if (defined(x86_64) || defined(__x86_64__))
	RtlCaptureContext( &context );
#else
	// Those three registers are enough.
geteip:
	context.Eip = (DWORD)&&geteip;
	__asm__(
	"mov %%ebp, %0\n"
	"mov %%esp, %1"
	: "=r"(context.Ebp), "=r"(context.Esp));
#endif
	ZeroMemory( &stackFrame, sizeof( stackFrame ) );
#ifdef CPU_IS_64
	DWORD machineType           = IMAGE_FILE_MACHINE_AMD64;
	stackFrame.AddrPC.Offset    = context.Rip;
	stackFrame.AddrPC.Mode      = AddrModeFlat;
	stackFrame.AddrFrame.Offset = context.Rbp;//changed from rsp. correctly?
	stackFrame.AddrFrame.Mode   = AddrModeFlat;
	stackFrame.AddrStack.Offset = context.Rsp;
	stackFrame.AddrStack.Mode   = AddrModeFlat;
#else
	DWORD machineType           = IMAGE_FILE_MACHINE_I386;
	stackFrame.AddrPC.Offset    = context.Eip;
	stackFrame.AddrPC.Mode      = AddrModeFlat;
	stackFrame.AddrFrame.Offset = context.Ebp;
	stackFrame.AddrFrame.Mode   = AddrModeFlat;
	stackFrame.AddrStack.Offset = context.Esp;
	stackFrame.AddrStack.Mode   = AddrModeFlat;
	/* #elif _M_IA64
    MachineType                 = IMAGE_FILE_MACHINE_IA64;
    StackFrame.AddrPC.Offset    = Context.StIIP;
    StackFrame.AddrPC.Mode      = AddrModeFlat;
    StackFrame.AddrFrame.Offset = Context.IntSp;
    StackFrame.AddrFrame.Mode   = AddrModeFlat;
    StackFrame.AddrBStore.Offset= Context.RsBSP;
    StackFrame.AddrBStore.Mode  = AddrModeFlat;
    StackFrame.AddrStack.Offset = Context.IntSp;
    StackFrame.AddrStack.Mode   = AddrModeFlat;
  #else
    #error "Unsupported platform"*/
#endif
	
	static HMODULE dbghelp = LoadLibraryA("dbghelp.dll");
	if (!dbghelp) return "failed to load dbghelp.dll";

	LOAD_FUNCTIONREQ(StackWalk64, "StackWalk64");
	LOAD_FUNCTIONREQ(SymGetModuleBase64, "SymGetModuleBase64");
	LOAD_FUNCTIONREQ(SymFunctionTableAccess64, "SymFunctionTableAccess64");

	//get stackframes
	QList<DWORD64> stackFrames;
	while ((*StackWalk64)(machineType, process, thread, &stackFrame, &context, 0, SymFunctionTableAccess64, SymGetModuleBase64, 0))
		stackFrames << stackFrame.AddrPC.Offset;
	
	result << lookUpAddresses(stackFrames);

	backtraceMutex.unlock();
	
	return result.join("\r\n");
}
void tst_QMutex::lock_unlock_locked_tryLock()
{
    // normal mutex
    QMutex mutex;
    mutex_Thread thread(mutex);

    QMutex rmutex(QMutex::Recursive);
    rmutex_Thread rthread(rmutex);

    for (int i = 0; i < iterations; ++i) {
        // normal mutex
        QVERIFY(mutex.tryLock());
        mutex.unlock();

        thread.mutex.lock();
        thread.start();

        for (int j = 0; j < iterations; ++j) {
            QVERIFY(thread.cond.wait(&thread.mutex, 10000));
            QVERIFY(!mutex.tryLock());

            thread.cond.wakeOne();
        }

        thread.mutex.unlock();

        QVERIFY(thread.wait(10000));
        QVERIFY(mutex.tryLock());

        mutex.unlock();

        // recursive mutex
        QVERIFY(rmutex.tryLock());
        QVERIFY(rmutex.tryLock());
        QVERIFY(rmutex.tryLock());
        QVERIFY(rmutex.tryLock());

        rmutex.unlock();
        rmutex.unlock();
        rmutex.unlock();
        rmutex.unlock();

        rthread.mutex.lock();
        rthread.start();

        for (int k = 0; k < iterations; ++k) {
            QVERIFY(rthread.cond.wait(&rthread.mutex, 10000));
            QVERIFY(!rmutex.tryLock());

            rthread.cond.wakeOne();
        }

        rthread.mutex.unlock();

        QVERIFY(rthread.wait(10000));
        QVERIFY(rmutex.tryLock());
        QVERIFY(rmutex.tryLock());
        QVERIFY(rmutex.tryLock());
        QVERIFY(rmutex.tryLock());

        rmutex.unlock();
        rmutex.unlock();
        rmutex.unlock();
        rmutex.unlock();
    }
}
 MutexTryLocker(QMutex &m) : m_(m), locked_(m.tryLock()) {}