예제 #1
0
    bool wait(unsigned long time)
    {
        TInt err = KErrNone;
        if (time == ULONG_MAX) {
            // untimed wait, loop because RCondVar::Wait may return before the condition is triggered
            do {
                err = cond.Wait(mutex);
            } while (err == KErrNone && wakeups == 0);
        } else {
            unsigned long maxWait = KMaxTInt / 1000;
            QElapsedTimer waitTimer;
            do {
                waitTimer.start();
                unsigned long waitTime = qMin(maxWait, time);
                // wait at least 1ms, as 0 means no wait
                err = cond.TimedWait(mutex, qMax(1ul, waitTime) * 1000);
                // RCondVar::TimedWait may return before the condition is triggered, update the timeout with actual wait time
                time -= qMin((unsigned long)waitTimer.elapsed(), waitTime);
            } while ((err == KErrNone && wakeups == 0) || (err == KErrTimedOut && time > 0));
        }

        Q_ASSERT_X(waiters > 0, "QWaitCondition::wait", "internal error (waiters)");
        --waiters;
        if (err == KErrNone) {
            Q_ASSERT_X(wakeups > 0, "QWaitCondition::wait", "internal error (wakeups)");
            --wakeups;
        }

        mutex.Signal();

        if (err && err != KErrTimedOut)
            report_error(err, "QWaitCondition::wait()", "cv wait");
        return err == KErrNone;
    }
예제 #2
0
TInt Thread4(TAny* a)
{
    volatile TInt& count = *(volatile TInt*)a;
    TInt r = KErrNone;
    M2.Wait();
    while (r==KErrNone)
    {
        r = CV2.Wait(M2);
        ++count;
    }
    return r;
}
예제 #3
0
TInt Thread3(TAny* a)
{
    SThreadData2& d = *(SThreadData2*)a;
    RMutex m;
    RCondVar cv;
    TInt r = m.OpenGlobal(TPtrC(d.iMutexName), EOwnerThread);
    if (r!=KErrNone)
        return r;
    r = cv.OpenGlobal(TPtrC(d.iCondVarName), EOwnerThread);
    if (r!=KErrNone)
        return r;
    m.Wait();
    while (r==KErrNone)
    {
        r = cv.Wait(m);
        ++d.iInnerLoops;
    }
    return r;
}
예제 #4
0
TInt Thread0(TAny*)
{
    return CV1.Wait(M1);
}