VirtualBox

Changeset 100213 in vbox for trunk


Ignore:
Timestamp:
Jun 19, 2023 4:13:40 PM (18 months ago)
Author:
vboxsync
Message:

Shared Clipboard: More code for locking transfers. bugref:9437

Location:
trunk/src/VBox/GuestHost/SharedClipboard
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-transfers-http.cpp

    r100204 r100213  
    100100*********************************************************************************************************************************/
    101101
     102/**
     103 * Locks an HTTP transfer.
     104 *
     105 * @param   pSrvTx              HTTP transfer to lock.
     106 */
    102107DECLINLINE(void) shClHttpTransferLock(PSHCLHTTPSERVERTRANSFER pSrvTx)
    103108{
     
    106111}
    107112
     113/**
     114 * Unlocks an HTTP transfer.
     115 *
     116 * @param   pSrvTx              HTTP transfer to unlock.
     117 */
    108118DECLINLINE(void) shClHttpTransferUnlock(PSHCLHTTPSERVERTRANSFER pSrvTx)
    109119{
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-transfers.cpp

    r100205 r100213  
    5050
    5151
     52/*********************************************************************************************************************************
     53 * Transfer List                                                                                                                 *
     54 ********************************************************************************************************************************/
     55
    5256/**
    5357 * Initializes a transfer list.
     
    675679    return true;
    676680}
     681
     682
     683/*********************************************************************************************************************************
     684 * Transfer Object                                                                                                               *
     685 ********************************************************************************************************************************/
    677686
    678687/**
     
    10271036}
    10281037
     1038
     1039/*********************************************************************************************************************************
     1040 * Transfer                                                                                                                      *
     1041 ********************************************************************************************************************************/
     1042
    10291043/**
    10301044 * Creates a clipboard transfer, extended version.
     
    11361150    ShClTransferReset(pTransfer);
    11371151
     1152    if (RTCritSectIsInitialized(&pTransfer->CritSect))
     1153        RTCritSectDelete(&pTransfer->CritSect);
     1154
    11381155    ShClEventSourceDestroy(&pTransfer->Events);
    11391156
     
    11761193    pTransfer->CallbackCtx.cbUser    = pTransfer->Callbacks.cbUser;
    11771194
    1178     int rc = VINF_SUCCESS;
    1179 
    1180     LogRelFunc(("pfnOnInitialized=%p\n", pTransfer->Callbacks.pfnOnInitialized));
     1195    int rc = RTCritSectInit(&pTransfer->CritSect);
     1196    AssertRCReturn(rc, rc);
    11811197
    11821198    if (pTransfer->Callbacks.pfnOnInitialized)
     
    11901206    LogFlowFuncLeaveRC(rc);
    11911207    return rc;
     1208}
     1209
     1210/**
     1211 * Locks a transfer.
     1212 *
     1213 * @param   pTransfer           Transfer to lock.
     1214 */
     1215DECLINLINE(void) shClTransferLock(PSHCLTRANSFER pTransfer)
     1216{
     1217    int rc2 = RTCritSectEnter(&pTransfer->CritSect);
     1218    AssertRC(rc2);
     1219}
     1220
     1221/**
     1222 * Unlocks a transfer.
     1223 *
     1224 * @param   pTransfer           Transfer to unlock.
     1225 */
     1226DECLINLINE(void) shClTransferUnlock(PSHCLTRANSFER pTransfer)
     1227{
     1228    int rc2 = RTCritSectLeave(&pTransfer->CritSect);
     1229    AssertRC(rc2);
    11921230}
    11931231
     
    14991537    AssertPtrReturn(pTransfer, 0);
    15001538
    1501     LogFlowFunc(("[Transfer %RU32] cRoots=%RU64\n", pTransfer->State.uID, pTransfer->lstRoots.Hdr.cEntries));
    1502     return (uint32_t)pTransfer->lstRoots.Hdr.cEntries;
     1539    shClTransferLock(pTransfer);
     1540
     1541    uint32_t const cRoots = pTransfer->lstRoots.Hdr.cEntries;
     1542
     1543    shClTransferUnlock(pTransfer);
     1544
     1545    return cRoots;
    15031546}
    15041547
     
    15071550 *
    15081551 * @param   pTransfer           Transfer to clear transfer root list for.
     1552 *
     1553 * @note    Caller needs to take critical section.
    15091554 */
    15101555static void shClTransferRootsReset(PSHCLTRANSFER pTransfer)
    15111556{
    15121557    AssertPtrReturnVoid(pTransfer);
     1558    Assert(RTCritSectIsOwner(&pTransfer->CritSect));
    15131559
    15141560    if (pTransfer->pszPathRootAbs)
     
    15321578    LogFlowFuncEnter();
    15331579
     1580    shClTransferLock(pTransfer);
     1581
    15341582    shClTransferRootsReset(pTransfer);
    15351583
     
    15531601        RTMemFree(pItObj);
    15541602    }
     1603
     1604    shClTransferUnlock(pTransfer);
    15551605}
    15561606
     
    15661616    AssertPtrReturn(pTransfer, NULL);
    15671617
     1618    shClTransferLock(pTransfer);
     1619
    15681620    if (uIndex >= pTransfer->lstRoots.Hdr.cEntries)
     1621    {
     1622        shClTransferUnlock(pTransfer);
    15691623        return NULL;
    1570 
    1571     return shClTransferListGetEntryById(&pTransfer->lstRoots, uIndex);
     1624    }
     1625
     1626    PCSHCLLISTENTRY pEntry = shClTransferListGetEntryById(&pTransfer->lstRoots, uIndex);
     1627
     1628    shClTransferUnlock(pTransfer);
     1629
     1630    return pEntry;
    15721631}
    15731632
     
    15921651        rc = VERR_NOT_SUPPORTED;
    15931652
     1653    shClTransferLock(pTransfer);
     1654
    15941655    /* Make sure that we have at least an empty root path set. */
    15951656    if (   RT_SUCCESS(rc)
     
    15991660            rc = VERR_NO_MEMORY;
    16001661    }
     1662
     1663    shClTransferUnlock(pTransfer);
    16011664
    16021665    LogFlowFuncLeaveRC(rc);
     
    16281691    int rc = VINF_SUCCESS;
    16291692
     1693    shClTransferLock(pTransfer);
     1694
    16301695    shClTransferRootsReset(pTransfer);
    16311696
     
    16351700    RTCList<RTCString> lstRootEntries = RTCString(pszRoots, cbRoots - 1).split(SHCL_TRANSFER_URI_LIST_SEP_STR);
    16361701    if (!lstRootEntries.size())
     1702    {
     1703        shClTransferUnlock(pTransfer);
    16371704        return VINF_SUCCESS;
     1705    }
    16381706
    16391707    for (size_t i = 0; i < lstRootEntries.size(); ++i)
     
    17561824    }
    17571825
     1826    shClTransferUnlock(pTransfer);
     1827
    17581828    LogFlowFuncLeaveRC(rc);
    17591829    return rc;
     
    17941864    AssertPtrReturn(pTransfer, 0);
    17951865
    1796     return pTransfer->State.uID;
     1866    shClTransferLock(pTransfer);
     1867
     1868    SHCLTRANSFERID const uID = pTransfer->State.uID;
     1869
     1870    shClTransferUnlock(pTransfer);
     1871
     1872    return uID;
    17971873}
    17981874
     
    18071883    AssertPtrReturn(pTransfer, SHCLTRANSFERDIR_UNKNOWN);
    18081884
    1809     LogFlowFunc(("[Transfer %RU32] enmDir=%RU32\n", pTransfer->State.uID, pTransfer->State.enmDir));
    1810     return pTransfer->State.enmDir;
     1885    shClTransferLock(pTransfer);
     1886
     1887    SHCLTRANSFERDIR const enmDir = pTransfer->State.enmDir;
     1888
     1889    shClTransferUnlock(pTransfer);
     1890
     1891    return enmDir;
    18111892}
    18121893
     
    18221903{
    18231904    AssertPtrReturn(pTransfer, VERR_INVALID_POINTER);
     1905
     1906    shClTransferLock(pTransfer);
     1907
    18241908    AssertMsgReturn(pTransfer->pszPathRootAbs, ("Transfer has no root path set (yet)\n"), VERR_WRONG_ORDER);
    18251909
    1826     return RTStrCopy(pszPath, cbPath, pTransfer->pszPathRootAbs);
     1910    int const rc = RTStrCopy(pszPath, cbPath, pTransfer->pszPathRootAbs);
     1911
     1912    shClTransferUnlock(pTransfer);
     1913
     1914    return rc;
    18271915}
    18281916
     
    18371925    AssertPtrReturn(pTransfer, SHCLSOURCE_INVALID);
    18381926
    1839     LogFlowFunc(("[Transfer %RU32] enmSource=%RU32\n", pTransfer->State.uID, pTransfer->State.enmSource));
    1840     return pTransfer->State.enmSource;
     1927    shClTransferLock(pTransfer);
     1928
     1929    SHCLSOURCE const enmSource = pTransfer->State.enmSource;
     1930
     1931    shClTransferUnlock(pTransfer);
     1932
     1933    return enmSource;
    18411934}
    18421935
     
    18461939 * @returns Current transfer status.
    18471940 * @param   pTransfer           Clipboard transfer to return status for.
     1941 *
     1942 * @note    Caller needs to take critical section.
     1943 */
     1944DECLINLINE(SHCLTRANSFERSTATUS) shClTransferGetStatusLocked(PSHCLTRANSFER pTransfer)
     1945{
     1946    Assert(RTCritSectIsOwner(&pTransfer->CritSect));
     1947
     1948    shClTransferLock(pTransfer);
     1949
     1950    SHCLTRANSFERSTATUS const enmStatus = pTransfer->State.enmStatus;
     1951
     1952    shClTransferUnlock(pTransfer);
     1953
     1954    return enmStatus;
     1955}
     1956
     1957/**
     1958 * Returns the current transfer status.
     1959 *
     1960 * @returns Current transfer status.
     1961 * @param   pTransfer           Clipboard transfer to return status for.
    18481962 */
    18491963SHCLTRANSFERSTATUS ShClTransferGetStatus(PSHCLTRANSFER pTransfer)
     
    18511965    AssertPtrReturn(pTransfer, SHCLTRANSFERSTATUS_NONE);
    18521966
    1853     return pTransfer->State.enmStatus;
     1967    shClTransferLock(pTransfer);
     1968
     1969    SHCLTRANSFERSTATUS const enmSts = shClTransferGetStatusLocked(pTransfer);
     1970
     1971    shClTransferUnlock(pTransfer);
     1972
     1973    return enmSts;
    18541974}
    18551975
     
    18892009
    18902010    LogFlowFuncEnter();
     2011
     2012    shClTransferLock(pTransfer);
    18912013
    18922014    /* Ready to start? */
     
    19022024    pTransfer->State.enmStatus = SHCLTRANSFERSTATUS_STARTED;
    19032025
     2026    shClTransferUnlock(pTransfer);
     2027
    19042028    if (pTransfer->Callbacks.pfnOnStarted)
    19052029        pTransfer->Callbacks.pfnOnStarted(&pTransfer->CallbackCtx);
     
    19212045{
    19222046    AssertPtrReturn(pTransfer, VERR_INVALID_POINTER);
     2047
     2048    shClTransferLock(pTransfer);
    19232049
    19242050    /* Already marked for stopping? */
     
    19352061    if (RT_SUCCESS(rc))
    19362062    {
     2063        shClTransferUnlock(pTransfer); /* Leave lock while waiting. */
     2064
    19372065        int rc2 = RTThreadUserWait(pTransfer->Thread.hThread, RT_MS_30SEC /* Timeout in ms */);
    19382066        AssertRC(rc2);
     2067
     2068        shClTransferLock(pTransfer);
    19392069
    19402070        if (pTransfer->Thread.fStarted) /* Did the thread indicate that it started correctly? */
     
    19462076    }
    19472077
     2078    shClTransferUnlock(pTransfer);
     2079
    19482080    LogFlowFuncLeaveRC(rc);
    19492081    return rc;
     
    19612093    AssertPtrReturn(pTransfer, VERR_INVALID_POINTER);
    19622094
     2095    shClTransferLock(pTransfer);
     2096
    19632097    if (pTransfer->Thread.hThread == NIL_RTTHREAD)
     2098    {
     2099        shClTransferUnlock(pTransfer);
    19642100        return VINF_SUCCESS;
     2101    }
    19652102
    19662103    LogFlowFuncEnter();
     
    19692106    pTransfer->Thread.fStop = true;
    19702107
     2108    shClTransferUnlock(pTransfer); /* Leave lock while waiting. */
     2109
    19712110    int rcThread = VERR_WRONG_ORDER;
    19722111    int rc = RTThreadWait(pTransfer->Thread.hThread, uTimeoutMs, &rcThread);
     
    19752114
    19762115    return rc;
     2116}
     2117
     2118
     2119/*********************************************************************************************************************************
     2120 * Transfer Context                                                                                                              *
     2121 ********************************************************************************************************************************/
     2122
     2123/**
     2124 * Locks a transfer context.
     2125 *
     2126 * @param   pTransferCtx        Transfer context to lock.
     2127 */
     2128DECLINLINE(void) shClTransferCtxLock(PSHCLTRANSFERCTX pTransferCtx)
     2129{
     2130    int rc2 = RTCritSectEnter(&pTransferCtx->CritSect);
     2131    AssertRC(rc2);
     2132}
     2133
     2134/**
     2135 * Unlocks a transfer context.
     2136 *
     2137 * @param   pTransferCtx        Transfer context to unlock.
     2138 */
     2139DECLINLINE(void) shClTransferCtxUnlock(PSHCLTRANSFERCTX pTransferCtx)
     2140{
     2141    int rc2 = RTCritSectLeave(&pTransferCtx->CritSect);
     2142    AssertRC(rc2);
    19772143}
    19782144
     
    20182184    LogFlowFunc(("pTransferCtx=%p\n", pTransferCtx));
    20192185
     2186    shClTransferCtxLock(pTransferCtx);
     2187
     2188    PSHCLTRANSFER pTransfer, pTransferNext;
     2189    RTListForEachSafe(&pTransferCtx->List, pTransfer, pTransferNext, SHCLTRANSFER, Node)
     2190    {
     2191        ShClTransferDestroy(pTransfer);
     2192
     2193        shclTransferCtxTransferRemoveAndUnregister(pTransferCtx, pTransfer);
     2194
     2195        RTMemFree(pTransfer);
     2196        pTransfer = NULL;
     2197    }
     2198
     2199    pTransferCtx->cRunning   = 0;
     2200    pTransferCtx->cTransfers = 0;
     2201
     2202    shClTransferCtxUnlock(pTransferCtx);
     2203
    20202204    if (RTCritSectIsInitialized(&pTransferCtx->CritSect))
    20212205        RTCritSectDelete(&pTransferCtx->CritSect);
    2022 
    2023     PSHCLTRANSFER pTransfer, pTransferNext;
    2024     RTListForEachSafe(&pTransferCtx->List, pTransfer, pTransferNext, SHCLTRANSFER, Node)
    2025     {
    2026         ShClTransferDestroy(pTransfer);
    2027 
    2028         shclTransferCtxTransferRemoveAndUnregister(pTransferCtx, pTransfer);
    2029 
    2030         RTMemFree(pTransfer);
    2031         pTransfer = NULL;
    2032     }
    2033 
    2034     pTransferCtx->cRunning   = 0;
    2035     pTransferCtx->cTransfers = 0;
    20362206}
    20372207
     
    20442214{
    20452215    AssertPtrReturnVoid(pTransferCtx);
     2216
     2217    shClTransferCtxLock(pTransferCtx);
    20462218
    20472219    LogFlowFuncEnter();
     
    20542226    /** @todo Anything to do here? */
    20552227#endif
     2228
     2229    shClTransferCtxUnlock(pTransferCtx);
    20562230}
    20572231
     
    20622236 * @param   pTransferCtx                Transfer context to return transfer for.
    20632237 * @param   uID                         ID of the transfer to return.
     2238 *
     2239 * @note    Caller needs to take critical section.
    20642240 */
    20652241static PSHCLTRANSFER shClTransferCtxGetTransferByIdInternal(PSHCLTRANSFERCTX pTransferCtx, uint32_t uID)
    20662242{
     2243    Assert(RTCritSectIsOwner(&pTransferCtx->CritSect));
     2244
    20672245    PSHCLTRANSFER pTransfer;
    20682246    RTListForEach(&pTransferCtx->List, pTransfer, SHCLTRANSFER, Node) /** @todo Slow, but works for now. */
     
    20812259 * @param   pTransferCtx                Transfer context to return transfer for.
    20822260 * @param   uIdx                        Index of the transfer to return.
     2261 *
     2262 * @note    Caller needs to take critical section.
    20832263 */
    20842264static PSHCLTRANSFER shClTransferCtxGetTransferByIndexInternal(PSHCLTRANSFERCTX pTransferCtx, uint32_t uIdx)
    20852265{
     2266    Assert(RTCritSectIsOwner(&pTransferCtx->CritSect));
     2267
    20862268    uint32_t idx = 0;
    20872269
     
    21062288PSHCLTRANSFER ShClTransferCtxGetTransferById(PSHCLTRANSFERCTX pTransferCtx, uint32_t uID)
    21072289{
    2108     return shClTransferCtxGetTransferByIdInternal(pTransferCtx, uID);
     2290    shClTransferCtxLock(pTransferCtx);
     2291
     2292    PSHCLTRANSFER const pTransfer = shClTransferCtxGetTransferByIdInternal(pTransferCtx, uID);
     2293
     2294    shClTransferCtxUnlock(pTransferCtx);
     2295
     2296    return pTransfer;
    21092297}
    21102298
     
    21182306PSHCLTRANSFER ShClTransferCtxGetTransferByIndex(PSHCLTRANSFERCTX pTransferCtx, uint32_t uIdx)
    21192307{
    2120     return shClTransferCtxGetTransferByIndexInternal(pTransferCtx, uIdx);
     2308    shClTransferCtxLock(pTransferCtx);
     2309
     2310    PSHCLTRANSFER const pTransfer = shClTransferCtxGetTransferByIndexInternal(pTransferCtx, uIdx);
     2311
     2312    shClTransferCtxUnlock(pTransferCtx);
     2313
     2314    return pTransfer;
    21212315}
    21222316
     
    21302324{
    21312325    AssertPtrReturn(pTransferCtx, 0);
    2132     return pTransferCtx->cRunning;
     2326
     2327    shClTransferCtxLock(pTransferCtx);
     2328
     2329    uint32_t const cRunning = pTransferCtx->cRunning;
     2330
     2331    shClTransferCtxUnlock(pTransferCtx);
     2332
     2333    return cRunning;
    21332334}
    21342335
     
    21422343{
    21432344    AssertPtrReturn(pTransferCtx, 0);
    2144     return pTransferCtx->cTransfers;
     2345
     2346    shClTransferCtxLock(pTransferCtx);
     2347
     2348    uint32_t const cTransfers = pTransferCtx->cTransfers;
     2349
     2350    shClTransferCtxUnlock(pTransferCtx);
     2351
     2352    return cTransfers;
    21452353}
    21462354
     
    21602368    AssertPtrReturn(pTransfer, VERR_INVALID_POINTER);
    21612369    /* pidTransfer is optional. */
     2370
     2371    shClTransferCtxLock(pTransferCtx);
    21622372
    21632373    /*
     
    21832393    {
    21842394        LogFunc(("Maximum number of transfers reached (%RU16 transfers)\n", pTransferCtx->cTransfers));
     2395        shClTransferCtxUnlock(pTransferCtx);
    21852396        return VERR_SHCLPB_MAX_TRANSFERS_REACHED;
    21862397    }
     
    21932404
    21942405    Log2Func(("pTransfer=%p, idTransfer=%RU32 -- now %RU16 transfer(s)\n", pTransfer, idTransfer, pTransferCtx->cTransfers));
     2406
     2407    shClTransferCtxUnlock(pTransferCtx);
    21952408
    21962409    if (pTransfer->Callbacks.pfnOnRegistered)
     
    22162429int ShClTransferCtxTransferRegisterById(PSHCLTRANSFERCTX pTransferCtx, PSHCLTRANSFER pTransfer, SHCLTRANSFERID idTransfer)
    22172430{
    2218     LogFlowFunc(("cTransfers=%RU16, idTransfer=%RU32\n", pTransferCtx->cTransfers, idTransfer));
     2431    shClTransferCtxLock(pTransferCtx);
    22192432
    22202433    if (pTransferCtx->cTransfers < VBOX_SHCL_MAX_TRANSFERS - 2 /* First and last are not used */)
     
    22262439            pTransfer->State.uID = idTransfer;
    22272440
     2441            shClTransferCtxUnlock(pTransferCtx);
     2442
    22282443            if (pTransfer->Callbacks.pfnOnRegistered)
    22292444                pTransfer->Callbacks.pfnOnRegistered(&pTransfer->CallbackCtx, pTransferCtx);
    22302445
     2446            shClTransferCtxLock(pTransferCtx);
     2447
    22312448            pTransferCtx->cTransfers++;
     2449
     2450            LogFunc(("Registered transfer ID %RU16 -- now %RU16 transfers total\n", idTransfer, pTransferCtx->cTransfers));
     2451
     2452            shClTransferCtxUnlock(pTransferCtx);
    22322453            return VINF_SUCCESS;
    22332454        }
     
    22372458
    22382459    LogFunc(("Maximum number of transfers reached (%RU16 transfers)\n", pTransferCtx->cTransfers));
     2460
     2461    shClTransferCtxUnlock(pTransferCtx);
     2462
    22392463    return VERR_SHCLPB_MAX_TRANSFERS_REACHED;
    22402464}
     
    22452469 * @param   pTransferCtx        Transfer context to remove transfer from.
    22462470 * @param   pTransfer           Transfer to remove.
     2471 *
     2472 * @note    Caller needs to take critical section.
    22472473 */
    22482474static void shclTransferCtxTransferRemoveAndUnregister(PSHCLTRANSFERCTX pTransferCtx, PSHCLTRANSFER pTransfer)
    22492475{
     2476    Assert(RTCritSectIsOwner(&pTransferCtx->CritSect));
     2477
    22502478    RTListNodeRemove(&pTransfer->Node);
    22512479
     
    22552483    Assert(pTransferCtx->cTransfers >= pTransferCtx->cRunning);
    22562484
     2485    shClTransferCtxUnlock(pTransferCtx);
     2486
    22572487    if (pTransfer->Callbacks.pfnOnUnregistered)
    22582488        pTransfer->Callbacks.pfnOnUnregistered(&pTransfer->CallbackCtx, pTransferCtx);
     2489
     2490    shClTransferCtxLock(pTransferCtx);
    22592491
    22602492    LogFlowFunc(("Now %RU32 transfers left\n", pTransferCtx->cTransfers));
     
    22712503int ShClTransferCtxTransferUnregister(PSHCLTRANSFERCTX pTransferCtx, SHCLTRANSFERID idTransfer)
    22722504{
     2505    AssertPtrReturn(pTransferCtx, VERR_INVALID_POINTER);
     2506    AssertReturn(idTransfer, VERR_INVALID_PARAMETER);
     2507
     2508    shClTransferCtxLock(pTransferCtx);
     2509
    22732510    int rc = VINF_SUCCESS;
    22742511    AssertMsgStmt(ASMBitTestAndClear(&pTransferCtx->bmTransferIds, idTransfer), ("idTransfer=%#x\n", idTransfer), rc = VERR_NOT_FOUND);
     
    22762513    LogFlowFunc(("idTransfer=%RU32\n", idTransfer));
    22772514
    2278     PSHCLTRANSFER pTransfer = shClTransferCtxGetTransferByIdInternal(pTransferCtx, idTransfer);
    2279     if (pTransfer)
    2280     {
    2281         shclTransferCtxTransferRemoveAndUnregister(pTransferCtx, pTransfer);
    2282     }
    2283     else
    2284         rc = VERR_NOT_FOUND;
     2515    if (RT_SUCCESS(rc))
     2516    {
     2517        PSHCLTRANSFER pTransfer = shClTransferCtxGetTransferByIdInternal(pTransferCtx, idTransfer);
     2518        if (pTransfer)
     2519        {
     2520            shclTransferCtxTransferRemoveAndUnregister(pTransferCtx, pTransfer);
     2521        }
     2522        else
     2523            rc = VERR_NOT_FOUND;
     2524    }
     2525
     2526    shClTransferCtxUnlock(pTransferCtx);
    22852527
    22862528    LogFlowFuncLeaveRC(rc);
     
    22982540    AssertPtrReturnVoid(pTransferCtx);
    22992541
     2542    shClTransferCtxLock(pTransferCtx);
     2543
    23002544    LogFlowFunc(("pTransferCtx=%p, cTransfers=%RU16 cRunning=%RU16\n",
    23012545                 pTransferCtx, pTransferCtx->cTransfers, pTransferCtx->cRunning));
    23022546
    23032547    if (pTransferCtx->cTransfers == 0)
     2548    {
     2549        shClTransferCtxUnlock(pTransferCtx);
    23042550        return;
     2551    }
    23052552
    23062553    /* Remove all transfers which are not in a running state (e.g. only announced). */
     
    23082555    RTListForEachSafe(&pTransferCtx->List, pTransfer, pTransferNext, SHCLTRANSFER, Node)
    23092556    {
    2310         if (ShClTransferGetStatus(pTransfer) != SHCLTRANSFERSTATUS_STARTED)
     2557        shClTransferLock(pTransfer);
     2558
     2559        SHCLTRANSFERSTATUS const enmStatus = shClTransferGetStatusLocked(pTransfer);
     2560        LogFlowFunc(("\tTransfer #%RU16: %s\n", pTransfer->State.uID, ShClTransferStatusToStr(enmStatus)));
     2561
     2562        if (enmStatus != SHCLTRANSFERSTATUS_STARTED)
    23112563        {
    23122564            shclTransferCtxTransferRemoveAndUnregister(pTransferCtx, pTransfer);
     2565
     2566            shClTransferUnlock(pTransfer);
    23132567
    23142568            ShClTransferDestroy(pTransfer);
     
    23172571            pTransfer = NULL;
    23182572        }
    2319     }
     2573        else
     2574            shClTransferUnlock(pTransfer);
     2575    }
     2576
     2577    shClTransferCtxUnlock(pTransferCtx);
    23202578}
    23212579
     
    23302588    AssertPtrReturn(pTransferCtx, true);
    23312589
     2590    shClTransferCtxLock(pTransferCtx);
     2591
    23322592    LogFlowFunc(("cRunning=%RU32, cMaxRunning=%RU32\n", pTransferCtx->cRunning, pTransferCtx->cMaxRunning));
    23332593
    23342594    Assert(pTransferCtx->cRunning <= pTransferCtx->cMaxRunning);
    2335     return pTransferCtx->cRunning == pTransferCtx->cMaxRunning;
     2595    bool const fMaximumReached = pTransferCtx->cRunning == pTransferCtx->cMaxRunning;
     2596
     2597    shClTransferCtxUnlock(pTransferCtx);
     2598
     2599    return fMaximumReached;
    23362600}
    23372601
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