VirtualBox

Changeset 25478 in vbox


Ignore:
Timestamp:
Dec 18, 2009 12:58:10 PM (15 years ago)
Author:
vboxsync
Message:

IPRT,PDMCritSect: More lock validator refactoring.

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/lockvalidator.h

    r25467 r25478  
    4444RT_C_DECLS_BEGIN
    4545
    46 /**
    47  * Record recording the ownership of a lock.
    48  *
    49  * This is typically part of the per-lock data structure when compiling with
    50  * the lock validator.
    51  */
    52 typedef struct RTLOCKVALIDATORREC
     46typedef struct RTLOCKVALIDATORSRCPOS
    5347{
    54     /** Magic value (RTLOCKVALIDATORREC_MAGIC). */
    55     uint32_t                            u32Magic;
    56     /** The line number in the file. */
    57     uint32_t volatile                   uLine;
    5848    /** The file where the lock was taken. */
    5949    R3R0PTRTYPE(const char * volatile)  pszFile;
     
    6252    /** Some ID indicating where the lock was taken, typically an address. */
    6353    RTHCUINTPTR volatile                uId;
     54    /** The line number in the file. */
     55    uint32_t volatile                   uLine;
     56#if HC_ARCH_BITS == 64
     57    uint32_t                            u32Padding; /**< Alignment padding. */
     58#endif
     59} RTLOCKVALIDATORSRCPOS;
     60AssertCompileSize(RTLOCKVALIDATORSRCPOS, HC_ARCH_BITS == 32 ? 16 : 32);
     61/* The pointer types are defined in iprt/types.h. */
     62
     63/** @def RTLOCKVALIDATORSRCPOS_INIT
     64 * Initializer for a RTLOCKVALIDATORSRCPOS variable.
     65 *
     66 * @param   pszFile         The file name.  Optional (NULL).
     67 * @param   uLine           The line number in that file. Optional (0).
     68 * @param   pszFunction     The function.  Optional (NULL).
     69 * @param   uId             Some location ID, normally the return address.
     70 *                          Optional (NULL).
     71 */
     72#if HC_ARCH_BITS == 64
     73# define RTLOCKVALIDATORSRCPOS_INIT(pszFile, uLine, pszFunction, uId) \
     74    { (pszFile), (pszFunction), (uId), (uLine), 0 }
     75#else
     76# define RTLOCKVALIDATORSRCPOS_INIT(pszFile, uLine, pszFunction, uId) \
     77    { (pszFile), (pszFunction), (uId), (uLine) }
     78#endif
     79
     80/** @def RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API
     81 * Initializer for a RTLOCKVALIDATORSRCPOS variable in a typicial debug API
     82 * variant.  Assumes RT_SRC_POS_DECL and RTHCUINTPTR uId as arguments.
     83 */
     84#define RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API()  \
     85    RTLOCKVALIDATORSRCPOS_INIT(pszFile, iLine, pszFunction, uId)
     86
     87/** @def RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API
     88 * Initializer for a RTLOCKVALIDATORSRCPOS variable in a normal API
     89 * variant.  Assumes iprt/asm.h is included.
     90 */
     91#define RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API() \
     92    RTLOCKVALIDATORSRCPOS_INIT(__FILE__, __LINE__, __PRETTY_FUNCTION__, (uintptr_t)ASMReturnAddress())
     93
     94
     95/**
     96 * Record recording the ownership of a lock.
     97 *
     98 * This is typically part of the per-lock data structure when compiling with
     99 * the lock validator.
     100 */
     101typedef struct RTLOCKVALIDATORREC
     102{
     103    /** Magic value (RTLOCKVALIDATORREC_MAGIC). */
     104    uint32_t                            u32Magic;
     105    /** Reserved. */
     106    uint32_t                            u32Reserved;
     107    /** Source position where the lock was taken. */
     108    RTLOCKVALIDATORSRCPOS               SrcPos;
    64109    /** The current owner thread. */
    65110    RTTHREAD volatile                   hThread;
     
    76121    /** The lock name. */
    77122    R3R0PTRTYPE(const char *)           pszName;
     123    /** Reserved. */
     124    RTHCPTR                             pvReserved;
    78125} RTLOCKVALIDATORREC;
    79 AssertCompileSize(RTLOCKVALIDATORREC, HC_ARCH_BITS == 32 ? 48 : 80);
    80 /* The pointer is defined in iprt/types.h */
     126AssertCompileSize(RTLOCKVALIDATORREC, HC_ARCH_BITS == 32 ? 8 + 16 + 32 : 8 + 32 + 56);
     127/* The pointer type is defined in iprt/types.h. */
     128
     129/** Pointer to a record of one ownership share.  */
     130typedef struct RTLOCKVALIDATORSHAREDREC *PRTLOCKVALIDATORSHAREDREC;
     131/**
     132 * For recording the one ownership share.
     133 */
     134typedef struct RTLOCKVALIDATORSHAREDONE
     135{
     136    /** Magic value (RTLOCKVALIDATORSHAREDONE_MAGIC). */
     137    uint32_t                                u32Magic;
     138    /** Recursion count */
     139    uint32_t                                cRecursion;
     140    /** The current owner thread. */
     141    RTTHREAD volatile                       hThread;
     142    /** Pointer to the lock record below us. Only accessed by the owner. */
     143    R3R0PTRTYPE(PRTLOCKVALIDATORREC)        pDown;
     144    /** Pointer back to the shared record. */
     145    R3R0PTRTYPE(PRTLOCKVALIDATORSHAREDREC)  pSharedRec;
     146#if HC_ARCH_BITS == 32
     147    /** Reserved. */
     148    RTHCPTR                                 pvReserved;
     149#endif
     150    /** Source position where the lock was taken. */
     151    RTLOCKVALIDATORSRCPOS                   SrcPos;
     152} RTLOCKVALIDATORSHAREDONE;
     153AssertCompileSize(RTLOCKVALIDATORSHAREDONE, HC_ARCH_BITS == 32 ? 24 + 16 : 32 + 32);
     154/** Pointer to a RTLOCKVALIDATORSHAREDONE. */
     155typedef RTLOCKVALIDATORSHAREDONE *PRTLOCKVALIDATORSHAREDONE;
     156
     157/**
     158 * Record recording the shared ownership of a lock.
     159 *
     160 * This is typically part of the per-lock data structure when compiling with
     161 * the lock validator.
     162 */
     163typedef struct RTLOCKVALIDATORSHARED
     164{
     165    /** Magic value (RTLOCKVALIDATORSHARED_MAGIC). */
     166    uint32_t                            u32Magic;
     167    /** The lock sub-class. */
     168    uint32_t volatile                   uSubClass;
     169    /** The lock class. */
     170    RTLOCKVALIDATORCLASS                hClass;
     171    /** Pointer to the lock. */
     172    RTHCPTR                             hLock;
     173    /** The lock name. */
     174    R3R0PTRTYPE(const char *)           pszName;
     175
     176    /** The number of entries in the table.
     177     * Updated before inserting and after removal. */
     178    uint32_t volatile                   cEntries;
     179    /** The index of the last entry (approximately). */
     180    uint32_t volatile                   iLastEntry;
     181    /** The max table size. */
     182    uint32_t volatile                   cAllocated;
     183    /** Set if the table is being reallocated, clear if not.
     184     * This is used together with rtLockValidatorSerializeDetectionEnter to make
     185     * sure there is exactly one thread doing the reallocation and that nobody is
     186     * using the table at that point. */
     187    bool volatile                       fReallocating;
     188    /** Alignment padding. */
     189    bool                                afPadding[3];
     190    /** Pointer to a table containing pointers to records of all the owners. */
     191    R3R0PTRTYPE(PRTLOCKVALIDATORSHAREDONE volatile *) papOwners;
     192    /** Alignment padding. */
     193    uint64_t                            u64Alignment;
     194} RTLOCKVALIDATORSHARED;
     195AssertCompileSize(RTLOCKVALIDATORSHARED, HC_ARCH_BITS == 32 ? 20 + 20 + 8 : 32 + 32);
     196/** Pointer to a RTLOCKVALIDATORSHARED. */
     197typedef RTLOCKVALIDATORSHARED *PRTLOCKVALIDATORSHARED;
    81198
    82199
     
    158275 *                              pass NIL_RTTHREAD and this method will figure it
    159276 *                              out.
    160  * @param   uId                 Some kind of locking location ID.  Typically a
    161  *                              return address up the stack.  Optional (0).
    162  * @param   pszFile             The file where the lock is being acquired from.
    163  *                              Optional.
    164  * @param   iLine               The line number in that file.  Optional (0).
    165  * @param   pszFunction         The functionn where the lock is being acquired
    166  *                              from.  Optional.
    167  */
    168 RTDECL(int)  RTLockValidatorCheckOrder(PRTLOCKVALIDATORREC pRec, RTTHREAD hThread, RTHCUINTPTR uId, RT_SRC_POS_DECL);
    169 
    170 /**
    171  * Change the thread state to blocking and do deadlock detection.
     277 * @param   pSrcPos             The source position of the lock operation.
     278 */
     279RTDECL(int)  RTLockValidatorCheckOrder(PRTLOCKVALIDATORREC pRec, RTTHREAD hThread, PCRTLOCKVALIDATORSRCPOS pSrcPos);
     280
     281/**
     282 * Do deadlock detection before blocking on a lock.
    172283 *
    173284 * @retval  VINF_SUCCESS
     
    183294 * @param   pvBlock             Pointer to a RTLOCKVALIDATORREC structure.
    184295 * @param   fRecursiveOk        Whether it's ok to recurse.
    185  * @param   uId                 Where we are blocking.
    186  * @param   RT_SRC_POS_DECL     Where we are blocking.
     296 * @param   pSrcPos             The source position of the lock operation.
    187297 */
    188298RTDECL(int) RTLockValidatorCheckBlocking(PRTLOCKVALIDATORREC pRec, RTTHREAD hThread,
    189299                                         RTTHREADSTATE enmState, bool fRecursiveOk,
    190                                          RTHCUINTPTR uId, RT_SRC_POS_DECL);
     300                                         PCRTLOCKVALIDATORSRCPOS pSrcPos);
    191301
    192302/**
     
    213323 *
    214324 * @param   pRec                The validator record.
    215  * @param   uId                 Some kind of locking location ID.  Typically a
    216  *                              return address up the stack.  Optional (0).
    217  * @param   pszFile             The file where the lock is being acquired from.
    218  *                              Optional.
    219  * @param   iLine               The line number in that file.  Optional (0).
    220  * @param   pszFunction         The functionn where the lock is being acquired
    221  *                              from.  Optional.
    222  */
    223 RTDECL(int) RTLockValidatorRecordRecursion(PRTLOCKVALIDATORREC pRec, RTHCUINTPTR uId, RT_SRC_POS_DECL);
     325 * @param   pSrcPos             The source position of the lock operation.
     326 */
     327RTDECL(int) RTLockValidatorRecordRecursion(PRTLOCKVALIDATORREC pRec, PCRTLOCKVALIDATORSRCPOS pSrcPos);
    224328
    225329/**
     
    244348 *                              pass NIL_RTTHREAD and this method will figure it
    245349 *                              out.
    246  * @param   uId                 Some kind of locking location ID.  Typically a
    247  *                              return address up the stack.  Optional (0).
    248  * @param   pszFile             The file where the lock is being acquired from.
    249  *                              Optional.
    250  * @param   iLine               The line number in that file.  Optional (0).
    251  * @param   pszFunction         The functionn where the lock is being acquired
    252  *                              from.  Optional.
    253  */
    254 RTDECL(RTTHREAD) RTLockValidatorSetOwner(PRTLOCKVALIDATORREC pRec, RTTHREAD hThread, RTHCUINTPTR uId, RT_SRC_POS_DECL);
     350 * @param   pSrcPos             The source position of the lock operation.
     351 */
     352RTDECL(RTTHREAD) RTLockValidatorSetOwner(PRTLOCKVALIDATORREC pRec, RTTHREAD hThread, PCRTLOCKVALIDATORSRCPOS pSrcPos);
    255353
    256354
  • trunk/include/iprt/thread.h

    r25409 r25478  
    3434#include <iprt/types.h>
    3535#include <iprt/stdarg.h>
    36 
    37 #ifdef IN_RC
    38 # error "There are no threading APIs available Guest Context!"
    39 #endif
    40 
    4136
    4237
     
    8984
    9085/**
    91  * Get the thread handle of the current thread.
    92  *
    93  * @returns Thread handle.
    94  */
    95 RTDECL(RTTHREAD) RTThreadSelf(void);
    96 
    97 /**
    98  * Get the thread handle of the current thread, automatically adopting alien
    99  * threads.
    100  *
    101  * @returns Thread handle.
    102  */
    103 RTDECL(RTTHREAD) RTThreadSelfAutoAdopt(void);
    104 
    105 /**
    106  * Get the native thread handle of the current thread.
    107  *
    108  * @returns Native thread handle.
    109  */
    110 RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void);
    111 
    112 /**
    113  * Millisecond granular sleep function.
    114  *
    115  * @returns VINF_SUCCESS on success.
    116  * @returns VERR_INTERRUPTED if a signal or other asynchronous stuff happend
    117  *          which interrupt the peaceful sleep.
    118  * @param   cMillies    Number of milliseconds to sleep.
    119  *                      0 milliseconds means yielding the timeslice - deprecated!
    120  * @remark  See RTThreadNanoSleep() for sleeping for smaller periods of time.
    121  */
    122 RTDECL(int) RTThreadSleep(unsigned cMillies);
    123 
    124 /**
    125  * Yields the CPU.
    126  *
    127  * @returns true if we yielded.
    128  * @returns false if it's probable that we didn't yield.
    129  */
    130 RTDECL(bool) RTThreadYield(void);
    131 
    132 
    133 
    134 /**
    135  * Thread function.
    136  *
    137  * @returns 0 on success.
    138  * @param   ThreadSelf  Thread handle to this thread.
    139  * @param   pvUser      User argument.
    140  */
    141 typedef DECLCALLBACK(int) FNRTTHREAD(RTTHREAD ThreadSelf, void *pvUser);
    142 /** Pointer to a FNRTTHREAD(). */
    143 typedef FNRTTHREAD *PFNRTTHREAD;
    144 
    145 /**
    14686 * Thread types.
    14787 * Besides identifying the purpose of the thread, the thread type is
     
    225165} RTTHREADTYPE;
    226166
     167
     168#ifndef IN_RC
     169
     170/**
     171 * Get the thread handle of the current thread.
     172 *
     173 * @returns Thread handle.
     174 */
     175RTDECL(RTTHREAD) RTThreadSelf(void);
     176
     177/**
     178 * Get the thread handle of the current thread, automatically adopting alien
     179 * threads.
     180 *
     181 * @returns Thread handle.
     182 */
     183RTDECL(RTTHREAD) RTThreadSelfAutoAdopt(void);
     184
     185/**
     186 * Get the native thread handle of the current thread.
     187 *
     188 * @returns Native thread handle.
     189 */
     190RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void);
     191
     192/**
     193 * Millisecond granular sleep function.
     194 *
     195 * @returns VINF_SUCCESS on success.
     196 * @returns VERR_INTERRUPTED if a signal or other asynchronous stuff happend
     197 *          which interrupt the peaceful sleep.
     198 * @param   cMillies    Number of milliseconds to sleep.
     199 *                      0 milliseconds means yielding the timeslice - deprecated!
     200 * @remark  See RTThreadNanoSleep() for sleeping for smaller periods of time.
     201 */
     202RTDECL(int) RTThreadSleep(unsigned cMillies);
     203
     204/**
     205 * Yields the CPU.
     206 *
     207 * @returns true if we yielded.
     208 * @returns false if it's probable that we didn't yield.
     209 */
     210RTDECL(bool) RTThreadYield(void);
     211
     212
     213
     214/**
     215 * Thread function.
     216 *
     217 * @returns 0 on success.
     218 * @param   ThreadSelf  Thread handle to this thread.
     219 * @param   pvUser      User argument.
     220 */
     221typedef DECLCALLBACK(int) FNRTTHREAD(RTTHREAD ThreadSelf, void *pvUser);
     222/** Pointer to a FNRTTHREAD(). */
     223typedef FNRTTHREAD *PFNRTTHREAD;
    227224
    228225/**
     
    443440RTDECL(int) RTThreadPoke(RTTHREAD hThread);
    444441
    445 #ifdef IN_RING0
     442# ifdef IN_RING0
    446443
    447444/**
     
    490487    /** In debug builds this will be used to check for cpu migration. */
    491488    RTCPUID         idCpu;
    492 #ifdef RT_OS_WINDOWS
     489#  ifdef RT_OS_WINDOWS
    493490    /** The old IRQL. Don't touch! */
    494491    unsigned char   uchOldIrql;
     
    499496    /** Reserved, MBZ. */
    500497    uint8_t         bReserved3;
    501 # define RTTHREADPREEMPTSTATE_INITIALIZER { NIL_RTCPUID, 255, 0, 0, 0 }
    502 #elif defined(RT_OS_SOLARIS)
     498#   define RTTHREADPREEMPTSTATE_INITIALIZER { NIL_RTCPUID, 255, 0, 0, 0 }
     499#  elif defined(RT_OS_SOLARIS)
    503500    /** The Old PIL. Don't touch! */
    504501    uint32_t        uOldPil;
    505 # define RTTHREADPREEMPTSTATE_INITIALIZER { NIL_RTCPUID, UINT32_MAX }
    506 #else
     502#   define RTTHREADPREEMPTSTATE_INITIALIZER { NIL_RTCPUID, UINT32_MAX }
     503#  else
    507504    /** Reserved, MBZ. */
    508505    uint32_t        u32Reserved;
    509 # define RTTHREADPREEMPTSTATE_INITIALIZER { NIL_RTCPUID, 0 }
    510 #endif
     506#   define RTTHREADPREEMPTSTATE_INITIALIZER { NIL_RTCPUID, 0 }
     507#  endif
    511508} RTTHREADPREEMPTSTATE;
    512509/** Pointer to a preemption state. */
     
    542539RTDECL(bool) RTThreadIsInInterrupt(RTTHREAD hThread);
    543540
    544 #endif /* IN_RING0 */
    545 
    546 
    547 #ifdef IN_RING3
     541# endif /* IN_RING0 */
     542
     543
     544# ifdef IN_RING3
    548545
    549546/**
     
    702699/** @} */
    703700
    704 #endif /* IN_RING3 */
     701# endif /* IN_RING3 */
     702# endif /* !IN_RC */
    705703
    706704/** @} */
  • trunk/include/iprt/types.h

    r25426 r25478  
    14771477/** Pointer to a lock validator record.
    14781478 * The structure definition is found in iprt/lockvalidator.h.  */
    1479 typedef struct RTLOCKVALIDATORREC *PRTLOCKVALIDATORREC;
     1479typedef struct RTLOCKVALIDATORREC          *PRTLOCKVALIDATORREC;
     1480/** Pointer to a lock validator source poisition.
     1481 * The structure definition is found in iprt/lockvalidator.h.  */
     1482typedef struct RTLOCKVALIDATORSRCPOS       *PRTLOCKVALIDATORSRCPOS;
     1483/** Pointer to a const lock validator source poisition.
     1484 * The structure definition is found in iprt/lockvalidator.h.  */
     1485typedef struct RTLOCKVALIDATORSRCPOS const *PCRTLOCKVALIDATORSRCPOS;
    14801486
    14811487
  • trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp

    r25467 r25478  
    6363
    6464
     65/**
     66 * Copy a source position record.
     67 *
     68 * @param   pDst                The destination.
     69 * @param   pSrc                The source.
     70 */
     71DECL_FORCE_INLINE(void) rtLockValidatorCopySrcPos(PRTLOCKVALIDATORSRCPOS pDst, PCRTLOCKVALIDATORSRCPOS pSrc)
     72{
     73    ASMAtomicUoWriteU32(&pDst->uLine,                           pSrc->uLine);
     74    ASMAtomicUoWritePtr((void * volatile *)&pDst->pszFile,      pSrc->pszFile);
     75    ASMAtomicUoWritePtr((void * volatile *)&pDst->pszFunction,  pSrc->pszFunction);
     76    ASMAtomicUoWritePtr((void * volatile *)&pDst->uId,          (void *)pSrc->uId);
     77}
     78
     79
     80/**
     81 * Init a source position record.
     82 *
     83 * @param   pSrcPos             The source position record.
     84 */
     85DECL_FORCE_INLINE(void) rtLockValidatorInitSrcPos(PRTLOCKVALIDATORSRCPOS pSrcPos)
     86{
     87    pSrcPos->pszFile        = NULL;
     88    pSrcPos->pszFunction    = NULL;
     89    pSrcPos->uId            = 0;
     90    pSrcPos->uLine          = 0;
     91#if HC_ARCH_BITS == 64
     92    pSrcPos->u32Padding     = 0;
     93#endif
     94}
     95
    6596
    6697/**
     
    113144{
    114145    pRec->u32Magic      = RTLOCKVALIDATORREC_MAGIC;
    115     pRec->uLine         = 0;
    116     pRec->pszFile       = NULL;
    117     pRec->pszFunction   = NULL;
    118     pRec->uId           = 0;
     146    rtLockValidatorInitSrcPos(&pRec->SrcPos);
    119147    pRec->hThread       = NIL_RTTHREAD;
    120148    pRec->pDown         = NULL;
     
    179207
    180208
    181 RTDECL(int) RTLockValidatorCheckOrder(PRTLOCKVALIDATORREC pRec, RTTHREAD hThread, RTHCUINTPTR uId, RT_SRC_POS_DECL)
     209RTDECL(int) RTLockValidatorCheckOrder(PRTLOCKVALIDATORREC pRec, RTTHREAD hThread, PCRTLOCKVALIDATORSRCPOS pSrcPos)
    182210{
    183211    AssertReturn(pRec->u32Magic == RTLOCKVALIDATORREC_MAGIC, VERR_SEM_LV_INVALID_PARAMETER);
     
    205233
    206234
    207 RTDECL(int) RTLockValidatorRecordRecursion(PRTLOCKVALIDATORREC pRec, RTHCUINTPTR uId, RT_SRC_POS_DECL)
     235RTDECL(int) RTLockValidatorRecordRecursion(PRTLOCKVALIDATORREC pRec, PCRTLOCKVALIDATORSRCPOS pSrcPos)
    208236{
    209237    AssertReturn(pRec->u32Magic == RTLOCKVALIDATORREC_MAGIC, VERR_SEM_LV_INVALID_PARAMETER);
     
    227255
    228256
    229 RTDECL(RTTHREAD) RTLockValidatorSetOwner(PRTLOCKVALIDATORREC pRec, RTTHREAD hThread, RTHCUINTPTR uId, RT_SRC_POS_DECL)
     257RTDECL(RTTHREAD) RTLockValidatorSetOwner(PRTLOCKVALIDATORREC pRec, RTTHREAD hThread, PCRTLOCKVALIDATORSRCPOS pSrcPos)
    230258{
    231259    AssertReturn(pRec->u32Magic == RTLOCKVALIDATORREC_MAGIC, NIL_RTTHREAD);
     
    248276         * Update the record.
    249277         */
    250         ASMAtomicUoWriteU32(&pRec->uLine, iLine);
    251         ASMAtomicUoWritePtr((void * volatile *)&pRec->pszFile,      pszFile);
    252         ASMAtomicUoWritePtr((void * volatile *)&pRec->pszFunction,  pszFunction);
    253         ASMAtomicUoWritePtr((void * volatile *)&pRec->uId,          (void *)uId);
     278        rtLockValidatorCopySrcPos(&pRec->SrcPos, pSrcPos);
    254279        ASMAtomicUoWriteU32(&pRec->cRecursion, 1);
    255 
    256280        ASMAtomicWriteHandle(&pRec->hThread, hThread);
    257281
     
    369393 * @param   pCur            The thread we're deadlocking with.
    370394 * @param   enmState        The sleep state.
    371  * @param   RT_SRC_POS_DECL Where we are going to deadlock.
    372  * @param   uId             Where we are going to deadlock.
     395 * @param   pSrcPos         Where we are going to deadlock.
    373396 */
    374397static void rtLockValidatorComplainAboutDeadlock(PRTLOCKVALIDATORREC pRec, PRTTHREADINT pThread, RTTHREADSTATE enmState,
    375                                                  PRTTHREADINT pCur, RTHCUINTPTR uId, RT_SRC_POS_DECL)
    376 {
    377     AssertMsg1(pCur == pThread ? "!!Deadlock detected!!" : "!!Deadlock exists!!", iLine, pszFile, pszFunction);
     398                                                 PRTTHREADINT pCur, PCRTLOCKVALIDATORSRCPOS pSrcPos)
     399{
     400    AssertMsg1(pCur == pThread ? "!!Deadlock detected!!" : "!!Deadlock exists!!", pSrcPos->uLine, pSrcPos->pszFile, pSrcPos->pszFunction);
    378401
    379402    /*
     
    390413        AssertMsg2(" #%u: %RTthrd/%RTnthrd %s: %s(%u) %RTptr\n",
    391414                   iEntry, pCur, pCur->Core.Key, pCur->szName,
    392                    pCur->LockValidator.pszBlockFile, pCur->LockValidator.uBlockLine,
    393                    pCur->LockValidator.pszBlockFunction, pCur->LockValidator.uBlockId);
     415                   pCur->LockValidator.SrcPos.pszFile, pCur->LockValidator.SrcPos.uLine,
     416                   pCur->LockValidator.SrcPos.pszFunction, pCur->LockValidator.SrcPos.uId);
    394417        PRTTHREADINT  pNext       = NULL;
    395418        RTTHREADSTATE enmCurState = rtThreadGetState(pCur);
     
    418441                    AssertMsg2("     Waiting on %s %p [%s]: Entered %s(%u) %s %p\n",
    419442                               RTThreadStateName(enmCurState), pCurRec->hLock, pCurRec->pszName,
    420                                pCurRec->pszFile, pCurRec->uLine, pCurRec->pszFunction, pCurRec->uId);
     443                               pCurRec->SrcPos.pszFile, pCurRec->SrcPos.uLine, pCurRec->SrcPos.pszFunction, pCurRec->SrcPos.uId);
    421444                    pNext = pCurRec->hThread;
    422445                }
     
    461484RTDECL(int) RTLockValidatorCheckBlocking(PRTLOCKVALIDATORREC pRec, RTTHREAD hThread,
    462485                                         RTTHREADSTATE enmState, bool fRecursiveOk,
    463                                          RTHCUINTPTR uId, RT_SRC_POS_DECL)
     486                                         PCRTLOCKVALIDATORSRCPOS pSrcPos)
    464487{
    465488    /*
     
    482505     * performing deadlock detection.
    483506     */
    484     /** @todo This has to be serialized! The deadlock detection isn't 100% safe!!! */
    485     pThread->LockValidator.pRec             = pRec;
    486     pThread->LockValidator.pszBlockFunction = pszFunction;
    487     pThread->LockValidator.pszBlockFile     = pszFile;
    488     pThread->LockValidator.uBlockLine       = iLine;
    489     pThread->LockValidator.uBlockId         = uId;
    490 
    491     RTThreadBlocking(hThread, enmState);
     507    pThread->LockValidator.pRec = pRec;
     508    rtLockValidatorCopySrcPos(&pThread->LockValidator.SrcPos, pSrcPos);
    492509
    493510    /*
     
    604621     * Ok, if we ever get here, it's most likely a genuine deadlock.
    605622     */
    606     rtLockValidatorComplainAboutDeadlock(pRec, pThread, enmState, pCur, uId, RT_SRC_POS_ARGS);
     623    rtLockValidatorComplainAboutDeadlock(pRec, pThread, enmState, pCur, pSrcPos);
    607624
    608625    rtLockValidatorSerializeDetectionLeave();
  • trunk/src/VBox/Runtime/generic/critsect-generic.cpp

    r25467 r25478  
    244244    ASMAtomicWriteHandle(&pCritSect->NativeThreadOwner, NativeThreadSelf);
    245245#ifdef RTCRITSECT_STRICT
    246     RTLockValidatorSetOwner(pCritSect->pValidatorRec, ThreadSelf, uId, RT_SRC_POS_ARGS);
     246    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API();
     247    RTLockValidatorSetOwner(pCritSect->pValidatorRec, ThreadSelf, &SrcPos);
    247248#endif
    248249
     
    283284    RTNATIVETHREAD  NativeThreadSelf = RTThreadNativeSelf();
    284285#ifdef RTCRITSECT_STRICT
    285     RTTHREAD        hThreadSelf = RTThreadSelfAutoAdopt();
    286     RTLockValidatorCheckOrder(pCritSect->pValidatorRec, hThreadSelf, uId, RT_SRC_POS_ARGS);
     286    RTTHREAD                hThreadSelf = RTThreadSelfAutoAdopt();
     287    RTLOCKVALIDATORSRCPOS   SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API();
     288    RTLockValidatorCheckOrder(pCritSect->pValidatorRec, hThreadSelf, &SrcPos);
    287289#endif
    288290
     
    324326            int rc9 = RTLockValidatorCheckBlocking(pCritSect->pValidatorRec, hThreadSelf, RTTHREADSTATE_CRITSECT,
    325327                                                   !(pCritSect->fFlags & RTCRITSECT_FLAGS_NO_NESTING),
    326                                                    uId, RT_SRC_POS_ARGS);
     328                                                   &SrcPos);
    327329            if (RT_FAILURE(rc9))
    328330            {
     
    330332                return rc9;
    331333            }
    332 #else
     334#endif
    333335            RTThreadBlocking(hThreadSelf, RTTHREADSTATE_CRITSECT);
    334 #endif
    335336
    336337            int rc = RTSemEventWait(pCritSect->EventSem, RT_INDEFINITE_WAIT);
     
    352353    ASMAtomicWriteHandle(&pCritSect->NativeThreadOwner, NativeThreadSelf);
    353354#ifdef RTCRITSECT_STRICT
    354     RTLockValidatorSetOwner(pCritSect->pValidatorRec, hThreadSelf, uId, RT_SRC_POS_ARGS);
     355    RTLockValidatorSetOwner(pCritSect->pValidatorRec, hThreadSelf, &SrcPos);
    355356#endif
    356357
  • trunk/src/VBox/Runtime/include/internal/lockvalidator.h

    r25436 r25478  
    4848    /** What we're blocking on. */
    4949    PRTLOCKVALIDATORREC     pRec;
    50     /** Where we're blocking. */
    51     const char volatile    *pszBlockFunction;
    52     /** Where we're blocking. */
    53     const char volatile    *pszBlockFile;
    54     /** Where we're blocking. */
    55     uint32_t volatile       uBlockLine;
    56     /** Where we're blocking. */
    57     RTHCUINTPTR volatile    uBlockId;
    58 
     50    /** Where we are blocking. */
     51    RTLOCKVALIDATORSRCPOS   SrcPos;
    5952    /** Number of registered write locks, mutexes and critsects that this thread owns. */
    6053    int32_t volatile        cWriteLocks;
  • trunk/src/VBox/Runtime/include/internal/strict.h

    r25467 r25478  
    5858#endif
    5959
    60 #ifdef RTSEMMUTEX_STRICT
    61 # define RTSEMMUTEX_STRICT_POS_DECL             RTHCUINTPTR uId, RT_SRC_POS_DECL
    62 # define RTSEMMUTEX_STRICT_POS_ARGS             uId, RT_SRC_POS_ARGS
    63 #else
    64 # define RTSEMMUTEX_STRICT_POS_DECL             int iDummy
    65 # define RTSEMMUTEX_STRICT_POS_ARGS             0
    66 #endif
    67 
    6860
    6961/** @def RTSEMRW_STRICT
     
    7466#endif
    7567
    76 #ifdef RTSEMRW_STRICT
    77 # define RTSEMRW_STRICT_POS_DECL                RTHCUINTPTR uId, RT_SRC_POS_DECL
    78 # define RTSEMRW_STRICT_POS_ARGS                uId, RT_SRC_POS_ARGS
    79 #else
    80 # define RTSEMRW_STRICT_POS_DECL                int iDummy
    81 # define RTSEMRW_STRICT_POS_ARGS                0
    82 #endif
    83 
    8468
    8569
  • trunk/src/VBox/Runtime/r3/linux/semmutex-linux.cpp

    r25467 r25478  
    167167
    168168
    169 DECL_FORCE_INLINE(int) rtSemMutexRequest(RTSEMMUTEX MutexSem, unsigned cMillies, bool fAutoResume, RTSEMMUTEX_STRICT_POS_DECL)
     169DECL_FORCE_INLINE(int) rtSemMutexRequest(RTSEMMUTEX MutexSem, unsigned cMillies, bool fAutoResume, PCRTLOCKVALIDATORSRCPOS pSrcPos)
    170170{
    171171    /*
     
    178178#ifdef RTSEMMUTEX_STRICT
    179179    RTTHREAD hThreadSelf = RTThreadSelfAutoAdopt();
    180     RTLockValidatorCheckOrder(&pThis->ValidatorRec, hThreadSelf, RTSEMMUTEX_STRICT_POS_ARGS);
     180    RTLockValidatorCheckOrder(&pThis->ValidatorRec, hThreadSelf, pSrcPos);
    181181#endif
    182182
     
    232232#ifdef RTSEMMUTEX_STRICT
    233233                int rc9 = RTLockValidatorCheckBlocking(&pThis->ValidatorRec, hThreadSelf,
    234                                                        RTTHREADSTATE_MUTEX, true, uId, RT_SRC_POS_ARGS);
     234                                                       RTTHREADSTATE_MUTEX, true, pSrcPos);
    235235                if (RT_FAILURE(rc9))
    236236                    return rc9;
    237 #else
     237#endif
    238238                RTThreadBlocking(hThreadSelf, RTTHREADSTATE_MUTEX);
    239 #endif
    240239            }
    241240
     
    300299    ASMAtomicWriteU32(&pThis->cNesting, 1);
    301300#ifdef RTSEMMUTEX_STRICT
    302     RTLockValidatorSetOwner(&pThis->ValidatorRec, hThreadSelf, RTSEMMUTEX_STRICT_POS_ARGS);
     301    RTLockValidatorSetOwner(&pThis->ValidatorRec, hThreadSelf, pSrcPos);
    303302#endif
    304303    return VINF_SUCCESS;
     
    309308{
    310309#ifndef RTSEMMUTEX_STRICT
    311     int rc = rtSemMutexRequest(MutexSem, cMillies, true, RTSEMMUTEX_STRICT_POS_ARGS);
     310    int rc = rtSemMutexRequest(MutexSem, cMillies, true, NULL);
     311#else
     312    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API();
     313    int rc = rtSemMutexRequest(MutexSem, cMillies, true, &SrcPos);
     314#endif
    312315    Assert(rc != VERR_INTERRUPTED);
    313316    return rc;
    314 #else
    315     return RTSemMutexRequestDebug(MutexSem, cMillies, (uintptr_t)ASMReturnAddress(), RT_SRC_POS);
    316 #endif
    317317}
    318318
     
    320320RTDECL(int) RTSemMutexRequestDebug(RTSEMMUTEX MutexSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
    321321{
    322 #ifdef RTSEMMUTEX_STRICT
    323     int rc = rtSemMutexRequest(MutexSem, cMillies, true, RTSEMMUTEX_STRICT_POS_ARGS);
     322    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API();
     323    int rc = rtSemMutexRequest(MutexSem, cMillies, true, &SrcPos);
    324324    Assert(rc != VERR_INTERRUPTED);
    325325    return rc;
     326}
     327
     328
     329RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies)
     330{
     331#ifndef RTSEMMUTEX_STRICT
     332    return rtSemMutexRequest(MutexSem, cMillies, false, NULL);
    326333#else
    327     return RTSemMutexRequest(MutexSem, cMillies);
    328 #endif
    329 }
    330 
    331 
    332 RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies)
    333 {
    334 #ifndef RTSEMMUTEX_STRICT
    335     return rtSemMutexRequest(MutexSem, cMillies, false, RTSEMMUTEX_STRICT_POS_ARGS);
    336 #else
    337     return RTSemMutexRequestNoResumeDebug(MutexSem, cMillies, (uintptr_t)ASMReturnAddress(), RT_SRC_POS);
     334    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API();
     335    return rtSemMutexRequest(MutexSem, cMillies, false, &SrcPos);
    338336#endif
    339337}
     
    342340RTDECL(int) RTSemMutexRequestNoResumeDebug(RTSEMMUTEX MutexSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
    343341{
    344 #ifdef RTSEMMUTEX_STRICT
    345     return rtSemMutexRequest(MutexSem, cMillies, false, RTSEMMUTEX_STRICT_POS_ARGS);
    346 #else
    347     return RTSemMutexRequest(MutexSem, cMillies);
    348 #endif
     342    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API();
     343    return rtSemMutexRequest(MutexSem, cMillies, false, &SrcPos);
    349344}
    350345
  • trunk/src/VBox/Runtime/r3/posix/semmutex-posix.cpp

    r25467 r25478  
    155155
    156156
    157 DECL_FORCE_INLINE(int) rtSemMutexRequest(RTSEMMUTEX MutexSem, unsigned cMillies, RTSEMMUTEX_STRICT_POS_DECL)
     157DECL_FORCE_INLINE(int) rtSemMutexRequest(RTSEMMUTEX MutexSem, unsigned cMillies, PCRTLOCKVALIDATORSRCPOS pSrcPos)
    158158{
    159159    /*
     
    166166#ifdef RTSEMMUTEX_STRICT
    167167    RTTHREAD hThreadSelf = RTThreadSelfAutoAdopt();
    168     RTLockValidatorCheckOrder(&pThis->ValidatorRec, hThreadSelf, RTSEMMUTEX_STRICT_POS_ARGS);
     168    RTLockValidatorCheckOrder(&pThis->ValidatorRec, hThreadSelf, pSrcPos);
    169169#endif
    170170
     
    190190#ifdef RTSEMMUTEX_STRICT
    191191        int rc9 = RTLockValidatorCheckBlocking(&pThis->ValidatorRec, hThreadSelf,
    192                                                RTTHREADSTATE_MUTEX, true, uId, RT_SRC_POS_ARGS);
     192                                               RTTHREADSTATE_MUTEX, true, pSrcPos);
    193193        if (RT_FAILURE(rc9))
    194194            return rc9;
    195 #else
     195#endif
    196196        RTThreadBlocking(hThreadSelf, RTTHREADSTATE_MUTEX);
    197 #endif
    198197    }
    199198
     
    248247    ASMAtomicWriteU32(&pThis->cNesting, 1);
    249248#ifdef RTSEMMUTEX_STRICT
    250     RTLockValidatorSetOwner(&pThis->ValidatorRec, hThreadSelf, RTSEMMUTEX_STRICT_POS_ARGS);
     249    RTLockValidatorSetOwner(&pThis->ValidatorRec, hThreadSelf, pSrcPos);
    251250#endif
    252251
     
    258257{
    259258#ifndef RTSEMMUTEX_STRICT
    260     return rtSemMutexRequest(MutexSem, cMillies, RTSEMMUTEX_STRICT_POS_ARGS);
     259    return rtSemMutexRequest(MutexSem, cMillies, NULL);
    261260#else
    262     return RTSemMutexRequestDebug(MutexSem, cMillies, (uintptr_t)ASMReturnAddress(), RT_SRC_POS);
     261    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API();
     262    return rtSemMutexRequest(MutexSem, cMillies, &SrcPos);
    263263#endif
    264264}
     
    267267RTDECL(int) RTSemMutexRequestDebug(RTSEMMUTEX MutexSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
    268268{
    269 #ifdef RTSEMMUTEX_STRICT
    270     return rtSemMutexRequest(MutexSem, cMillies, RTSEMMUTEX_STRICT_POS_ARGS);
     269    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API();
     270    return rtSemMutexRequest(MutexSem, cMillies, &SrcPos);
     271}
     272
     273
     274RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies)
     275{
     276    /* (EINTR isn't returned by the wait functions we're using.) */
     277#ifndef RTSEMMUTEX_STRICT
     278    return rtSemMutexRequest(MutexSem, cMillies, NULL);
    271279#else
    272     return RTSemMutexRequest(MutexSem, cMillies);
    273 #endif
    274 }
    275 
    276 
    277 RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies)
    278 {
    279     /* EINTR isn't returned by the wait functions we're using. */
    280 #ifndef RTSEMMUTEX_STRICT
    281     return RTSemMutexRequest(MutexSem, cMillies);
    282 #else
    283     return RTSemMutexRequestDebug(MutexSem, cMillies, (uintptr_t)ASMReturnAddress(), RT_SRC_POS);
     280    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API();
     281    return rtSemMutexRequest(MutexSem, cMillies, &SrcPos);
    284282#endif
    285283}
     
    288286RTDECL(int) RTSemMutexRequestNoResumeDebug(RTSEMMUTEX MutexSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
    289287{
    290     /* EINTR isn't returned by the wait functions we're using. */
    291 #ifdef RTSEMMUTEX_STRICT
    292     return RTSemMutexRequestDebug(MutexSem, cMillies, RTSEMMUTEX_STRICT_POS_ARGS);
    293 #else
    294     return RTSemMutexRequest(MutexSem, cMillies);
    295 #endif
     288    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API();
     289    return rtSemMutexRequest(MutexSem, cMillies, &SrcPos);
    296290}
    297291
  • trunk/src/VBox/Runtime/r3/posix/semrw-posix.cpp

    r25467 r25478  
    315315
    316316
    317 DECL_FORCE_INLINE(int) rtSemRWRequestWrite(RTSEMRW RWSem, unsigned cMillies, RTSEMRW_STRICT_POS_DECL)
     317DECL_FORCE_INLINE(int) rtSemRWRequestWrite(RTSEMRW RWSem, unsigned cMillies, PCRTLOCKVALIDATORSRCPOS pSrcPos)
    318318{
    319319    /*
     
    327327#ifdef RTSEMRW_STRICT
    328328    RTTHREAD hThreadSelf = RTThreadSelfAutoAdopt();
    329     RTLockValidatorCheckOrder(&pThis->ValidatorRec, hThreadSelf, RTSEMRW_STRICT_POS_ARGS);
     329    RTLockValidatorCheckOrder(&pThis->ValidatorRec, hThreadSelf, pSrcPos);
    330330#endif
    331331
     
    339339    {
    340340#ifdef RTSEMRW_STRICT
    341         int rc9 = RTLockValidatorRecordRecursion(&pThis->ValidatorRec, RTSEMRW_STRICT_POS_ARGS);
     341        int rc9 = RTLockValidatorRecordRecursion(&pThis->ValidatorRec, pSrcPos);
    342342        if (RT_FAILURE(rc9))
    343343            return rc9;
     
    357357    {
    358358#ifdef RTSEMRW_STRICT
    359         int rc9 = RTLockValidatorCheckBlocking(&pThis->ValidatorRec, hThreadSelf, RTTHREADSTATE_RW_WRITE, true, uId, RT_SRC_POS_ARGS);
     359        int rc9 = RTLockValidatorCheckBlocking(&pThis->ValidatorRec, hThreadSelf, RTTHREADSTATE_RW_WRITE, true, pSrcPos);
    360360        if (RT_FAILURE(rc9))
    361361            return rc9;
    362 #else
     362#endif
    363363        RTThreadBlocking(hThreadSelf, RTTHREADSTATE_RW_WRITE);
    364 #endif
    365364    }
    366365
     
    412411    pThis->cWrites = 1;
    413412#ifdef RTSEMRW_STRICT
    414     RTLockValidatorSetOwner(&pThis->ValidatorRec, hThreadSelf, RTSEMRW_STRICT_POS_ARGS);
     413    RTLockValidatorSetOwner(&pThis->ValidatorRec, hThreadSelf, pSrcPos);
    415414#endif
    416415    return VINF_SUCCESS;
     
    421420{
    422421#ifndef RTSEMRW_STRICT
    423     return rtSemRWRequestWrite(RWSem, cMillies, RTSEMRW_STRICT_POS_ARGS);
     422    return rtSemRWRequestWrite(RWSem, cMillies, NULL);
    424423#else
    425     return RTSemRWRequestWriteDebug(RWSem, cMillies, (uintptr_t)ASMReturnAddress(), RT_SRC_POS);
     424    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API();
     425    return rtSemRWRequestWrite(RWSem, cMillies, &SrcPos);
    426426#endif
    427427}
     
    430430RTDECL(int) RTSemRWRequestWriteDebug(RTSEMRW RWSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
    431431{
    432 #ifdef RTSEMRW_STRICT
    433     return rtSemRWRequestWrite(RWSem, cMillies, RTSEMRW_STRICT_POS_ARGS);
    434 #else
    435     return RTSemRWRequestWrite(RWSem, cMillies);
    436 #endif
     432    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API();
     433    return rtSemRWRequestWrite(RWSem, cMillies, &SrcPos);
    437434}
    438435
     
    442439    /* EINTR isn't returned by the wait functions we're using. */
    443440#ifndef RTSEMRW_STRICT
    444     return RTSemRWRequestWrite(RWSem, cMillies);
     441    return rtSemRWRequestWrite(RWSem, cMillies, NULL);
    445442#else
    446     return RTSemRWRequestWriteDebug(RWSem, cMillies, (uintptr_t)ASMReturnAddress(), RT_SRC_POS);
     443    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API();
     444    return rtSemRWRequestWrite(RWSem, cMillies, &SrcPos);
    447445#endif
    448446}
     
    452450{
    453451    /* EINTR isn't returned by the wait functions we're using. */
    454 #ifdef RTSEMRW_STRICT
    455     return RTSemRWRequestWriteDebug(RWSem, cMillies, RTSEMRW_STRICT_POS_ARGS);
    456 #else
    457     return RTSemRWRequestWrite(RWSem, cMillies);
    458 #endif
     452    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API();
     453    return rtSemRWRequestWrite(RWSem, cMillies, &SrcPos);
    459454}
    460455
  • trunk/src/VBox/Runtime/r3/win/semmutex-win.cpp

    r25467 r25478  
    138138 *
    139139 * @returns Same as RTSEmMutexRequestNoResume
    140  * @param   MutexSem                    The mutex handle.
    141  * @param   cMillies                    The number of milliseconds to wait.
    142  * @param   TSEMMUTEX_STRICT_POS_DECL   The source position of the caller.
     140 * @param   MutexSem            The mutex handle.
     141 * @param   cMillies            The number of milliseconds to wait.
     142 * @param   pSrcPos             The source position of the caller.
    143143 */
    144 DECL_FORCE_INLINE(int) rtSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies, RTSEMMUTEX_STRICT_POS_DECL)
     144DECL_FORCE_INLINE(int) rtSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies, PCRTLOCKVALIDATORSRCPOS pSrcPos)
    145145{
    146146    /*
     
    153153#ifdef RTSEMMUTEX_STRICT
    154154    RTTHREAD hThreadSelf = RTThreadSelfAutoAdopt();
    155     RTLockValidatorCheckOrder(&pThis->ValidatorRec, hThreadSelf, RTSEMMUTEX_STRICT_POS_ARGS);
     155    RTLockValidatorCheckOrder(&pThis->ValidatorRec, hThreadSelf, pSrcPos);
    156156#else
    157157    RTTHREAD hThreadSelf = RTThreadSelf();
     
    165165#ifdef RTSEMMUTEX_STRICT
    166166        int rc9 = RTLockValidatorCheckBlocking(&pThis->ValidatorRec, hThreadSelf,
    167                                                RTTHREADSTATE_MUTEX, true, uId, RT_SRC_POS_ARGS);
     167                                               RTTHREADSTATE_MUTEX, true, pSrcPos);
    168168        if (RT_FAILURE(rc9))
    169169            return rc9;
    170 #else
     170#endif
    171171        RTThreadBlocking(hThreadSelf, RTTHREADSTATE_MUTEX);
    172 #endif
    173172    }
    174173    int rc = WaitForSingleObjectEx(pThis->hMtx,
     
    180179        case WAIT_OBJECT_0:
    181180#ifdef RTSEMMUTEX_STRICT
    182             RTLockValidatorSetOwner(&pThis->ValidatorRec, hThreadSelf, RTSEMMUTEX_STRICT_POS_ARGS);
     181            RTLockValidatorSetOwner(&pThis->ValidatorRec, hThreadSelf, pSrcPos);
    183182#endif
    184183            return VINF_SUCCESS;
     
    204203{
    205204#ifndef RTSEMMUTEX_STRICT
    206     return rtSemMutexRequestNoResume(MutexSem, cMillies, RTSEMMUTEX_STRICT_POS_ARGS);
     205    return rtSemMutexRequestNoResume(MutexSem, cMillies, NULL);
    207206#else
    208     return RTSemMutexRequestNoResumeDebug(MutexSem, cMillies, (uintptr_t)ASMReturnAddress(), RT_SRC_POS);
     207    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API();
     208    return rtSemMutexRequestNoResume(MutexSem, cMillies, &SrcPos);
    209209#endif
    210210}
     
    213213RTDECL(int) RTSemMutexRequestNoResumeDebug(RTSEMMUTEX MutexSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
    214214{
    215 #ifdef RTSEMMUTEX_STRICT
    216     return rtSemMutexRequestNoResume(MutexSem, cMillies, RTSEMMUTEX_STRICT_POS_ARGS);
    217 #else
    218     return RTSemMutexRequestNoResume(MutexSem, cMillies);
    219 #endif
     215    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API();
     216    return rtSemMutexRequestNoResume(MutexSem, cMillies, &SrcPos);
    220217}
    221218
  • trunk/src/VBox/VMM/PDMCritSect.cpp

    r25406 r25478  
    396396
    397397#ifdef PDMCRITSECT_STRICT
    398     const char * const pszFile      = pCritSect->s.Core.pValidatorRec->pszFile;
    399     const char * const pszFunction  = pCritSect->s.Core.pValidatorRec->pszFunction;
    400     uint32_t     const iLine        = pCritSect->s.Core.pValidatorRec->uLine;
    401     RTHCUINTPTR  const uId          = pCritSect->s.Core.pValidatorRec->uId;
     398    RTLOCKVALIDATORSRCPOS const SrcPos = pCritSect->s.Core.pValidatorRec->SrcPos;
    402399#endif
    403400    PDMCritSectLeave(pCritSect);
     
    423420
    424421#ifdef PDMCRITSECT_STRICT
    425     int rc = PDMCritSectEnterDebug(pCritSect, VERR_INTERNAL_ERROR, uId, pszFile, iLine, pszFunction);
     422    int rc = PDMCritSectEnterDebug(pCritSect, VERR_INTERNAL_ERROR,
     423                                   SrcPos.uId, SrcPos.pszFile, SrcPos.uLine, SrcPos.pszFunction);
    426424#else
    427425    int rc = PDMCritSectEnter(pCritSect, VERR_INTERNAL_ERROR);
  • trunk/src/VBox/VMM/VMMAll/PDMAllCritSect.cpp

    r25467 r25478  
    5252#define PDMCRITSECT_SPIN_COUNT_RC       256
    5353
    54 #ifdef PDMCRITSECT_STRICT
    55 # define PDMCRITSECT_STRICT_POS_DECL            RTHCUINTPTR uId, RT_SRC_POS_DECL
    56 # define PDMCRITSECT_STRICT_POS_ARGS            uId, RT_SRC_POS_ARGS
    57 # define PDMCRITSECT_STRICT_BLOCK_RET(hThread, pRec, fRecursive) \
    58     do { \
    59         int rc9 = RTLockValidatorCheckBlocking(pRec, (hThread), RTTHREADSTATE_CRITSECT, fRecursive, uId, RT_SRC_POS_ARGS); \
    60         if (RT_FAILURE(rc9)) \
    61             return rc9; \
    62     } while (0)
    63 #else
    64 # define PDMCRITSECT_STRICT_POS_DECL            int iDummy
    65 # define PDMCRITSECT_STRICT_POS_ARGS            0
    66 # define PDMCRITSECT_STRICT_BLOCK_RET(hThread, pRec, fRecursive) \
    67                                                 RTThreadBlocking((hThread), RTTHREADSTATE_CRITSECT)
    68 #endif
    69 #define  PDMCRITSECT_STRICT_UNBLOCK(hThread)    RTThreadUnblocked((hThread), RTTHREADSTATE_CRITSECT)
    7054
    7155/* Undefine the automatic VBOX_STRICT API mappings. */
     
    10488 * @param   hNativeSelf     The native handle of this thread.
    10589 */
    106 DECL_FORCE_INLINE(int) pdmCritSectEnterFirst(PPDMCRITSECT pCritSect, RTNATIVETHREAD hNativeSelf, PDMCRITSECT_STRICT_POS_DECL)
     90DECL_FORCE_INLINE(int) pdmCritSectEnterFirst(PPDMCRITSECT pCritSect, RTNATIVETHREAD hNativeSelf, PCRTLOCKVALIDATORSRCPOS pSrcPos)
    10791{
    10892    AssertMsg(pCritSect->s.Core.NativeThreadOwner == NIL_RTNATIVETHREAD, ("NativeThreadOwner=%p\n", pCritSect->s.Core.NativeThreadOwner));
     
    11397
    11498# ifdef PDMCRITSECT_STRICT
    115     RTLockValidatorSetOwner(pCritSect->s.Core.pValidatorRec, NIL_RTTHREAD, PDMCRITSECT_STRICT_POS_ARGS);
     99    RTLockValidatorSetOwner(pCritSect->s.Core.pValidatorRec, NIL_RTTHREAD, pSrcPos);
    116100# endif
    117101
     
    129113 * @param   hNativeSelf         The native thread handle.
    130114 */
    131 static int pdmR3CritSectEnterContended(PPDMCRITSECT pCritSect, RTNATIVETHREAD hNativeSelf, PDMCRITSECT_STRICT_POS_DECL)
     115static int pdmR3CritSectEnterContended(PPDMCRITSECT pCritSect, RTNATIVETHREAD hNativeSelf, PCRTLOCKVALIDATORSRCPOS pSrcPos)
    132116{
    133117    /*
     
    135119     */
    136120    if (ASMAtomicIncS32(&pCritSect->s.Core.cLockers) == 0)
    137         return pdmCritSectEnterFirst(pCritSect, hNativeSelf, PDMCRITSECT_STRICT_POS_ARGS);
     121        return pdmCritSectEnterFirst(pCritSect, hNativeSelf, pSrcPos);
    138122    STAM_COUNTER_INC(&pCritSect->s.StatContentionR3);
    139123
     
    141125     * The wait loop.
    142126     */
    143     PSUPDRVSESSION  pSession = pCritSect->s.CTX_SUFF(pVM)->pSession;
    144     SUPSEMEVENT     hEvent   = (SUPSEMEVENT)pCritSect->s.Core.EventSem;
     127    PSUPDRVSESSION  pSession    = pCritSect->s.CTX_SUFF(pVM)->pSession;
     128    SUPSEMEVENT     hEvent      = (SUPSEMEVENT)pCritSect->s.Core.EventSem;
    145129# ifdef PDMCRITSECT_STRICT
    146     RTTHREAD        hSelf    = RTThreadSelfAutoAdopt();
    147     int rc2 = RTLockValidatorCheckOrder(pCritSect->s.Core.pValidatorRec, hSelf, 0, NULL, 0, NULL);
     130    RTTHREAD        hThreadSelf = RTThreadSelfAutoAdopt();
     131    int rc2 = RTLockValidatorCheckOrder(pCritSect->s.Core.pValidatorRec, hThreadSelf, pSrcPos);
    148132    if (RT_FAILURE(rc2))
    149133        return rc2;
    150134# else
    151     RTTHREAD        hSelf    = RTThreadSelf();
     135    RTTHREAD        hThreadSelf = RTThreadSelf();
    152136# endif
    153137    for (;;)
    154138    {
    155         PDMCRITSECT_STRICT_BLOCK_RET(hSelf, pCritSect->s.Core.pValidatorRec, !(pCritSect->s.Core.fFlags & RTCRITSECT_FLAGS_NO_NESTING));
     139# ifdef PDMCRITSECT_STRICT
     140        int rc9 = RTLockValidatorCheckBlocking(pCritSect->s.Core.pValidatorRec, hThreadSelf, RTTHREADSTATE_CRITSECT,
     141                                               !(pCritSect->s.Core.fFlags & RTCRITSECT_FLAGS_NO_NESTING), pSrcPos);
     142        if (RT_FAILURE(rc9))
     143            return rc9;
     144# endif
     145
     146        RTThreadBlocking(hThreadSelf, RTTHREADSTATE_CRITSECT);
    156147        int rc = SUPSemEventWaitNoResume(pSession, hEvent, RT_INDEFINITE_WAIT);
    157         PDMCRITSECT_STRICT_UNBLOCK(hSelf);
     148        RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_CRITSECT);
     149
    158150        if (RT_UNLIKELY(pCritSect->s.Core.u32Magic != RTCRITSECT_MAGIC))
    159151            return VERR_SEM_DESTROYED;
    160152        if (rc == VINF_SUCCESS)
    161             return pdmCritSectEnterFirst(pCritSect, hNativeSelf, PDMCRITSECT_STRICT_POS_ARGS);
     153            return pdmCritSectEnterFirst(pCritSect, hNativeSelf, pSrcPos);
    162154        AssertMsg(rc == VERR_INTERRUPTED, ("rc=%Rrc\n", rc));
    163155    }
     
    178170 *                              and the section is busy.
    179171 */
    180 DECL_FORCE_INLINE(int) pdmCritSectEnter(PPDMCRITSECT pCritSect, int rcBusy, PDMCRITSECT_STRICT_POS_DECL)
     172DECL_FORCE_INLINE(int) pdmCritSectEnter(PPDMCRITSECT pCritSect, int rcBusy, PCRTLOCKVALIDATORSRCPOS pSrcPos)
    181173{
    182174    Assert(pCritSect->s.Core.cNestings < 8);  /* useful to catch incorrect locking */
     
    195187    /* Not owned ... */
    196188    if (ASMAtomicCmpXchgS32(&pCritSect->s.Core.cLockers, 0, -1))
    197         return pdmCritSectEnterFirst(pCritSect, hNativeSelf, PDMCRITSECT_STRICT_POS_ARGS);
     189        return pdmCritSectEnterFirst(pCritSect, hNativeSelf, pSrcPos);
    198190
    199191    /* ... or nested. */
     
    215207    {
    216208        if (ASMAtomicCmpXchgS32(&pCritSect->s.Core.cLockers, 0, -1))
    217             return pdmCritSectEnterFirst(pCritSect, hNativeSelf, PDMCRITSECT_STRICT_POS_ARGS);
     209            return pdmCritSectEnterFirst(pCritSect, hNativeSelf, pSrcPos);
    218210        ASMNopPause();
    219211        /** @todo Should use monitor/mwait on e.g. &cLockers here, possibly with a
     
    228220     * Take the slow path.
    229221     */
    230     return pdmR3CritSectEnterContended(pCritSect, hNativeSelf, PDMCRITSECT_STRICT_POS_ARGS);
     222    return pdmR3CritSectEnterContended(pCritSect, hNativeSelf, pSrcPos);
    231223#else
    232224    /*
     
    254246{
    255247#ifndef PDMCRITSECT_STRICT
    256     return pdmCritSectEnter(pCritSect, rcBusy, PDMCRITSECT_STRICT_POS_ARGS);
    257 #else
    258     /* No need for a second code instance. */
    259     return PDMCritSectEnterDebug(pCritSect, rcBusy, (uintptr_t)ASMReturnAddress(), RT_SRC_POS);
     248    return pdmCritSectEnter(pCritSect, rcBusy, NULL);
     249#else
     250    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API();
     251    return pdmCritSectEnter(pCritSect, rcBusy, &SrcPos);
    260252#endif
    261253}
     
    283275{
    284276#ifdef PDMCRITSECT_STRICT
    285     return pdmCritSectEnter(pCritSect, rcBusy, PDMCRITSECT_STRICT_POS_ARGS);
    286 #else
    287     /* No need for a second code instance. */
    288     return PDMCritSectEnter(pCritSect, rcBusy);
     277    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API();
     278    return pdmCritSectEnter(pCritSect, rcBusy, &SrcPos);
     279#else
     280    return pdmCritSectEnter(pCritSect, rcBusy, NULL);
    289281#endif
    290282}
     
    301293 * @param   pCritSect   The critical section.
    302294 */
    303 static int pdmCritSectTryEnter(PPDMCRITSECT pCritSect, PDMCRITSECT_STRICT_POS_DECL)
     295static int pdmCritSectTryEnter(PPDMCRITSECT pCritSect, PCRTLOCKVALIDATORSRCPOS pSrcPos)
    304296{
    305297    /*
     
    316308    /* Not owned ... */
    317309    if (ASMAtomicCmpXchgS32(&pCritSect->s.Core.cLockers, 0, -1))
    318         return pdmCritSectEnterFirst(pCritSect, hNativeSelf, PDMCRITSECT_STRICT_POS_ARGS);
     310        return pdmCritSectEnterFirst(pCritSect, hNativeSelf, pSrcPos);
    319311
    320312    /* ... or nested. */
     
    355347{
    356348#ifndef PDMCRITSECT_STRICT
    357     return pdmCritSectTryEnter(pCritSect, PDMCRITSECT_STRICT_POS_ARGS);
    358 #else
    359     /* No need for a second code instance. */
    360     return PDMCritSectTryEnterDebug(pCritSect, (uintptr_t)ASMReturnAddress(), RT_SRC_POS);
     349    return pdmCritSectTryEnter(pCritSect, NULL);
     350#else
     351    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API();
     352    return pdmCritSectTryEnter(pCritSect, &SrcPos);
    361353#endif
    362354}
     
    383375{
    384376#ifdef PDMCRITSECT_STRICT
    385     return pdmCritSectTryEnter(pCritSect, PDMCRITSECT_STRICT_POS_ARGS);
    386 #else
    387     /* No need for a second code instance. */
    388     return PDMCritSectTryEnter(pCritSect);
     377    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API();
     378    return pdmCritSectTryEnter(pCritSect, &SrcPos);
     379#else
     380    return pdmCritSectTryEnter(pCritSect, NULL);
    389381#endif
    390382}
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