VirtualBox

Changeset 34030 in vbox for trunk/src/VBox/Runtime/common


Ignore:
Timestamp:
Nov 12, 2010 2:37:32 PM (14 years ago)
Author:
vboxsync
Message:

vfs: lock cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/vfs/vfsbase.cpp

    r34029 r34030  
    760760
    761761/**
    762  * Write locks the object.
    763  *
    764  * @param   pThis               The object to lock.
    765  */
    766 DECLINLINE(void) rtVfsObjWriteLock(RTVFSOBJINTERNAL *pThis)
    767 {
    768     RTVfsLockAcquireWrite(pThis->hLock);
    769 }
    770 
    771 
    772 /**
    773  * Undoing the effects of rtVfsObjWriteLock.
    774  *
    775  * @param   pThis               The object to lock.
    776  */
    777 DECLINLINE(void) rtVfsObjWriteUnlock(RTVFSOBJINTERNAL *pThis)
    778 {
    779     RTVfsLockReleaseWrite(pThis->hLock);
    780 }
    781 
    782 /**
    783  * Read locks the object.
    784  *
    785  * @param   pThis               The object to lock.
    786  */
    787 DECLINLINE(void) rtVfsObjReadLock(RTVFSOBJINTERNAL *pThis)
    788 {
    789     RTVfsLockAcquireRead(pThis->hLock);
    790 }
    791 
    792 
    793 /**
    794  * Undoing the effects of rtVfsObjReadLock.
    795  *
    796  * @param   pThis               The object to lock.
    797  */
    798 DECLINLINE(void) rtVfsObjReadUnlock(RTVFSOBJINTERNAL *pThis)
    799 {
    800     RTVfsLockReleaseRead(pThis->hLock);
    801 }
    802 
    803 
    804 
    805 /**
    806762 * Internal object retainer that asserts sanity in strict builds.
    807763 *
     
    840796     * Invalidate the object.
    841797     */
    842     rtVfsObjWriteLock(pThis);           /* paranoia */
     798    RTVfsLockAcquireWrite(pThis->hLock);    /* paranoia */
    843799    void *pvToFree = NULL;
    844800    switch (enmType)
     
    887843    }
    888844    ASMAtomicWriteU32(&pThis->uMagic, RTVFSOBJ_MAGIC_DEAD);
    889     rtVfsObjWriteUnlock(pThis);
     845    RTVfsLockReleaseWrite(pThis->hLock);
    890846
    891847    /*
     
    11281084    AssertReturn(pThis->uMagic == RTVFSOBJ_MAGIC, VERR_INVALID_HANDLE);
    11291085
    1130     rtVfsObjReadLock(pThis);
     1086    RTVfsLockAcquireRead(pThis->hLock);
    11311087    int rc = pThis->pOps->pfnQueryInfo(pThis->pvThis, pObjInfo, enmAddAttr);
    1132     rtVfsObjReadUnlock(pThis);
     1088    RTVfsLockReleaseRead(pThis->hLock);
    11331089    return rc;
    11341090}
     
    14121368    /** @todo Union mounts, traversal optimization methods, races, ++ */
    14131369    RTVFSDIRINTERNAL *pCurDir;
    1414     rtVfsObjReadLock(&pThis->Base);
     1370    RTVfsLockAcquireRead(pThis->Base.hLock);
    14151371    int rc = pThis->pOps->pfnOpenRoot(pThis->Base.pvThis, &pCurDir);
    1416     rtVfsObjReadUnlock(&pThis->Base);
     1372    RTVfsLockReleaseRead(pThis->Base.hLock);
    14171373    if (RT_FAILURE(rc))
    14181374        return rc;
     
    14471403        if (fFinal)
    14481404        {
    1449             rtVfsObjReadLock(&pCurDir->Base);
     1405            RTVfsLockAcquireRead(pCurDir->Base.hLock);
    14501406            rc = pCurDir->pOps->pfnTraversalOpen(pCurDir->Base.pvThis, pszEntry, NULL, &hSymlink, NULL);
    1451             rtVfsObjReadUnlock(&pCurDir->Base);
     1407            RTVfsLockReleaseRead(pCurDir->Base.hLock);
    14521408            *pszEntryEnd = '\0';
    14531409            if (rc == VERR_PATH_NOT_FOUND)
     
    14641420        else
    14651421        {
    1466             rtVfsObjReadLock(&pCurDir->Base);
     1422            RTVfsLockAcquireRead(pCurDir->Base.hLock);
    14671423            rc = pCurDir->pOps->pfnTraversalOpen(pCurDir->Base.pvThis, pszEntry, &hDir, &hSymlink, &hVfsMnt);
    1468             rtVfsObjReadUnlock(&pCurDir->Base);
     1424            RTVfsLockReleaseRead(pCurDir->Base.hLock);
    14691425            *pszEntryEnd = '/';
    14701426            if (RT_FAILURE(rc))
     
    15151471                /* Must restart from the root (optimize this). */
    15161472                RTVfsDirRelease(pCurDir);
    1517                 rtVfsObjReadLock(&pThis->Base);
     1473                RTVfsLockAcquireRead(pThis->Base.hLock);
    15181474                rc = pThis->pOps->pfnOpenRoot(pThis->Base.pvThis, &pCurDir);
    1519                 rtVfsObjReadUnlock(&pThis->Base);
     1475                RTVfsLockReleaseRead(pThis->Base.hLock);
    15201476                if (RT_FAILURE(rc))
    15211477                {
     
    15321488             */
    15331489            RTVfsDirRelease(pCurDir);
    1534             rtVfsObjReadLock(&hVfsMnt->Base);
     1490            RTVfsLockAcquireRead(hVfsMnt->Base.hLock);
    15351491            rc = pThis->pOps->pfnOpenRoot(hVfsMnt->Base.pvThis, &pCurDir);
    1536             rtVfsObjReadUnlock(&hVfsMnt->Base);
     1492            RTVfsLockReleaseRead(hVfsMnt->Base.hLock);
    15371493            if (RT_FAILURE(rc))
    15381494            {
     
    17581714    AssertReturn(pThis->uMagic == RTVFSSYMLINK_MAGIC, VERR_INVALID_HANDLE);
    17591715
    1760     rtVfsObjWriteLock(&pThis->Base);
     1716    RTVfsLockAcquireWrite(pThis->Base.hLock);
    17611717    int rc = pThis->pOps->pfnRead(pThis->Base.pvThis, pszTarget, cbTarget);
    1762     rtVfsObjWriteUnlock(&pThis->Base);
     1718    RTVfsLockReleaseWrite(pThis->Base.hLock);
    17631719
    17641720    return rc;
     
    18771833    RTSgBufInit(&SgBuf, &Seg, 1);
    18781834
    1879     rtVfsObjWriteLock(&pThis->Base);
     1835    RTVfsLockAcquireWrite(pThis->Base.hLock);
    18801836    int rc = pThis->pOps->pfnRead(pThis->Base.pvThis, -1 /*off*/, &SgBuf, fBlocking, pcbRead);
    1881     rtVfsObjWriteUnlock(&pThis->Base);
     1837    RTVfsLockReleaseWrite(pThis->Base.hLock);
    18821838    return rc;
    18831839}
     
    18981854    RTSgBufInit(&SgBuf, &Seg, 1);
    18991855
    1900     rtVfsObjWriteLock(&pThis->Base);
     1856    RTVfsLockAcquireWrite(pThis->Base.hLock);
    19011857    int rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, -1 /*off*/, &SgBuf, fBlocking, pcbWritten);
    1902     rtVfsObjWriteUnlock(&pThis->Base);
     1858    RTVfsLockReleaseWrite(pThis->Base.hLock);
    19031859    return rc;
    19041860}
     
    19161872    AssertReturn(fBlocking || pcbRead, VERR_INVALID_PARAMETER);
    19171873
    1918     rtVfsObjWriteLock(&pThis->Base);
     1874    RTVfsLockAcquireWrite(pThis->Base.hLock);
    19191875    int rc = pThis->pOps->pfnRead(pThis->Base.pvThis, -1 /*off*/, pSgBuf, fBlocking, pcbRead);
    1920     rtVfsObjWriteUnlock(&pThis->Base);
     1876    RTVfsLockReleaseWrite(pThis->Base.hLock);
    19211877    return rc;
    19221878}
     
    19341890    AssertReturn(fBlocking || pcbWritten, VERR_INVALID_PARAMETER);
    19351891
    1936     rtVfsObjWriteLock(&pThis->Base);
     1892    RTVfsLockAcquireWrite(pThis->Base.hLock);
    19371893    int rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, -1 /*off*/, pSgBuf, fBlocking, pcbWritten);
    1938     rtVfsObjWriteUnlock(&pThis->Base);
     1894    RTVfsLockReleaseWrite(pThis->Base.hLock);
    19391895    return rc;
    19401896}
     
    19471903    AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, VERR_INVALID_HANDLE);
    19481904
    1949     rtVfsObjWriteLock(&pThis->Base);
     1905    RTVfsLockAcquireWrite(pThis->Base.hLock);
    19501906    int rc = pThis->pOps->pfnFlush(pThis->Base.pvThis);
    1951     rtVfsObjWriteUnlock(&pThis->Base);
     1907    RTVfsLockReleaseWrite(pThis->Base.hLock);
    19521908    return rc;
    19531909}
     
    19611917    AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, VERR_INVALID_HANDLE);
    19621918
    1963     rtVfsObjWriteLock(&pThis->Base);
     1919    RTVfsLockAcquireWrite(pThis->Base.hLock);
    19641920    int rc = pThis->pOps->pfnPollOne(pThis->Base.pvThis, fEvents, cMillies, fIntr, pfRetEvents);
    1965     rtVfsObjWriteUnlock(&pThis->Base);
     1921    RTVfsLockReleaseWrite(pThis->Base.hLock);
    19661922    return rc;
    19671923}
     
    19751931
    19761932    RTFOFF off;
    1977     rtVfsObjReadLock(&pThis->Base);
     1933    RTVfsLockAcquireRead(pThis->Base.hLock);
    19781934    int rc = pThis->pOps->pfnTell(pThis->Base.pvThis, &off);
    1979     rtVfsObjReadUnlock(&pThis->Base);
     1935    RTVfsLockReleaseRead(pThis->Base.hLock);
    19801936    if (RT_FAILURE(rc))
    19811937        off = rc;
     
    19941950    if (pThis->pOps->pfnSkip)
    19951951    {
    1996         rtVfsObjWriteLock(&pThis->Base);
     1952        RTVfsLockAcquireWrite(pThis->Base.hLock);
    19971953        rc = pThis->pOps->pfnSkip(pThis->Base.pvThis, cb);
    1998         rtVfsObjWriteUnlock(&pThis->Base);
     1954        RTVfsLockReleaseWrite(pThis->Base.hLock);
    19991955    }
    20001956    else
     
    20071963            {
    20081964                size_t cbToRead = RT_MIN(cb, _64K);
    2009                 rtVfsObjWriteLock(&pThis->Base);
     1965                RTVfsLockAcquireWrite(pThis->Base.hLock);
    20101966                rc = RTVfsIoStrmRead(hVfsIos, pvBuf, cbToRead, true /*fBlocking*/, NULL);
    2011                 rtVfsObjWriteUnlock(&pThis->Base);
     1967                RTVfsLockReleaseWrite(pThis->Base.hLock);
    20121968                if (RT_FAILURE(rc))
    20131969                    break;
     
    20331989    if (pThis->pOps->pfnSkip)
    20341990    {
    2035         rtVfsObjWriteLock(&pThis->Base);
     1991        RTVfsLockAcquireWrite(pThis->Base.hLock);
    20361992        rc = pThis->pOps->pfnZeroFill(pThis->Base.pvThis, cb);
    2037         rtVfsObjWriteUnlock(&pThis->Base);
     1993        RTVfsLockReleaseWrite(pThis->Base.hLock);
    20381994    }
    20391995    else
     
    20462002            {
    20472003                size_t cbToWrite = RT_MIN(cb, _64K);
    2048                 rtVfsObjWriteLock(&pThis->Base);
     2004                RTVfsLockAcquireWrite(pThis->Base.hLock);
    20492005                rc = RTVfsIoStrmWrite(hVfsIos, pvBuf, cbToWrite, true /*fBlocking*/, NULL);
    2050                 rtVfsObjWriteUnlock(&pThis->Base);
     2006                RTVfsLockReleaseWrite(pThis->Base.hLock);
    20512007                if (RT_FAILURE(rc))
    20522008                    break;
     
    21582114
    21592115                /** @todo there is a symlink creation race here. */
    2160                 rtVfsObjWriteLock(&pVfsParentDir->Base);
     2116                RTVfsLockAcquireWrite(pVfsParentDir->Base.hLock);
    21612117                rc = pVfsParentDir->pOps->pfnOpenFile(pVfsParentDir->Base.pvThis, pszEntryName, fOpen, phVfsFile);
    2162                 rtVfsObjWriteUnlock(&pVfsParentDir->Base);
     2118                RTVfsLockReleaseWrite(pVfsParentDir->Base.hLock);
    21632119
    21642120                RTVfsDirRelease(pVfsParentDir);
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