VirtualBox

Changeset 25722 in vbox


Ignore:
Timestamp:
Jan 11, 2010 2:22:03 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
56464
Message:

iprt/RTSemFastMutex: A little cleanup.

Location:
trunk
Files:
9 edited

Legend:

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

    r25721 r25722  
    484484 *
    485485 * @returns iprt status code.
    486  * @param   pMutexSem   Where to store the mutex semaphore handle.
     486 * @param   phFastMtx           Where to store the handle to the newly created
     487 *                              fast mutex semaphore.
    487488 *
    488489 * @remarks Fast mutex semaphores are not recursive.
    489490 */
    490 RTDECL(int)  RTSemFastMutexCreate(PRTSEMFASTMUTEX pMutexSem);
     491RTDECL(int)  RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx);
    491492
    492493/**
     
    494495 *
    495496 * @returns iprt status code.
    496  * @param   hMutexSem    The mutex semaphore to destroy.
    497  */
    498 RTDECL(int)  RTSemFastMutexDestroy(RTSEMFASTMUTEX hMutexSem);
     497 * @param   hFastMtx            Handle to the fast mutex semaphore.  NIL is
     498 *                              quietly ignored (VINF_SUCCESS).
     499 */
     500RTDECL(int)  RTSemFastMutexDestroy(RTSEMFASTMUTEX hFastMtx);
    499501
    500502/**
     
    506508 *
    507509 * @returns iprt status code.
    508  * @param   hMutexSem    The mutex semaphore to request ownership over.
    509  */
    510 RTDECL(int)  RTSemFastMutexRequest(RTSEMFASTMUTEX hMutexSem);
     510 * @param   hFastMtx            Handle to the fast mutex semaphore.
     511 */
     512RTDECL(int)  RTSemFastMutexRequest(RTSEMFASTMUTEX hFastMtx);
    511513
    512514/**
     
    514516 *
    515517 * @returns iprt status code.
    516  * @param   hMutexSem    The mutex to release the ownership of.
    517  *                      It goes without saying the the calling thread must own it.
    518  */
    519 RTDECL(int)  RTSemFastMutexRelease(RTSEMFASTMUTEX hMutexSem);
     518 * @param   hFastMtx            Handle to the fast mutex semaphore.  It goes
     519 *                              without saying the the calling thread must own
     520 *                              it.
     521 */
     522RTDECL(int)  RTSemFastMutexRelease(RTSEMFASTMUTEX hFastMtx);
    520523
    521524/** @} */
  • trunk/src/VBox/Runtime/generic/semfastmutex-generic.cpp

    r21533 r25722  
    4242
    4343
    44 RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX pMutexSem)
     44RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx)
    4545{
    4646    PRTCRITSECT pCritSect = (PRTCRITSECT)RTMemAlloc(sizeof(RTCRITSECT));
    4747    if (!pCritSect)
    4848        return VERR_NO_MEMORY;
    49     int rc = RTCritSectInit(pCritSect);
     49
     50    int rc = RTCritSectInitEx(pCritSect, RTCRITSECT_FLAGS_NO_NESTING,
     51                              NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, NULL);
    5052    if (RT_SUCCESS(rc))
    51     {
    52         /** @todo pCritSect->fFlags |= RTCRITSECT_FLAGS_NO_NESTING; */
    53         *pMutexSem = (RTSEMFASTMUTEX)pCritSect;
    54     }
     53        *phFastMtx = (RTSEMFASTMUTEX)pCritSect;
    5554    else
    5655        RTMemFree(pCritSect);
     
    6059
    6160
    62 RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX MutexSem)
     61RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX hFastMtx)
    6362{
    64     if (MutexSem == NIL_RTSEMFASTMUTEX)
     63    if (hFastMtx == NIL_RTSEMFASTMUTEX)
    6564        return VERR_INVALID_PARAMETER;
    66     PRTCRITSECT pCritSect = (PRTCRITSECT)MutexSem;
     65    PRTCRITSECT pCritSect = (PRTCRITSECT)hFastMtx;
    6766    int rc = RTCritSectDelete(pCritSect);
    6867    if (RT_SUCCESS(rc))
     
    7372
    7473
    75 RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX MutexSem)
     74RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX hFastMtx)
    7675{
    77     return RTCritSectEnter((PRTCRITSECT)MutexSem);
     76    return RTCritSectEnter((PRTCRITSECT)hFastMtx);
    7877}
    7978RT_EXPORT_SYMBOL(RTSemFastMutexRequest);
    8079
    8180
    82 RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX MutexSem)
     81RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX hFastMtx)
    8382{
    84     return RTCritSectLeave((PRTCRITSECT)MutexSem);
     83    return RTCritSectLeave((PRTCRITSECT)hFastMtx);
    8584}
    8685RT_EXPORT_SYMBOL(RTSemFastMutexRelease);
  • trunk/src/VBox/Runtime/r0drv/darwin/semaphore-r0drv-darwin.cpp

    r25721 r25722  
    530530
    531531#if 0 /* need proper timeout lock function! */
    532 RTDECL(int)  RTSemMutexCreate(PRTSEMMUTEX pMutexSem)
     532RTDECL(int)  RTSemMutexCreate(PRTSEMMUTEX phFastMtx)
    533533{
    534534    RT_ASSERT_PREEMPTIBLE();
     
    542542        if (pThis->pMtx)
    543543        {
    544             *pMutexSem = pThis;
     544            *phFastMtx = pThis;
    545545            return VINF_SUCCESS;
    546546        }
     
    653653
    654654
    655 RTDECL(int)  RTSemFastMutexCreate(PRTSEMFASTMUTEX pMutexSem)
     655RTDECL(int)  RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx)
    656656{
    657657    AssertCompile(sizeof(RTSEMFASTMUTEXINTERNAL) > sizeof(void *));
    658     AssertPtrReturn(pMutexSem, VERR_INVALID_POINTER);
     658    AssertPtrReturn(phFastMtx, VERR_INVALID_POINTER);
    659659    RT_ASSERT_PREEMPTIBLE();
    660660
    661     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pFastInt));
    662     if (pFastInt)
    663     {
    664         pFastInt->u32Magic = RTSEMFASTMUTEX_MAGIC;
     661    PRTSEMFASTMUTEXINTERNAL pThis = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pThis));
     662    if (pThis)
     663    {
     664        pThis->u32Magic = RTSEMFASTMUTEX_MAGIC;
    665665        Assert(g_pDarwinLockGroup);
    666         pFastInt->pMtx = lck_mtx_alloc_init(g_pDarwinLockGroup, LCK_ATTR_NULL);
    667         if (pFastInt->pMtx)
     666        pThis->pMtx = lck_mtx_alloc_init(g_pDarwinLockGroup, LCK_ATTR_NULL);
     667        if (pThis->pMtx)
    668668        {
    669             *pMutexSem = pFastInt;
     669            *phFastMtx = pThis;
    670670            return VINF_SUCCESS;
    671671        }
    672672
    673         RTMemFree(pFastInt);
     673        RTMemFree(pThis);
    674674    }
    675675    return VERR_NO_MEMORY;
     
    677677
    678678
    679 RTDECL(int)  RTSemFastMutexDestroy(RTSEMFASTMUTEX hMutexSem)
    680 {
    681     if (hMutexSem == NIL_RTSEMFASTMUTEX) /* don't bitch */
    682         return VERR_INVALID_PARAMETER;
    683     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)hMutexSem;
    684     AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER);
    685     AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC,
    686                     ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt),
    687                     VERR_INVALID_PARAMETER);
     679RTDECL(int)  RTSemFastMutexDestroy(RTSEMFASTMUTEX hFastMtx)
     680{
     681    PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
     682    if (pThis == NIL_RTSEMFASTMUTEX)
     683        return VINF_SUCCESS;
     684    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     685    AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
    688686    RT_ASSERT_INTS_ON();
    689687
    690     ASMAtomicIncU32(&pFastInt->u32Magic); /* make the handle invalid. */
     688    ASMAtomicWriteU32(&pThis->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD);
    691689    Assert(g_pDarwinLockGroup);
    692     lck_mtx_free(pFastInt->pMtx, g_pDarwinLockGroup);
    693     pFastInt->pMtx = NULL;
    694     RTMemFree(pFastInt);
    695 
    696     return VINF_SUCCESS;
    697 }
    698 
    699 
    700 RTDECL(int)  RTSemFastMutexRequest(RTSEMFASTMUTEX hMutexSem)
    701 {
    702     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)hMutexSem;
    703     AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER);
    704     AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC,
    705                     ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt),
    706                     VERR_INVALID_PARAMETER);
     690    lck_mtx_free(pThis->pMtx, g_pDarwinLockGroup);
     691    pThis->pMtx = NULL;
     692    RTMemFree(pThis);
     693
     694    return VINF_SUCCESS;
     695}
     696
     697
     698RTDECL(int)  RTSemFastMutexRequest(RTSEMFASTMUTEX hFastMtx)
     699{
     700    PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
     701    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     702    AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
    707703    RT_ASSERT_PREEMPTIBLE();
    708     lck_mtx_lock(pFastInt->pMtx);
    709     return VINF_SUCCESS;
    710 }
    711 
    712 
    713 RTDECL(int)  RTSemFastMutexRelease(RTSEMFASTMUTEX hMutexSem)
    714 {
    715     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)hMutexSem;
    716     AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER);
    717     AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC,
    718                     ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt),
    719                     VERR_INVALID_PARAMETER);
     704
     705    lck_mtx_lock(pThis->pMtx);
     706    return VINF_SUCCESS;
     707}
     708
     709
     710RTDECL(int)  RTSemFastMutexRelease(RTSEMFASTMUTEX hFastMtx)
     711{
     712    PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
     713    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     714    AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
    720715    RT_ASSERT_PREEMPTIBLE();
    721     lck_mtx_unlock(pFastInt->pMtx);
    722     return VINF_SUCCESS;
    723 }
    724 
     716
     717    lck_mtx_unlock(pThis->pMtx);
     718    return VINF_SUCCESS;
     719}
     720
  • trunk/src/VBox/Runtime/r0drv/freebsd/semfastmutex-r0drv-freebsd.c

    r22579 r25722  
    5858
    5959
    60 RTDECL(int)  RTSemFastMutexCreate(PRTSEMFASTMUTEX pMutexSem)
     60RTDECL(int)  RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx)
    6161{
    6262    AssertCompile(sizeof(RTSEMFASTMUTEXINTERNAL) > sizeof(void *));
    63     AssertPtrReturn(pMutexSem, VERR_INVALID_POINTER);
     63    AssertPtrReturn(phFastMtx, VERR_INVALID_POINTER);
    6464
    65     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)RTMemAllocZ(sizeof(*pFastInt));
    66     if (pFastInt)
     65    PRTSEMFASTMUTEXINTERNAL pThis = (PRTSEMFASTMUTEXINTERNAL)RTMemAllocZ(sizeof(*pThis));
     66    if (pThis)
    6767    {
    68         pFastInt->u32Magic = RTSEMFASTMUTEX_MAGIC;
    69         sx_init(&pFastInt->SxLock, "IPRT Fast Mutex Semaphore");
    70         *pMutexSem = pFastInt;
     68        pThis->u32Magic = RTSEMFASTMUTEX_MAGIC;
     69        sx_init(&pThis->SxLock, "IPRT Fast Mutex Semaphore");
     70
     71        *phFastMtx = pThis;
    7172        return VINF_SUCCESS;
    7273    }
     
    7576
    7677
    77 RTDECL(int)  RTSemFastMutexDestroy(RTSEMFASTMUTEX MutexSem)
     78RTDECL(int)  RTSemFastMutexDestroy(RTSEMFASTMUTEX hFastMtx)
    7879{
    79     if (MutexSem == NIL_RTSEMFASTMUTEX) /* don't bitch */
    80         return VERR_INVALID_PARAMETER;
    81     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
    82     AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER);
    83     AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC,
    84                     ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt),
    85                     VERR_INVALID_PARAMETER);
     80    PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
     81    if (pThis == NIL_RTSEMFASTMUTEX)
     82        return VINF_SUCCESS;
     83    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     84    AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
    8685
    87     ASMAtomicXchgU32(&pFastInt->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD);
    88     sx_destroy(&pFastInt->SxLock);
    89     RTMemFree(pFastInt);
     86    ASMAtomicWriteU32(&pThis->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD);
     87    sx_destroy(&pThis->SxLock);
     88    RTMemFree(pThis);
    9089
    9190    return VINF_SUCCESS;
     
    9392
    9493
    95 RTDECL(int)  RTSemFastMutexRequest(RTSEMFASTMUTEX MutexSem)
     94RTDECL(int)  RTSemFastMutexRequest(RTSEMFASTMUTEX hFastMtx)
    9695{
    97     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
    98     AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER);
    99     AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC,
    100                     ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt),
    101                     VERR_INVALID_PARAMETER);
     96    PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
     97    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     98    AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
    10299
    103     sx_xlock(&pFastInt->SxLock);
     100    sx_xlock(&pThis->SxLock);
    104101    return VINF_SUCCESS;
    105102}
    106103
    107104
    108 RTDECL(int)  RTSemFastMutexRelease(RTSEMFASTMUTEX MutexSem)
     105RTDECL(int)  RTSemFastMutexRelease(RTSEMFASTMUTEX hFastMtx)
    109106{
    110     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
    111     AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER);
    112     AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC,
    113                     ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt),
    114                     VERR_INVALID_PARAMETER);
     107    PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
     108    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     109    AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
    115110
    116     sx_xunlock(&pFastInt->SxLock);
     111    sx_xunlock(&pThis->SxLock);
    117112    return VINF_SUCCESS;
    118113}
  • trunk/src/VBox/Runtime/r0drv/linux/semfastmutex-r0drv-linux.c

    r21337 r25722  
    6666
    6767
    68 RTDECL(int)  RTSemFastMutexCreate(PRTSEMFASTMUTEX pMutexSem)
     68RTDECL(int)  RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx)
    6969{
    7070    /*
    7171     * Allocate.
    7272     */
    73     PRTSEMFASTMUTEXINTERNAL pFastInt;
    74     pFastInt = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pFastInt));
    75     if (!pFastInt)
     73    PRTSEMFASTMUTEXINTERNAL pThis;
     74    pThis = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pThis));
     75    if (!pThis)
    7676        return VERR_NO_MEMORY;
    7777
     
    7979     * Initialize.
    8080     */
    81     pFastInt->u32Magic = RTSEMFASTMUTEX_MAGIC;
    82     sema_init(&pFastInt->Semaphore, 1);
     81    pThis->u32Magic = RTSEMFASTMUTEX_MAGIC;
     82    sema_init(&pThis->Semaphore, 1);
    8383#ifdef IPRT_DEBUG_SEMS
    84     pFastInt->Owner = NIL_RTNATIVETHREAD;
     84    pThis->Owner = NIL_RTNATIVETHREAD;
    8585#endif
    86     *pMutexSem = pFastInt;
     86
     87    *phFastMtx = pThis;
    8788    return VINF_SUCCESS;
    8889}
     
    9091
    9192
    92 RTDECL(int)  RTSemFastMutexDestroy(RTSEMFASTMUTEX MutexSem)
     93RTDECL(int)  RTSemFastMutexDestroy(RTSEMFASTMUTEX hFastMtx)
    9394{
    9495    /*
    9596     * Validate.
    9697     */
    97     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
    98     if (!pFastInt)
    99         return VERR_INVALID_PARAMETER;
    100     if (pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC)
    101     {
    102         AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt->u32Magic, pFastInt));
    103         return VERR_INVALID_PARAMETER;
    104     }
     98    PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
     99    if (pThis == NIL_RTSEMFASTMUTEX)
     100        return VINF_SUCCESS;
     101    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     102    AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE);
    105103
    106     ASMAtomicIncU32(&pFastInt->u32Magic);
    107     RTMemFree(pFastInt);
     104    ASMAtomicWriteU32(&pThis->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD);
     105    RTMemFree(pThis);
    108106    return VINF_SUCCESS;
    109107}
     
    111109
    112110
    113 RTDECL(int)  RTSemFastMutexRequest(RTSEMFASTMUTEX MutexSem)
     111RTDECL(int)  RTSemFastMutexRequest(RTSEMFASTMUTEX hFastMtx)
    114112{
    115113    /*
    116114     * Validate.
    117115     */
    118     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
    119     if (    !pFastInt
    120         ||  pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC)
    121     {
    122         AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt ? pFastInt->u32Magic : 0, pFastInt));
    123         return VERR_INVALID_PARAMETER;
    124     }
     116    PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
     117    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     118    AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE);
    125119
    126120#ifdef IPRT_DEBUG_SEMS
    127     snprintf(current->comm, TASK_COMM_LEN, "d%lx", IPRT_DEBUG_SEMS_ADDRESS(pFastInt));
     121    snprintf(current->comm, TASK_COMM_LEN, "d%lx", IPRT_DEBUG_SEMS_ADDRESS(pThis));
    128122#endif
    129     down(&pFastInt->Semaphore);
     123    down(&pThis->Semaphore);
    130124#ifdef IPRT_DEBUG_SEMS
    131     snprintf(current->comm, TASK_COMM_LEN, "o%lx", IPRT_DEBUG_SEMS_ADDRESS(pFastInt));
    132     AssertRelease(pFastInt->Owner == NIL_RTNATIVETHREAD);
    133     ASMAtomicUoWriteSize(&pFastInt->Owner, RTThreadNativeSelf());
     125    snprintf(current->comm, TASK_COMM_LEN, "o%lx", IPRT_DEBUG_SEMS_ADDRESS(pThis));
     126    AssertRelease(pThis->Owner == NIL_RTNATIVETHREAD);
     127    ASMAtomicUoWriteSize(&pThis->Owner, RTThreadNativeSelf());
    134128#endif
    135129    return VINF_SUCCESS;
     
    138132
    139133
    140 RTDECL(int)  RTSemFastMutexRelease(RTSEMFASTMUTEX MutexSem)
     134RTDECL(int)  RTSemFastMutexRelease(RTSEMFASTMUTEX hFastMtx)
    141135{
    142136    /*
    143137     * Validate.
    144138     */
    145     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
    146     if (    !pFastInt
    147         ||  pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC)
    148     {
    149         AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt ? pFastInt->u32Magic : 0, pFastInt));
    150         return VERR_INVALID_PARAMETER;
    151     }
     139    PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
     140    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     141    AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE);
    152142
    153143#ifdef IPRT_DEBUG_SEMS
    154     AssertRelease(pFastInt->Owner == RTThreadNativeSelf());
    155     ASMAtomicUoWriteSize(&pFastInt->Owner, NIL_RTNATIVETHREAD);
     144    AssertRelease(pThis->Owner == RTThreadNativeSelf());
     145    ASMAtomicUoWriteSize(&pThis->Owner, NIL_RTNATIVETHREAD);
    156146#endif
    157     up(&pFastInt->Semaphore);
     147    up(&pThis->Semaphore);
    158148#ifdef IPRT_DEBUG_SEMS
    159     snprintf(current->comm, TASK_COMM_LEN, "u%lx", IPRT_DEBUG_SEMS_ADDRESS(pFastInt));
     149    snprintf(current->comm, TASK_COMM_LEN, "u%lx", IPRT_DEBUG_SEMS_ADDRESS(pThis));
    160150#endif
    161151    return VINF_SUCCESS;
  • trunk/src/VBox/Runtime/r0drv/nt/semeventmulti-r0drv-nt.cpp

    r25720 r25722  
    7676        KeInitializeEvent(&pThis->Event, NotificationEvent, FALSE /* not signalled */);
    7777
    78         *phEventSem = pThis;
     78        *phEventMultiSem = pThis;
    7979        return VINF_SUCCESS;
    8080    }
  • trunk/src/VBox/Runtime/r0drv/nt/semfastmutex-r0drv-nt.cpp

    r12160 r25722  
    6060
    6161
    62 RTDECL(int)  RTSemFastMutexCreate(PRTSEMFASTMUTEX pMutexSem)
     62RTDECL(int)  RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx)
    6363{
    6464    /*
    6565     * Allocate.
    6666     */
    67     PRTSEMFASTMUTEXINTERNAL pFastInt;
    68     Assert(sizeof(*pFastInt) > sizeof(void *));
    69     pFastInt = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pFastInt));
    70     if (!pFastInt)
     67    PRTSEMFASTMUTEXINTERNAL pThis;
     68    Assert(sizeof(*pThis) > sizeof(void *));
     69    pThis = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pThis));
     70    if (!pThis)
    7171        return VERR_NO_MEMORY;
    7272
     
    7474     * Initialize.
    7575     */
    76     pFastInt->u32Magic = RTSEMFASTMUTEX_MAGIC;
    77     ExInitializeFastMutex(&pFastInt->Mutex);
    78     *pMutexSem = pFastInt;
     76    pThis->u32Magic = RTSEMFASTMUTEX_MAGIC;
     77    ExInitializeFastMutex(&pThis->Mutex);
     78
     79    *phFastMtx = pThis;
    7980    return VINF_SUCCESS;
    8081}
    8182
    8283
    83 RTDECL(int)  RTSemFastMutexDestroy(RTSEMFASTMUTEX MutexSem)
     84RTDECL(int)  RTSemFastMutexDestroy(RTSEMFASTMUTEX hFastMtx)
    8485{
    8586    /*
    8687     * Validate.
    8788     */
    88     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
    89     if (!pFastInt)
    90         return VERR_INVALID_PARAMETER;
    91     if (pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC)
    92     {
    93         AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt->u32Magic, pFastInt));
    94         return VERR_INVALID_PARAMETER;
    95     }
     89    PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
     90    if (pThis == NIL_RTSEMFASTMUTEX)
     91        return VINF_SUCCESS;
     92    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     93    AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
    9694
    97     ASMAtomicIncU32(&pFastInt->u32Magic);
    98     Assert(pFastInt->Mutex.Count == 1);
    99     /* It's not very clear what this Contention field really means. Seems to be a counter for the number of times contention occurred. (see e.g. http://winprogger.com/?p=6)
    100      * The following assertion is therefor wrong:
    101      * Assert(pFastInt->Mutex.Contention == 0);
    102      */
    103     RTMemFree(pFastInt);
     95    ASMAtomicWriteU32(&pThis->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD);
     96    Assert(pThis->Mutex.Count == 1);
     97    RTMemFree(pThis);
    10498    return VINF_SUCCESS;
    10599}
    106100
    107101
    108 RTDECL(int)  RTSemFastMutexRequest(RTSEMFASTMUTEX MutexSem)
     102RTDECL(int)  RTSemFastMutexRequest(RTSEMFASTMUTEX hFastMtx)
    109103{
    110104    /*
    111105     * Validate.
    112106     */
    113     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
    114     if (    !pFastInt
    115         ||  pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC)
    116     {
    117         AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt ? pFastInt->u32Magic : 0, pFastInt));
    118         return VERR_INVALID_PARAMETER;
    119     }
     107    PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
     108    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     109    AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
     110
    120111#if 1
    121112    /*
    122113     * ExAcquireFastMutex will set the IRQL to APC regardless of our current
    123      * level. Lowering the IRQL may screw things up, so to allow this.
     114     * level.  Lowering the IRQL may screw things up, so do not allow this.
    124115     */
    125116# if 0 /** @todo enable this when the logger has been fixed. */
    126     AssertMsg(KeGetCurrentIrql() <= APC_LEVEL,
    127               ("%d\n", KeGetCurrentIrql()),
    128               VERR_INVALID_STATE);
     117    AssertMsg(KeGetCurrentIrql() <= APC_LEVEL, ("%d\n", KeGetCurrentIrql()), VERR_INVALID_STATE);
    129118# else  /* the gentler approach. */
    130119    KIRQL Irql = KeGetCurrentIrql();
     
    134123#endif
    135124
    136     ExAcquireFastMutex(&pFastInt->Mutex);
     125    ExAcquireFastMutex(&pThis->Mutex);
    137126    return VINF_SUCCESS;
    138127}
    139128
    140129
    141 RTDECL(int)  RTSemFastMutexRelease(RTSEMFASTMUTEX MutexSem)
     130RTDECL(int)  RTSemFastMutexRelease(RTSEMFASTMUTEX hFastMtx)
    142131{
    143132    /*
    144133     * Validate.
    145134     */
    146     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
    147     if (    !pFastInt
    148         ||  pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC)
    149     {
    150         AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt ? pFastInt->u32Magic : 0, pFastInt));
    151         return VERR_INVALID_PARAMETER;
    152     }
     135    PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
     136    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     137    AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
    153138
    154     ExReleaseFastMutex(&pFastInt->Mutex);
     139    ExReleaseFastMutex(&pThis->Mutex);
    155140    return VINF_SUCCESS;
    156141}
  • trunk/src/VBox/Runtime/r0drv/os2/semfastmutex-r0drv-os2.cpp

    r8245 r25722  
    5858
    5959
    60 RTDECL(int)  RTSemFastMutexCreate(PRTSEMFASTMUTEX pMutexSem)
     60RTDECL(int)  RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx)
    6161{
    6262    AssertCompile(sizeof(RTSEMFASTMUTEXINTERNAL) > sizeof(void *));
    63     AssertPtrReturn(pMutexSem, VERR_INVALID_POINTER);
     63    AssertPtrReturn(phFastMtx, VERR_INVALID_POINTER);
    6464
    65     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pFastInt));
    66     if (pFastInt)
     65    PRTSEMFASTMUTEXINTERNAL pThis = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pThis));
     66    if (pThis)
    6767    {
    68         pFastInt->u32Magic = RTSEMFASTMUTEX_MAGIC;
    69         KernAllocMutexLock(&pFastInt->Mtx);
    70         *pMutexSem = pFastInt;
     68        pThis->u32Magic = RTSEMFASTMUTEX_MAGIC;
     69        KernAllocMutexLock(&pThis->Mtx);
     70
     71        *phFastMtx = pThis;
    7172        return VINF_SUCCESS;
    7273    }
     
    7576
    7677
    77 RTDECL(int)  RTSemFastMutexDestroy(RTSEMFASTMUTEX MutexSem)
     78RTDECL(int)  RTSemFastMutexDestroy(RTSEMFASTMUTEX hFastMtx)
    7879{
    79     if (MutexSem == NIL_RTSEMFASTMUTEX) /* don't bitch */
    80         return VERR_INVALID_PARAMETER;
    81     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
    82     AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER);
    83     AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC,
    84                     ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt),
    85                     VERR_INVALID_PARAMETER);
     80    PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
     81    if (pThis == NIL_RTSEMFASTMUTEX)
     82        return VINF_SUCCESS;
     83    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     84    AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
    8685
    87     ASMAtomicXchgU32(&pFastInt->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD);
    88     KernFreeMutexLock(&pFastInt->Mtx);
    89     RTMemFree(pFastInt);
     86    ASMAtomicWriteU32(&pThis->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD);
     87    KernFreeMutexLock(&pThis->Mtx);
     88    RTMemFree(pThis);
    9089
    9190    return VINF_SUCCESS;
     
    9392
    9493
    95 RTDECL(int)  RTSemFastMutexRequest(RTSEMFASTMUTEX MutexSem)
     94RTDECL(int)  RTSemFastMutexRequest(RTSEMFASTMUTEX hFastMtx)
    9695{
    97     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
    98     AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER);
    99     AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC,
    100                     ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt),
    101                     VERR_INVALID_PARAMETER);
    102     KernRequestExclusiveMutex(&pFastInt->Mtx);
     96    PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
     97    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     98    AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
     99
     100    KernRequestExclusiveMutex(&pThis->Mtx);
    103101    return VINF_SUCCESS;
    104102}
    105103
    106104
    107 RTDECL(int)  RTSemFastMutexRelease(RTSEMFASTMUTEX MutexSem)
     105RTDECL(int)  RTSemFastMutexRelease(RTSEMFASTMUTEX hFastMtx)
    108106{
    109     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
    110     AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER);
    111     AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC,
    112                     ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt),
    113                     VERR_INVALID_PARAMETER);
    114     KernReleaseExclusiveMutex(&pFastInt->Mtx);
     107    PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
     108    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     109    AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
     110
     111    KernReleaseExclusiveMutex(&pThis->Mtx);
    115112    return VINF_SUCCESS;
    116113}
  • trunk/src/VBox/Runtime/r0drv/solaris/semfastmutex-r0drv-solaris.c

    r22073 r25722  
    6161
    6262
    63 RTDECL(int)  RTSemFastMutexCreate(PRTSEMFASTMUTEX pMutexSem)
     63RTDECL(int)  RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx)
    6464{
    6565    AssertCompile(sizeof(RTSEMFASTMUTEXINTERNAL) > sizeof(void *));
    66     AssertPtrReturn(pMutexSem, VERR_INVALID_POINTER);
     66    AssertPtrReturn(phFastMtx, VERR_INVALID_POINTER);
    6767    RT_ASSERT_PREEMPTIBLE();
    6868
    69     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pFastInt));
    70     if (pFastInt)
     69    PRTSEMFASTMUTEXINTERNAL pThis = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pThis));
     70    if (pThis)
    7171    {
    72         pFastInt->u32Magic = RTSEMFASTMUTEX_MAGIC;
    73         rw_init (&pFastInt->Mtx, "RWLOCK", RW_DRIVER, NULL);
    74         *pMutexSem = pFastInt;
     72        pThis->u32Magic = RTSEMFASTMUTEX_MAGIC;
     73        rw_init (&pThis->Mtx, "RWLOCK", RW_DRIVER, NULL);
     74
     75        *phFastMtx = pThis;
    7576        return VINF_SUCCESS;
    7677    }
     
    7980
    8081
    81 RTDECL(int)  RTSemFastMutexDestroy(RTSEMFASTMUTEX MutexSem)
     82RTDECL(int)  RTSemFastMutexDestroy(RTSEMFASTMUTEX hFastMtx)
    8283{
    83     if (MutexSem == NIL_RTSEMFASTMUTEX)
    84         return VERR_INVALID_PARAMETER;
    85     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
    86     AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER);
    87     AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC,
    88                     ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt),
    89                     VERR_INVALID_PARAMETER);
     84    PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
     85    if (pThis == NIL_RTSEMFASTMUTEX)
     86        return VINF_SUCCESS;
     87    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     88    AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
    9089    RT_ASSERT_INTS_ON();
    9190
    92     ASMAtomicXchgU32(&pFastInt->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD);
    93     rw_destroy(&pFastInt->Mtx);
    94     RTMemFree(pFastInt);
     91    ASMAtomicXchgU32(&pThis->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD);
     92    rw_destroy(&pThis->Mtx);
     93    RTMemFree(pThis);
    9594
    9695    return VINF_SUCCESS;
     
    9897
    9998
    100 RTDECL(int)  RTSemFastMutexRequest(RTSEMFASTMUTEX MutexSem)
     99RTDECL(int)  RTSemFastMutexRequest(RTSEMFASTMUTEX hFastMtx)
    101100{
    102     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
    103     AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER);
    104     AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC,
    105                     ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt),
    106                     VERR_INVALID_PARAMETER);
     101    PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
     102    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     103    AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
    107104    RT_ASSERT_PREEMPTIBLE();
    108105
    109     rw_enter(&pFastInt->Mtx, RW_WRITER);
     106    rw_enter(&pThis->Mtx, RW_WRITER);
    110107    return VINF_SUCCESS;
    111108}
    112109
    113110
    114 RTDECL(int)  RTSemFastMutexRelease(RTSEMFASTMUTEX MutexSem)
     111RTDECL(int)  RTSemFastMutexRelease(RTSEMFASTMUTEX hFastMtx)
    115112{
    116     PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
    117     AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER);
    118     AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC,
    119                     ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt),
    120                     VERR_INVALID_PARAMETER);
     113    PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
     114    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     115    AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
    121116    RT_ASSERT_INTS_ON();
    122117
    123     rw_exit(&pFastInt->Mtx);
     118    rw_exit(&pThis->Mtx);
    124119    return VINF_SUCCESS;
    125120}
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