VirtualBox

Ignore:
Timestamp:
Jan 11, 2010 2:22:03 PM (15 years ago)
Author:
vboxsync
Message:

iprt/RTSemFastMutex: A little cleanup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
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