VirtualBox

Changeset 85214 in vbox


Ignore:
Timestamp:
Jul 11, 2020 1:04:06 PM (4 years ago)
Author:
vboxsync
Message:

Main/ProcessImpl.cpp: Tweaked the waitForOperationCompletion and waitForCompletion loops a little. Fixed sign conversion warnings/errors for Clang 11. bugref:9790

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-all/ProgressImpl.cpp

    r82968 r85214  
    369369    }
    370370
    371     return notifyComplete(aResultCode, errorInfo);
     371    return notifyComplete((LONG)aResultCode, errorInfo);
    372372}
    373373
     
    413413    errorInfo->init(aResultCode, aIID, pcszComponent, text);
    414414
    415     return notifyComplete(aResultCode, errorInfo);
     415    return notifyComplete((LONG)aResultCode, errorInfo);
    416416}
    417417
     
    460460    errorInfo->initEx(aResultCode, vrc, aIID, pszComponent, text);
    461461
    462     return notifyComplete(aResultCode, errorInfo);
     462    return notifyComplete((LONG)aResultCode, errorInfo);
    463463}
    464464
     
    656656        return setError(E_FAIL, tr("Result code is not available, operation is still in progress"));
    657657
    658     *aResultCode = mResultCode;
     658    *aResultCode = (LONG)mResultCode;
    659659
    660660    return S_OK;
     
    766766
    767767    /* if we're already completed, take a shortcut */
    768     if (!mCompleted)
    769     {
    770         int vrc = VINF_SUCCESS;
    771         bool fForever = aTimeout < 0;
    772         int64_t timeLeft = aTimeout;
    773         int64_t lastTime = RTTimeMilliTS();
    774 
    775         while (!mCompleted && (fForever || timeLeft > 0))
     768    if (!mCompleted && aTimeout != 0)
     769    {
     770        RTMSINTERVAL cMsWait  = aTimeout < 0 ? RT_INDEFINITE_WAIT : (RTMSINTERVAL)aTimeout;
     771        uint64_t     msLast   = aTimeout < 0 ? 0                  : RTTimeMilliTS();
     772
     773        for (;;)
    776774        {
    777775            mWaitersCount++;
    778776            alock.release();
    779             vrc = RTSemEventMultiWait(mCompletedSem,
    780                                       fForever ? RT_INDEFINITE_WAIT : (RTMSINTERVAL)timeLeft);
     777            int vrc = RTSemEventMultiWait(mCompletedSem, cMsWait);
    781778            alock.acquire();
    782779            mWaitersCount--;
     
    787784
    788785            if (RT_FAILURE(vrc) && vrc != VERR_TIMEOUT)
     786                return setErrorBoth(VBOX_E_IPRT_ERROR, vrc, tr("Failed to wait for the task completion (%Rrc)"), vrc);
     787
     788            if (mCompleted)
    789789                break;
    790790
    791             if (!fForever)
     791            if (aTimeout >= 0)
    792792            {
    793                 int64_t now = RTTimeMilliTS();
    794                 timeLeft -= now - lastTime;
    795                 lastTime = now;
     793                uint64_t msNow = RTTimeMilliTS();
     794                uint64_t cMsElapsed = msNow - msLast;
     795                if (cMsWait <= cMsElapsed)
     796                    break;
     797                cMsWait -= (RTMSINTERVAL)cMsElapsed;
     798                msLast   = msNow;
    796799            }
    797800        }
    798 
    799         if (RT_FAILURE(vrc) && vrc != VERR_TIMEOUT)
    800             return setErrorBoth(VBOX_E_IPRT_ERROR, vrc, tr("Failed to wait for the task completion (%Rrc)"), vrc);
    801801    }
    802802
    803803    LogFlowThisFuncLeave();
    804 
    805804    return S_OK;
    806805}
     
    825824     * then take a shortcut */
    826825    if (    !mCompleted
    827          && aOperation >= m_ulCurrentOperation)
    828     {
    829         int vrc = VINF_SUCCESS;
    830         bool fForever = aTimeout < 0;
    831         int64_t timeLeft = aTimeout;
    832         int64_t lastTime = RTTimeMilliTS();
    833 
    834         while (    !mCompleted && aOperation >= m_ulCurrentOperation
    835                 && (fForever || timeLeft > 0))
     826         && aOperation >= m_ulCurrentOperation
     827         && aTimeout != 0)
     828    {
     829        RTMSINTERVAL cMsWait  = aTimeout < 0 ? RT_INDEFINITE_WAIT : (RTMSINTERVAL)aTimeout;
     830        uint64_t     msLast   = aTimeout < 0 ? 0                  : RTTimeMilliTS();
     831
     832        for (;;)
    836833        {
    837834            mWaitersCount ++;
    838835            alock.release();
    839             vrc = RTSemEventMultiWait(mCompletedSem,
    840                                       fForever ? RT_INDEFINITE_WAIT : (unsigned) timeLeft);
     836            int vrc = RTSemEventMultiWait(mCompletedSem, cMsWait);
    841837            alock.acquire();
    842838            mWaitersCount--;
     
    847843
    848844            if (RT_FAILURE(vrc) && vrc != VERR_TIMEOUT)
     845                return setErrorBoth(E_FAIL, vrc, tr("Failed to wait for the operation completion (%Rrc)"), vrc);
     846
     847            if (mCompleted || aOperation >= m_ulCurrentOperation)
    849848                break;
    850849
    851             if (!fForever)
     850            if (aTimeout >= 0)
    852851            {
    853                 int64_t now = RTTimeMilliTS();
    854                 timeLeft -= now - lastTime;
    855                 lastTime = now;
     852                uint64_t msNow = RTTimeMilliTS();
     853                uint64_t cMsElapsed = msNow - msLast;
     854                if (cMsWait <= cMsElapsed)
     855                    break;
     856                cMsWait -= (RTMSINTERVAL)cMsElapsed;
     857                msLast   = msNow;
    856858            }
    857859        }
    858 
    859         if (RT_FAILURE(vrc) && vrc != VERR_TIMEOUT)
    860             return setErrorBoth(E_FAIL, vrc, tr("Failed to wait for the operation completion (%Rrc)"), vrc);
    861860    }
    862861
    863862    LogFlowThisFuncLeave();
    864 
    865863    return S_OK;
    866864}
     
    913911        ULONG actualPercent = 0;
    914912        getPercent(&actualPercent);
    915         fireProgressPercentageChangedEvent(pEventSource, mId.toUtf16().raw(), actualPercent);
     913        fireProgressPercentageChangedEvent(pEventSource, mId.toUtf16().raw(), (LONG)actualPercent);
    916914    }
    917915
     
    10261024    rc = aProgressOther->COMGETTER(ResultCode)(&iRc);
    10271025    if (FAILED(rc)) return rc;
    1028     if (FAILED(iRc))
     1026    if (FAILED((HRESULT)iRc))
    10291027    {
    10301028        setError(ProgressErrorInfo(aProgressOther));
    1031         rc = iRc;
     1029        rc = (HRESULT)iRc;
    10321030    }
    10331031
     
    10701068    ULONG actualPercent = 0;
    10711069    getPercent(&actualPercent);
    1072     fireProgressPercentageChangedEvent(pEventSource, mId.toUtf16().raw(), actualPercent);
     1070    fireProgressPercentageChangedEvent(pEventSource, mId.toUtf16().raw(), (LONG)actualPercent);
    10731071
    10741072    return S_OK;
     
    11141112HRESULT Progress::notifyComplete(LONG aResultCode, const ComPtr<IVirtualBoxErrorInfo> &aErrorInfo)
    11151113{
    1116     LogThisFunc(("aResultCode=%d\n", aResultCode));
     1114    HRESULT hrcOperation = (HRESULT)aResultCode; /* XPCOM has an unsigned HRESULT, upsetting Clang 11 wrt sign conv. */
     1115    LogThisFunc(("hrcOperation=%Rhrc\n", hrcOperation));
    11171116    /* on failure we expect error info, on success there must be none */
    1118     AssertMsg(FAILED(aResultCode) ^ aErrorInfo.isNull(),
     1117    AssertMsg(FAILED(hrcOperation) ^ aErrorInfo.isNull(),
    11191118              ("No error info but trying to set a failed result (%08X)!\n",
    1120                aResultCode));
     1119               hrcOperation));
    11211120
    11221121    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    11241123    AssertReturn(mCompleted == FALSE, E_FAIL);
    11251124
    1126     if (mCanceled && SUCCEEDED(aResultCode))
    1127         aResultCode = E_FAIL;
     1125    if (mCanceled && SUCCEEDED(hrcOperation))
     1126        hrcOperation = E_FAIL;
    11281127
    11291128    mCompleted = TRUE;
    1130     mResultCode = aResultCode;
    1131     if (SUCCEEDED(aResultCode))
     1129    mResultCode = hrcOperation;
     1130    if (SUCCEEDED(hrcOperation))
    11321131    {
    11331132        m_ulCurrentOperation = m_cOperations - 1; /* last operation */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette