VirtualBox

Changeset 25620 in vbox


Ignore:
Timestamp:
Jan 2, 2010 10:18:07 PM (15 years ago)
Author:
vboxsync
Message:

iprt/semaphore.h: Added Debug wrappers for all the RW semaphores.

Location:
trunk
Files:
3 edited

Legend:

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

    r25616 r25620  
    491491 */
    492492RTDECL(int)   RTSemRWRequestReadNoResume(RTSEMRW RWSem, unsigned cMillies);
     493
     494/**
     495 * Debug version of RTSemRWRequestRead that tracks the location.
     496 *
     497 * @returns iprt status code.
     498 * @retval  VINF_SUCCESS on success.
     499 * @retval  VERR_INTERRUPT if the wait was interrupted.
     500 * @retval  VERR_INVALID_HANDLE if RWSem is invalid.
     501 *
     502 * @param   RWSem       The Read/Write semaphore to request read access to.
     503 * @param   cMillies    The number of milliseconds to wait.
     504 * @param   uId                 Some kind of locking location ID.  Typically a
     505 *                              return address up the stack.  Optional (0).
     506 * @param   pszFile             The file where the lock is being acquired from.
     507 *                              Optional.
     508 * @param   iLine               The line number in that file.  Optional (0).
     509 * @param   pszFunction         The functionn where the lock is being acquired
     510 *                              from.  Optional.
     511 */
     512RTDECL(int)   RTSemRWRequestReadDebug(RTSEMRW RWSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL);
     513
     514/**
     515 * Debug version of RTSemRWRequestWriteNoResume that tracks the location.
     516 *
     517 * @returns iprt status code.
     518 * @retval  VINF_SUCCESS on success.
     519 * @retval  VERR_INTERRUPT if the wait was interrupted.
     520 * @retval  VERR_INVALID_HANDLE if RWSem is invalid.
     521 *
     522 * @param   RWSem       The Read/Write semaphore to request read access to.
     523 * @param   cMillies    The number of milliseconds to wait.
     524 * @param   uId                 Some kind of locking location ID.  Typically a
     525 *                              return address up the stack.  Optional (0).
     526 * @param   pszFile             The file where the lock is being acquired from.
     527 *                              Optional.
     528 * @param   iLine               The line number in that file.  Optional (0).
     529 * @param   pszFunction         The functionn where the lock is being acquired
     530 *                              from.  Optional.
     531 */
     532RTDECL(int)   RTSemRWRequestReadNoResumeDebug(RTSEMRW RWSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL);
    493533
    494534/**
     
    605645 */
    606646RTDECL(uint32_t) RTSemRWGetReadCount(RTSEMRW RWSem);
     647
     648/* Strict build: Remap the four request calls to the debug versions. */
     649#ifdef RT_STRICT
     650# ifdef ___iprt_asm_h
     651#  define RTSemRWRequestRead(pCritSect, cMillies)           RTSemRWRequestReadDebug((pCritSect), (cMillies), (uintptr_t)ASMReturnAddress(), RT_SRC_POS)
     652#  define RTSemRWRequestReadNoResume(pCritSect, cMillies)   RTSemRWRequestReadNoResumeDebug((pCritSect), (cMillies), (uintptr_t)ASMReturnAddress(), RT_SRC_POS)
     653#  define RTSemRWRequestWrite(pCritSect, cMillies)          RTSemRWRequestWriteDebug((pCritSect), (cMillies), (uintptr_t)ASMReturnAddress(), RT_SRC_POS)
     654#  define RTSemRWRequestWriteNoResume(pCritSect, cMillies)  RTSemRWRequestWriteNoResumeDebug((pCritSect), (cMillies), (uintptr_t)ASMReturnAddress(), RT_SRC_POS)
     655# else
     656#  define RTSemRWRequestRead(pCritSect, cMillies)           RTSemRWRequestReadDebug((pCritSect), (cMillies), 0, RT_SRC_POS)
     657#  define RTSemRWRequestReadNoResume(pCritSect, cMillies)   RTSemRWRequestReadNoResumeDebug((pCritSect), (cMillies), 0, RT_SRC_POS)
     658#  define RTSemRWRequestWrite(pCritSect, cMillies)          RTSemRWRequestWriteDebug((pCritSect), (cMillies), 0, RT_SRC_POS)
     659#  define RTSemRWRequestWriteNoResume(pCritSect, cMillies)  RTSemRWRequestWriteNoResumeDebug((pCritSect), (cMillies), 0, RT_SRC_POS)
     660# endif
     661#endif
    607662
    608663/** @} */
  • trunk/src/VBox/Runtime/generic/semrw-generic.cpp

    r25618 r25620  
    9191
    9292
     93/* No debug wrapping here. */
     94#undef RTSemRWRequestRead
     95#undef RTSemRWRequestReadNoResume
     96#undef RTSemRWRequestWrite
     97#undef RTSemRWRequestWriteNoResume
     98
    9399
    94100RTDECL(int) RTSemRWCreate(PRTSEMRW pRWSem)
     
    217223
    218224
    219 RTDECL(int) RTSemRWRequestRead(RTSEMRW RWSem, unsigned cMillies)
    220 {
    221     PRTLOCKVALSRCPOS        pSrcPos = NULL;
    222 
     225DECL_FORCE_INLINE(int) rtSemRWRequestRead(RTSEMRW RWSem, unsigned cMillies, bool fInterruptible, PCRTLOCKVALSRCPOS pSrcPos)
     226{
    223227    /*
    224228     * Validate handle.
     
    326330        RTThreadBlocking(hThreadSelf, RTTHREADSTATE_RW_READ);
    327331#endif
    328         int rcWait = rc = RTSemEventMultiWait(pThis->ReadEvent, cMillies);
     332        int rcWait;
     333        if (fInterruptible)
     334            rcWait = rc = RTSemEventMultiWaitNoResume(pThis->ReadEvent, cMillies);
     335        else
     336            rcWait = rc = RTSemEventMultiWait(pThis->ReadEvent, cMillies);
    329337        RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_RW_READ);
    330338        if (RT_FAILURE(rc) && rc != VERR_TIMEOUT) /* handle timeout below */
     
    382390    return rc;
    383391}
     392
     393
     394RTDECL(int) RTSemRWRequestRead(RTSEMRW RWSem, unsigned cMillies)
     395{
     396#ifndef RTSEMRW_STRICT
     397    return rtSemRWRequestRead(RWSem, cMillies, false, NULL);
     398#else
     399    RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_NORMAL_API();
     400    return rtSemRWRequestRead(RWSem, cMillies, false, &SrcPos);
     401#endif
     402}
    384403RT_EXPORT_SYMBOL(RTSemRWRequestRead);
    385404
    386405
     406RTDECL(int) RTSemRWRequestReadDebug(RTSEMRW RWSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
     407{
     408    RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_DEBUG_API();
     409    return rtSemRWRequestRead(RWSem, cMillies, false, &SrcPos);
     410}
     411RT_EXPORT_SYMBOL(RTSemRWRequestReadDebug);
     412
     413
    387414RTDECL(int) RTSemRWRequestReadNoResume(RTSEMRW RWSem, unsigned cMillies)
    388415{
    389     return RTSemRWRequestRead(RWSem, cMillies);
     416#ifndef RTSEMRW_STRICT
     417    return rtSemRWRequestRead(RWSem, cMillies, true, NULL);
     418#else
     419    RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_NORMAL_API();
     420    return rtSemRWRequestRead(RWSem, cMillies, true, &SrcPos);
     421#endif
    390422}
    391423RT_EXPORT_SYMBOL(RTSemRWRequestReadNoResume);
     424
     425
     426RTDECL(int) RTSemRWRequestReadNoResumeDebug(RTSEMRW RWSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
     427{
     428    RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_DEBUG_API();
     429    return rtSemRWRequestRead(RWSem, cMillies, true, &SrcPos);
     430}
     431RT_EXPORT_SYMBOL(RTSemRWRequestReadNoResumeDebug);
    392432
    393433
     
    472512
    473513
    474 RTDECL(int) RTSemRWRequestWrite(RTSEMRW RWSem, unsigned cMillies)
    475 {
    476     PRTLOCKVALSRCPOS        pSrcPos = NULL;
    477 
     514DECL_FORCE_INLINE(int) rtSemRWRequestWrite(RTSEMRW RWSem, unsigned cMillies, bool fInterruptible, PCRTLOCKVALSRCPOS pSrcPos)
     515{
    478516    /*
    479517     * Validate handle.
     
    580618        RTThreadBlocking(hThreadSelf, RTTHREADSTATE_RW_WRITE);
    581619#endif
    582         int rcWait = rc = RTSemEventWait(pThis->WriteEvent, cMillies);
     620        int rcWait;
     621        if (fInterruptible)
     622            rcWait = rc = RTSemEventWaitNoResume(pThis->WriteEvent, cMillies);
     623        else
     624            rcWait = rc = RTSemEventWait(pThis->WriteEvent, cMillies);
    583625        RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_RW_WRITE);
    584626        if (RT_UNLIKELY(RT_FAILURE_NP(rc) && rc != VERR_TIMEOUT)) /* timeouts are handled below */
     
    651693    return rc;
    652694}
     695
     696
     697RTDECL(int) RTSemRWRequestWrite(RTSEMRW RWSem, unsigned cMillies)
     698{
     699#ifndef RTSEMRW_STRICT
     700    return rtSemRWRequestWrite(RWSem, cMillies, false, NULL);
     701#else
     702    RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_NORMAL_API();
     703    return rtSemRWRequestWrite(RWSem, cMillies, false, &SrcPos);
     704#endif
     705}
    653706RT_EXPORT_SYMBOL(RTSemRWRequestWrite);
    654707
    655708
     709RTDECL(int) RTSemRWRequestWriteDebug(RTSEMRW RWSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
     710{
     711    RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_DEBUG_API();
     712    return rtSemRWRequestWrite(RWSem, cMillies, false, &SrcPos);
     713}
     714RT_EXPORT_SYMBOL(RTSemRWRequestWriteDebug);
     715
     716
    656717RTDECL(int) RTSemRWRequestWriteNoResume(RTSEMRW RWSem, unsigned cMillies)
    657718{
    658     return RTSemRWRequestWrite(RWSem, cMillies);
     719#ifndef RTSEMRW_STRICT
     720    return rtSemRWRequestWrite(RWSem, cMillies, true, NULL);
     721#else
     722    RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_NORMAL_API();
     723    return rtSemRWRequestWrite(RWSem, cMillies, true, &SrcPos);
     724#endif
    659725}
    660726RT_EXPORT_SYMBOL(RTSemRWRequestWriteNoResume);
     727
     728
     729RTDECL(int) RTSemRWRequestWriteNoResumeDebug(RTSEMRW RWSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
     730{
     731    RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_DEBUG_API();
     732    return rtSemRWRequestWrite(RWSem, cMillies, true, &SrcPos);
     733}
     734RT_EXPORT_SYMBOL(RTSemRWRequestWriteNoResumeDebug);
    661735
    662736
  • trunk/src/VBox/Runtime/r3/posix/semrw-posix.cpp

    r25618 r25620  
    9393
    9494
     95/* No debug wrapping here. */
     96#undef RTSemRWRequestRead
     97#undef RTSemRWRequestReadNoResume
     98#undef RTSemRWRequestWrite
     99#undef RTSemRWRequestWriteNoResume
     100
     101
    95102RTDECL(int) RTSemRWCreate(PRTSEMRW pRWSem)
    96103{
     
    180187
    181188
    182 RTDECL(int) RTSemRWRequestRead(RTSEMRW RWSem, unsigned cMillies)
    183 {
    184     PRTLOCKVALSRCPOS pSrcPos = NULL;
    185 
     189DECL_FORCE_INLINE(int) rtSemRWRequestRead(RTSEMRW RWSem, unsigned cMillies, PCRTLOCKVALSRCPOS pSrcPos)
     190{
    186191    /*
    187192     * Validate input.
     
    281286
    282287
     288RTDECL(int) RTSemRWRequestRead(RTSEMRW RWSem, unsigned cMillies)
     289{
     290#ifndef RTSEMRW_STRICT
     291    return rtSemRWRequestRead(RWSem, cMillies, NULL);
     292#else
     293    RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_NORMAL_API();
     294    return rtSemRWRequestRead(RWSem, cMillies, &SrcPos);
     295#endif
     296}
     297
     298
     299RTDECL(int) RTSemRWRequestReadDebug(RTSEMRW RWSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
     300{
     301    RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_DEBUG_API();
     302    return rtSemRWRequestRead(RWSem, cMillies, &SrcPos);
     303}
     304
     305
    283306RTDECL(int) RTSemRWRequestReadNoResume(RTSEMRW RWSem, unsigned cMillies)
    284307{
    285308    /* EINTR isn't returned by the wait functions we're using. */
    286     return RTSemRWRequestRead(RWSem, cMillies);
     309#ifndef RTSEMRW_STRICT
     310    return rtSemRWRequestRead(RWSem, cMillies, NULL);
     311#else
     312    RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_NORMAL_API();
     313    return rtSemRWRequestRead(RWSem, cMillies, &SrcPos);
     314#endif
     315}
     316
     317
     318RTDECL(int) RTSemRWRequestReadNoResumeDebug(RTSEMRW RWSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
     319{
     320    RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_DEBUG_API();
     321    return rtSemRWRequestRead(RWSem, cMillies, &SrcPos);
    287322}
    288323
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