VirtualBox

Changeset 25611 in vbox


Ignore:
Timestamp:
Dec 31, 2009 2:54:25 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
56302
Message:

iprt/lockvaldiator,++: owner record management and some other stuff. Disabled lock strictness for everyeone but me.

Location:
trunk/src/VBox/Runtime
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp

    r25609 r25611  
    5555 * Deadlock detection stack entry.
    5656 */
    57 typedef struct RTLOCKVALIDATORDDENTRY
     57typedef struct RTLOCKVALDDENTRY
    5858{
    5959    /** The current record. */
    60     PRTLOCKVALRECUNION    pRec;
     60    PRTLOCKVALRECUNION      pRec;
    6161    /** The current entry number if pRec is a shared one. */
    62     uint32_t                    iEntry;
     62    uint32_t                iEntry;
    6363    /** The thread state of the thread we followed to get to pFirstSibling.
    6464     * This is only used for validating a deadlock stack.  */
    65     RTTHREADSTATE               enmState;
     65    RTTHREADSTATE           enmState;
    6666    /** The thread we followed to get to pFirstSibling.
    6767     * This is only used for validating a deadlock stack. */
    68     PRTTHREADINT                pThread;
     68    PRTTHREADINT            pThread;
    6969    /** What pThread is waiting on, i.e. where we entered the circular list of
    7070     * siblings.  This is used for validating a deadlock stack as well as
    7171     * terminating the sibling walk. */
    72     PRTLOCKVALRECUNION    pFirstSibling;
    73 } RTLOCKVALIDATORDDENTRY;
     72    PRTLOCKVALRECUNION      pFirstSibling;
     73} RTLOCKVALDDENTRY;
    7474
    7575
     
    7777 * Deadlock detection stack.
    7878 */
    79 typedef struct RTLOCKVALIDATORDDSTACK
     79typedef struct RTLOCKVALDDSTACK
    8080{
    8181    /** The number stack entries. */
    82     uint32_t                    c;
     82    uint32_t                c;
    8383    /** The stack entries. */
    84     RTLOCKVALIDATORDDENTRY      a[32];
    85 } RTLOCKVALIDATORDDSTACK;
     84    RTLOCKVALDDENTRY        a[32];
     85} RTLOCKVALDDSTACK;
    8686/** Pointer to a deadlock detction stack. */
    87 typedef RTLOCKVALIDATORDDSTACK *PRTLOCKVALIDATORDDSTACK;
     87typedef RTLOCKVALDDSTACK *PRTLOCKVALDDSTACK;
    8888
    8989
     
    9292*******************************************************************************/
    9393/** Serializing object destruction and deadlock detection.
    94  * NS: RTLOCKVALIDATORREC* and RTTHREADINT destruction.
    95  * EW: Deadlock detection.
     94 *
     95 * This makes sure that none of the memory examined by the deadlock detection
     96 * code will become invalid (reused for other purposes or made not present)
     97 * while the detection is in progress.
     98 *
     99 * NS: RTLOCKVALREC*, RTTHREADINT and RTLOCKVALDRECSHRD::papOwners destruction.
     100 * EW: Deadlock detection and some related activities.
    96101 */
    97102static RTSEMXROADS      g_hLockValidatorXRoads   = NIL_RTSEMXROADS;
     
    320325
    321326/**
    322  * Serializes destruction of RTLOCKVALIDATORREC* and RTTHREADINT structures.
     327 * Serializes destruction of RTLOCKVALREC* and RTTHREADINT structures.
    323328 */
    324329DECLHIDDEN(void) rtLockValidatorSerializeDestructEnter(void)
     
    361366    if (hXRoads != NIL_RTSEMXROADS)
    362367        RTSemXRoadsEWLeave(hXRoads);
     368}
     369
     370
     371/**
     372 * Initializes the per thread lock validator data.
     373 *
     374 * @param   pPerThread      The data.
     375 */
     376DECLHIDDEN(void) rtLockValidatorInitPerThread(RTLOCKVALPERTHREAD *pPerThread)
     377{
     378    pPerThread->bmFreeShrdOwners = UINT32_MAX;
     379
     380    /* ASSUMES the rest has already been zeroed. */
     381    Assert(pPerThread->pRec == NULL);
     382    Assert(pPerThread->cWriteLocks == 0);
     383    Assert(pPerThread->cReadLocks == 0);
    363384}
    364385
     
    401422    }
    402423}
     424
     425
     426RTDECL(int) RTLockValidatorRecMakeSiblings(PRTLOCKVALRECCORE pRec1, PRTLOCKVALRECCORE pRec2)
     427{
     428    /*
     429     * Validate input.
     430     */
     431    PRTLOCKVALRECUNION p1 = (PRTLOCKVALRECUNION)pRec1;
     432    PRTLOCKVALRECUNION p2 = (PRTLOCKVALRECUNION)pRec2;
     433
     434    AssertPtrReturn(p1, VERR_SEM_LV_INVALID_PARAMETER);
     435    AssertReturn(   p1->Core.u32Magic == RTLOCKVALRECEXCL_MAGIC
     436                 || p1->Core.u32Magic == RTLOCKVALRECSHRD_MAGIC
     437                 , VERR_SEM_LV_INVALID_PARAMETER);
     438
     439    AssertPtrReturn(p2, VERR_SEM_LV_INVALID_PARAMETER);
     440    AssertReturn(   p2->Core.u32Magic == RTLOCKVALRECEXCL_MAGIC
     441                 || p2->Core.u32Magic == RTLOCKVALRECSHRD_MAGIC
     442                 , VERR_SEM_LV_INVALID_PARAMETER);
     443
     444    /*
     445     * Link them (circular list).
     446     */
     447    if (    p1->Core.u32Magic == RTLOCKVALRECEXCL_MAGIC
     448        &&  p2->Core.u32Magic == RTLOCKVALRECSHRD_MAGIC)
     449    {
     450        p1->Excl.pSibling   = p2;
     451        p2->Shared.pSibling = p1;
     452    }
     453    else if (   p1->Core.u32Magic == RTLOCKVALRECSHRD_MAGIC
     454             && p2->Core.u32Magic == RTLOCKVALRECEXCL_MAGIC)
     455    {
     456        p1->Shared.pSibling = p2;
     457        p2->Excl.pSibling   = p1;
     458    }
     459    else
     460        AssertFailedReturn(VERR_SEM_LV_INVALID_PARAMETER); /* unsupported mix */
     461
     462    return VINF_SUCCESS;
     463}
     464
     465
    403466
    404467
     
    538601
    539602/**
    540  * Locates a thread in a shared lock record.
    541  *
    542  * @returns Pointer to the thread record on success, NULL on failure..
     603 * Locates an owner (thread) in a shared lock record.
     604 *
     605 * @returns Pointer to the owner entry on success, NULL on failure..
    543606 * @param   pShared             The shared lock record.
    544  * @param   hThread             The thread to find.
     607 * @param   hThread             The thread (owner) to find.
    545608 * @param   piEntry             Where to optionally return the table in index.
     609 *                              Optional.
    546610 */
    547611DECLINLINE(PRTLOCKVALRECSHRDOWN)
    548 rtLockValidatorSharedRecFindThread(PRTLOCKVALRECSHRD pShared, RTTHREAD hThread, uint32_t *piEntry)
     612rtLockValidatorRecSharedFindOwner(PRTLOCKVALRECSHRD pShared, RTTHREAD hThread, uint32_t *piEntry)
    549613{
    550614    rtLockValidatorSerializeDetectionEnter();
     
    573637
    574638/**
    575  * Allocates and initializes a thread entry for the shared lock record.
    576  *
    577  * @returns The new thread entry.
     639 * Allocates and initializes an owner entry for the shared lock record.
     640 *
     641 * @returns The new owner entry.
    578642 * @param   pShared             The shared lock record.
    579  * @param   hThread             The thread handle.
     643 * @param   pThreadSelf         The calling thread and owner.  Used for record
     644 *                              initialization and allocation.
    580645 * @param   pSrcPos             The source position.
    581646 */
    582647DECLINLINE(PRTLOCKVALRECSHRDOWN)
    583 rtLockValidatorSharedRecAllocThread(PRTLOCKVALRECSHRD pRead, RTTHREAD hThread, PCRTLOCKVALSRCPOS pSrcPos)
     648rtLockValidatorRecSharedAllocOwner(PRTLOCKVALRECSHRD pRead, PRTTHREADINT pThreadSelf, PCRTLOCKVALSRCPOS pSrcPos)
    584649{
    585650    PRTLOCKVALRECSHRDOWN pEntry;
    586651
    587     pEntry = (PRTLOCKVALRECSHRDOWN)RTMemAlloc(sizeof(RTLOCKVALRECSHRDOWN));
     652    /*
     653     * Check if the thread has any statically allocated records we can use.
     654     */
     655    unsigned iEntry = ASMBitFirstSetU32(pThreadSelf->LockValidator.bmFreeShrdOwners);
     656    if (iEntry > 0)
     657    {
     658        iEntry--;
     659        pThreadSelf->LockValidator.bmFreeShrdOwners |= RT_BIT_32(iEntry);
     660        pEntry = &pThreadSelf->LockValidator.aShrdOwners[iEntry];
     661        Assert(!pEntry->fReserved);
     662        pEntry->fStaticAlloc = true;
     663    }
     664    else
     665    {
     666        pEntry = (PRTLOCKVALRECSHRDOWN)RTMemAlloc(sizeof(RTLOCKVALRECSHRDOWN));
     667        if (RT_UNLIKELY(!pEntry))
     668            return NULL;
     669        pEntry->fStaticAlloc = false;
     670    }
     671
     672    pEntry->Core.u32Magic   = RTLOCKVALRECSHRDOWN_MAGIC;
     673    pEntry->cRecursion      = 1;
     674    pEntry->fReserved       = true;
     675    pEntry->hThread         = pThreadSelf;
     676    pEntry->pDown           = NULL;
     677    pEntry->pSharedRec      = pRead;
     678#if HC_ARCH_BITS == 32
     679    pEntry->pvReserved      = NULL;
     680#endif
     681    if (pSrcPos)
     682        pEntry->SrcPos      = *pSrcPos;
     683    else
     684        rtLockValidatorInitSrcPos(&pEntry->SrcPos);
     685    return pEntry;
     686}
     687
     688
     689/**
     690 * Frees an owner entry allocated by rtLockValidatorRecSharedAllocOwner.
     691 *
     692 * @param   pEntry              The owner entry.
     693 */
     694DECLINLINE(void) rtLockValidatorRecSharedFreeOwner(PRTLOCKVALRECSHRDOWN pEntry)
     695{
    588696    if (pEntry)
    589697    {
    590         pEntry->Core.u32Magic   = RTLOCKVALRECSHRDOWN_MAGIC;
    591         pEntry->cRecursion      = 1;
    592         pEntry->hThread         = hThread;
    593         pEntry->pDown           = NULL;
    594         pEntry->pSharedRec      = pRead;
    595 #if HC_ARCH_BITS == 32
    596         pEntry->pvReserved      = NULL;
    597 #endif
    598         if (pSrcPos)
    599             pEntry->SrcPos      = *pSrcPos;
     698        ASMAtomicWriteU32(&pEntry->Core.u32Magic, RTLOCKVALRECSHRDOWN_MAGIC_DEAD);
     699
     700        PRTTHREADINT pThreadSelf = pEntry->hThread;
     701        ASMAtomicXchgHandle(&pEntry->hThread, NIL_RTTHREAD, &pThreadSelf);
     702        Assert(pThreadSelf == RTThreadSelf());
     703
     704        pEntry->fReserved = false;
     705
     706        Assert(pEntry->fReserved);
     707        if (pEntry->fStaticAlloc)
     708        {
     709            uintptr_t iEntry = pEntry - &pThreadSelf->LockValidator.aShrdOwners[0];
     710            AssertReleaseReturnVoid(iEntry < RT_ELEMENTS(pThreadSelf->LockValidator.aShrdOwners));
     711            pThreadSelf->LockValidator.bmFreeShrdOwners &= ~RT_BIT_32(iEntry);
     712        }
    600713        else
    601             rtLockValidatorInitSrcPos(&pEntry->SrcPos);
    602     }
    603 
    604     return pEntry;
    605 }
    606 
    607 /**
    608  * Frees a thread entry allocated by rtLockValidatorSharedRecAllocThread.
    609  *
    610  * @param   pEntry              The thread entry.
    611  */
    612 DECLINLINE(void) rtLockValidatorSharedRecFreeThread(PRTLOCKVALRECSHRDOWN pEntry)
    613 {
    614     if (pEntry)
    615     {
    616         rtLockValidatorSerializeDestructEnter();
    617         ASMAtomicWriteU32(&pEntry->Core.u32Magic, RTLOCKVALRECSHRDOWN_MAGIC_DEAD);
    618         ASMAtomicWriteHandle(&pEntry->hThread, NIL_RTTHREAD);
    619         rtLockValidatorSerializeDestructLeave();
    620 
    621         RTMemFree(pEntry);
     714        {
     715            rtLockValidatorSerializeDestructEnter();
     716            rtLockValidatorSerializeDestructLeave();
     717
     718            RTMemFree(pEntry);
     719        }
    622720    }
    623721}
     
    633731 * @param   pShared             The shared lock record.
    634732 */
    635 static bool rtLockValidatorSharedRecMakeRoom(PRTLOCKVALRECSHRD pShared)
     733static bool rtLockValidatorRecSharedMakeRoom(PRTLOCKVALRECSHRD pShared)
    636734{
    637735    for (unsigned i = 0; i < 1000; i++)
     
    704802
    705803/**
    706  * Adds a thread entry to a shared lock record.
     804 * Adds an owner entry to a shared lock record.
    707805 *
    708806 * @returns true on success, false on serious race or we're if out of memory.
    709807 * @param   pShared             The shared lock record.
    710  * @param   pEntry              The thread entry.
    711  */
    712 DECLINLINE(bool) rtLockValidatorSharedRecAddThread(PRTLOCKVALRECSHRD pShared, PRTLOCKVALRECSHRDOWN pEntry)
     808 * @param   pEntry              The owner entry.
     809 */
     810DECLINLINE(bool) rtLockValidatorRecSharedAddOwner(PRTLOCKVALRECSHRD pShared, PRTLOCKVALRECSHRDOWN pEntry)
    713811{
    714812    rtLockValidatorSerializeDetectionEnter();
     
    716814    {
    717815        if (   ASMAtomicIncU32(&pShared->cEntries) > pShared->cAllocated /** @todo add fudge */
    718             && !rtLockValidatorSharedRecMakeRoom(pShared))
     816            && !rtLockValidatorRecSharedMakeRoom(pShared))
    719817            return false; /* the worker leave the lock */
    720818
     
    741839
    742840/**
    743  * Remove a thread entry from a shared lock record and free it.
     841 * Remove an owner entry from a shared lock record and free it.
    744842 *
    745843 * @param   pShared             The shared lock record.
    746  * @param   pEntry              The thread entry to remove.
     844 * @param   pEntry              The owner entry to remove.
    747845 * @param   iEntry              The last known index.
    748846 */
    749 DECLINLINE(void) rtLockValidatorSharedRecRemoveAndFree(PRTLOCKVALRECSHRD pShared, PRTLOCKVALRECSHRDOWN pEntry,
    750                                                        uint32_t iEntry)
     847DECLINLINE(void) rtLockValidatorRecSharedRemoveAndFreeOwner(PRTLOCKVALRECSHRD pShared, PRTLOCKVALRECSHRDOWN pEntry,
     848                                                            uint32_t iEntry)
    751849{
    752850    /*
     
    774872     * Successfully removed, now free it.
    775873     */
    776     rtLockValidatorSharedRecFreeThread(pEntry);
    777 }
    778 
    779 
    780 RTDECL(int) RTLockValidatorRecMakeSiblings(PRTLOCKVALRECCORE pRec1, PRTLOCKVALRECCORE pRec2)
    781 {
    782     /*
    783      * Validate input.
    784      */
    785     PRTLOCKVALRECUNION p1 = (PRTLOCKVALRECUNION)pRec1;
    786     PRTLOCKVALRECUNION p2 = (PRTLOCKVALRECUNION)pRec2;
    787 
    788     AssertPtrReturn(p1, VERR_SEM_LV_INVALID_PARAMETER);
    789     AssertReturn(   p1->Core.u32Magic == RTLOCKVALRECEXCL_MAGIC
    790                  || p1->Core.u32Magic == RTLOCKVALRECSHRD_MAGIC
    791                  , VERR_SEM_LV_INVALID_PARAMETER);
    792 
    793     AssertPtrReturn(p2, VERR_SEM_LV_INVALID_PARAMETER);
    794     AssertReturn(   p2->Core.u32Magic == RTLOCKVALRECEXCL_MAGIC
    795                  || p2->Core.u32Magic == RTLOCKVALRECSHRD_MAGIC
    796                  , VERR_SEM_LV_INVALID_PARAMETER);
    797 
    798     /*
    799      * Link them (circular list).
    800      */
    801     if (    p1->Core.u32Magic == RTLOCKVALRECEXCL_MAGIC
    802         &&  p2->Core.u32Magic == RTLOCKVALRECSHRD_MAGIC)
    803     {
    804         p1->Excl.pSibling   = p2;
    805         p2->Shared.pSibling = p1;
    806     }
    807     else if (   p1->Core.u32Magic == RTLOCKVALRECSHRD_MAGIC
    808              && p2->Core.u32Magic == RTLOCKVALRECEXCL_MAGIC)
    809     {
    810         p1->Shared.pSibling = p2;
    811         p2->Excl.pSibling   = p1;
    812     }
    813     else
    814         AssertFailedReturn(VERR_SEM_LV_INVALID_PARAMETER); /* unsupported mix */
    815 
    816     return VINF_SUCCESS;
     874    rtLockValidatorRecSharedFreeOwner(pEntry);
    817875}
    818876
     
    860918     */
    861919    uint32_t                iEntry = 0;
    862     PRTLOCKVALRECSHRDOWN    pEntry = rtLockValidatorSharedRecFindThread(pRead, hThread, &iEntry);
     920    PRTLOCKVALRECSHRDOWN    pEntry = rtLockValidatorRecSharedFindOwner(pRead, hThread, &iEntry);
    863921    AssertReturn(pEntry, VERR_SEM_LV_NOT_OWNER);
    864922
     
    878936        pEntry->cRecursion--;
    879937    else
    880         rtLockValidatorSharedRecRemoveAndFree(pRead, pEntry, iEntry);
     938        rtLockValidatorRecSharedRemoveAndFreeOwner(pRead, pEntry, iEntry);
    881939
    882940    return VINF_SUCCESS;
     
    10141072        return;
    10151073    AssertReturnVoid(hThread != NIL_RTTHREAD);
     1074    AssertReturnVoid(hThread->u32Magic == RTTHREADINT_MAGIC);
    10161075
    10171076    /*
     
    10221081     *       so it can wait til later sometime.
    10231082     */
    1024     PRTLOCKVALRECSHRDOWN pEntry = rtLockValidatorSharedRecFindThread(pRead, hThread, NULL);
     1083    PRTLOCKVALRECSHRDOWN pEntry = rtLockValidatorRecSharedFindOwner(pRead, hThread, NULL);
    10251084    if (pEntry)
    10261085    {
     
    10301089
    10311090    /*
    1032      * Allocate a new thread entry and insert it into the table.
    1033      */
    1034     pEntry = rtLockValidatorSharedRecAllocThread(pRead, hThread, pSrcPos);
     1091     * Allocate a new owner entry and insert it into the table.
     1092     */
     1093    pEntry = rtLockValidatorRecSharedAllocOwner(pRead, hThread, pSrcPos);
    10351094    if (    pEntry
    1036         &&  !rtLockValidatorSharedRecAddThread(pRead, pEntry))
    1037         rtLockValidatorSharedRecFreeThread(pEntry);
     1095        &&  !rtLockValidatorRecSharedAddOwner(pRead, pEntry))
     1096        rtLockValidatorRecSharedFreeOwner(pEntry);
    10381097}
    10391098
     
    10491108     * Find the entry hope it's a recursive one.
    10501109     */
    1051     uint32_t iEntry;
    1052     PRTLOCKVALRECSHRDOWN pEntry = rtLockValidatorSharedRecFindThread(pRead, hThread, &iEntry);
     1110    uint32_t iEntry = UINT32_MAX; /* shuts up gcc */
     1111    PRTLOCKVALRECSHRDOWN pEntry = rtLockValidatorRecSharedFindOwner(pRead, hThread, &iEntry);
    10531112    AssertReturnVoid(pEntry);
    10541113    if (pEntry->cRecursion > 1)
    10551114        pEntry->cRecursion--;
    10561115    else
    1057         rtLockValidatorSharedRecRemoveAndFree(pRead, pEntry, iEntry);
     1116        rtLockValidatorRecSharedRemoveAndFreeOwner(pRead, pEntry, iEntry);
    10581117}
    10591118
     
    11371196 * @param   pStack              The deadlock detection stack.
    11381197 */
    1139 static int rtLockValidatorDdVerifyDeadlock(PRTLOCKVALIDATORDDSTACK pStack)
     1198static int rtLockValidatorDdVerifyDeadlock(PRTLOCKVALDDSTACK pStack)
    11401199{
    11411200    uint32_t const c = pStack->c;
     
    11671226 * @param   pStack              The deadlock detection stack.
    11681227 */
    1169 static int rtLockValidatorDdHandleStackOverflow(PRTLOCKVALIDATORDDSTACK pStack)
     1228static int rtLockValidatorDdHandleStackOverflow(PRTLOCKVALDDSTACK pStack)
    11701229{
    11711230    for (size_t i = 0; i < RT_ELEMENTS(pStack->a) - 1; i++)
     
    12321291 * @param   pThreadSelf     The calling thread.
    12331292 */
    1234 static int rtLockValidatorDdDoDetection(PRTLOCKVALIDATORDDSTACK pStack, PRTLOCKVALRECUNION const pOriginalRec,
     1293static int rtLockValidatorDdDoDetection(PRTLOCKVALDDSTACK pStack, PRTLOCKVALRECUNION const pOriginalRec,
    12351294                                        PRTTHREADINT const pThreadSelf)
    12361295{
    12371296    pStack->c = 0;
    12381297
    1239     /* We could use a single RTLOCKVALIDATORDDENTRY variable here, but the
     1298    /* We could use a single RTLOCKVALDDENTRY variable here, but the
    12401299       compiler may make a better job of it when using individual variables. */
    1241     PRTLOCKVALRECUNION    pRec            = pOriginalRec;
    1242     PRTLOCKVALRECUNION    pFirstSibling   = pOriginalRec;
    1243     uint32_t                    iEntry          = UINT32_MAX;
    1244     PRTTHREADINT                pThread         = NIL_RTTHREAD;
    1245     RTTHREADSTATE               enmState        = RTTHREADSTATE_RUNNING;
     1300    PRTLOCKVALRECUNION  pRec            = pOriginalRec;
     1301    PRTLOCKVALRECUNION  pFirstSibling   = pOriginalRec;
     1302    uint32_t            iEntry          = UINT32_MAX;
     1303    PRTTHREADINT        pThread         = NIL_RTTHREAD;
     1304    RTTHREADSTATE       enmState        = RTTHREADSTATE_RUNNING;
    12461305    for (;;)
    12471306    {
     
    12941353
    12951354                /* Scan the owner table for blocked owners. */
     1355                pNextThread = NIL_RTTHREAD;
    12961356                if (ASMAtomicUoReadU32(&pRec->Shared.cEntries) > 0)
    12971357                {
     
    13441404
    13451405        /* If we found a thread, check if it is still waiting for something. */
    1346         RTTHREADSTATE               enmNextState = RTTHREADSTATE_RUNNING;
    1347         PRTLOCKVALRECUNION    pNextRec     = NULL;
     1406        RTTHREADSTATE       enmNextState = RTTHREADSTATE_RUNNING;
     1407        PRTLOCKVALRECUNION  pNextRec     = NULL;
    13481408        if (   pNextThread != NIL_RTTHREAD
    13491409            && RT_LIKELY(pNextThread->u32Magic == RTTHREADINT_MAGIC))
     
    14521512 * @param   rc              The return code.
    14531513 */
    1454 static void rcLockValidatorDoDeadlockComplaining(PRTLOCKVALIDATORDDSTACK pStack, PRTLOCKVALRECUNION pRec,
     1514static void rcLockValidatorDoDeadlockComplaining(PRTLOCKVALDDSTACK pStack, PRTLOCKVALRECUNION pRec,
    14551515                                                 PRTTHREADINT pThreadSelf, PCRTLOCKVALSRCPOS pSrcPos, int rc)
    14561516{
     
    15001560{
    15011561#ifdef DEBUG_bird
    1502     RTLOCKVALIDATORDDSTACK Stack;
     1562    RTLOCKVALDDSTACK Stack;
    15031563    int rc = rtLockValidatorDdDoDetection(&Stack, pRec, pThreadSelf);
    15041564    if (RT_SUCCESS(rc))
     
    15391599    AssertPtrReturn(pWriteU, VERR_SEM_LV_INVALID_PARAMETER);
    15401600    AssertReturn(pWriteU->Core.u32Magic == RTLOCKVALRECEXCL_MAGIC, VERR_SEM_LV_INVALID_PARAMETER);
     1601
    15411602    PRTLOCKVALRECUNION pReadU = (PRTLOCKVALRECUNION)pRead;
    15421603    AssertPtrReturn(pRead, VERR_SEM_LV_INVALID_PARAMETER);
    15431604    AssertReturn(pReadU->Core.u32Magic == RTLOCKVALRECSHRD_MAGIC, VERR_SEM_LV_INVALID_PARAMETER);
     1605
    15441606    AssertReturn(pReadU->Shared.fEnabled == pWriteU->Excl.fEnabled, VERR_SEM_LV_INVALID_PARAMETER);
    15451607    if (!pWriteU->Excl.fEnabled)
    15461608        return VINF_SUCCESS;
     1609
    15471610    AssertReturn(RTTHREAD_IS_SLEEPING(enmState), VERR_SEM_LV_INVALID_PARAMETER);
     1611
    15481612    PRTTHREADINT pThread = hThread;
    15491613    AssertPtrReturn(pThread, VERR_SEM_LV_INVALID_PARAMETER);
     
    15581622     * Check for attempts at doing a read upgrade.
    15591623     */
    1560     PRTLOCKVALRECSHRDOWN pEntry = rtLockValidatorSharedRecFindThread(&pReadU->Shared, hThread, NULL);
     1624    PRTLOCKVALRECSHRDOWN pEntry = rtLockValidatorRecSharedFindOwner(&pReadU->Shared, hThread, NULL);
    15611625    if (pEntry)
    15621626    {
     
    16141678    if (!pRecU->Excl.fEnabled)
    16151679        return VINF_SUCCESS;
     1680
    16161681    AssertReturn(RTTHREAD_IS_SLEEPING(enmState), VERR_SEM_LV_INVALID_PARAMETER);
     1682
    16171683    PRTTHREADINT pThreadSelf = hThread;
    16181684    AssertPtrReturn(pThreadSelf, VERR_SEM_LV_INVALID_PARAMETER);
    16191685    AssertReturn(pThreadSelf->u32Magic == RTTHREADINT_MAGIC, VERR_SEM_LV_INVALID_PARAMETER);
     1686
    16201687    RTTHREADSTATE enmThreadState = rtThreadGetState(pThreadSelf);
    16211688    AssertReturn(   enmThreadState == RTTHREADSTATE_RUNNING
  • trunk/src/VBox/Runtime/common/misc/thread.cpp

    r25598 r25611  
    367367        pThread->fIntFlags  = fIntFlags;
    368368        pThread->enmState   = RTTHREADSTATE_INITIALIZING;
     369#ifdef IN_RING3
     370        rtLockValidatorInitPerThread(&pThread->LockValidator);
     371#endif
    369372        int rc = RTSemEventMultiCreate(&pThread->EventUser);
    370373        if (RT_SUCCESS(rc))
  • trunk/src/VBox/Runtime/include/internal/lockvalidator.h

    r25609 r25611  
    5555 * This is part of the RTTHREADINT structure.
    5656 */
    57 typedef struct RTLOCKVALIDATORPERTHREAD
     57typedef struct RTLOCKVALPERTHREAD
    5858{
     59    /** Where we are blocking. */
     60    RTLOCKVALSRCPOS                 SrcPos;
    5961    /** What we're blocking on. */
    6062    PRTLOCKVALRECUNION volatile     pRec;
    61     /** Where we are blocking. */
    62     RTLOCKVALSRCPOS                 SrcPos;
    6363    /** Number of registered write locks, mutexes and critsects that this thread owns. */
    6464    int32_t volatile                cWriteLocks;
    6565    /** Number of registered read locks that this thread owns, nesting included. */
    6666    int32_t volatile                cReadLocks;
    67 } RTLOCKVALIDATORPERTHREAD;
     67    /** Bitmap indicating which entires are free (set) and allocated (clear). */
     68    uint32_t                        bmFreeShrdOwners;
     69    /** Reserved for alignment purposes. */
     70    uint32_t                        u32Reserved;
     71    /** Statically allocated shared owner records */
     72    RTLOCKVALRECSHRDOWN             aShrdOwners[32];
     73} RTLOCKVALPERTHREAD;
    6874
    6975
     76DECLHIDDEN(void)    rtLockValidatorInitPerThread(RTLOCKVALPERTHREAD *pPerThread);
    7077DECLHIDDEN(void)    rtLockValidatorSerializeDestructEnter(void);
    7178DECLHIDDEN(void)    rtLockValidatorSerializeDestructLeave(void);
  • trunk/src/VBox/Runtime/include/internal/magics.h

    r25608 r25611  
    6767/** The magic value for RTLOCALIPCSERVER::u32Magic. (Katsuhiro Otomo) */
    6868#define RTLOCALIPCSESSION_MAGIC         UINT32_C(0x19530414)
    69 /** The magic value for RTLOCKVALIDATORREC::u32Magic. (Vladimir Vladimirovich Nabokov) */
     69/** The magic value for RTLOCKVALRECEXCL::u32Magic. (Vladimir Vladimirovich Nabokov) */
    7070#define RTLOCKVALRECEXCL_MAGIC          UINT32_C(0x18990422)
    71 /** The dead magic value for RTLOCKVALIDATORREC::u32Magic. */
     71/** The dead magic value for RTLOCKVALRECEXCL::u32Magic. */
    7272#define RTLOCKVALRECEXCL_MAGIC_DEAD     UINT32_C(0x19770702)
    7373/** The magic value for RTLOCKVALRECSHRD::u32Magic. (Agnar Mykle) */
  • trunk/src/VBox/Runtime/include/internal/strict.h

    r25482 r25611  
    3535 * @{ */
    3636
     37#ifdef DEBUG_bird /** @todo reenable this for everyone. Just being a little be cautious right now... */
    3738/** @def RTCRITSECT_STRICT
    3839 * Enables strictness checks and lock accounting of the RTCritSect API.
     
    5758# define RTSEMRW_STRICT
    5859#endif
    59 
     60#endif /* DEBUG_bird */
    6061
    6162
  • trunk/src/VBox/Runtime/include/internal/thread.h

    r25597 r25611  
    9292#ifdef IN_RING3
    9393    /** The lock validator data. */
    94     RTLOCKVALIDATORPERTHREAD LockValidator;
     94    RTLOCKVALPERTHREAD      LockValidator;
    9595#endif /* IN_RING3 */
    9696#ifdef IPRT_WITH_GENERIC_TLS
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