VirtualBox

Changeset 25433 in vbox


Ignore:
Timestamp:
Dec 16, 2009 2:55:18 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
56082
Message:

semmutex-r0drv-nt.cpp: Corrected the RTSemMutexRequest implementation (it's a non-interruptible wait) and added RTSemMutexRequestNoResume.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/nt/semmutex-r0drv-nt.cpp

    r25378 r25433  
    6969
    7070
    71 RTDECL(int)  RTSemMutexCreate(PRTSEMMUTEX pMutexSem)
     71RTDECL(int) RTSemMutexCreate(PRTSEMMUTEX pMutexSem)
    7272{
    7373    Assert(sizeof(RTSEMMUTEXINTERNAL) > sizeof(void *));
     
    8888
    8989
    90 RTDECL(int)  RTSemMutexDestroy(RTSEMMUTEX MutexSem)
     90RTDECL(int) RTSemMutexDestroy(RTSEMMUTEX MutexSem)
    9191{
    9292    /*
     
    9696    if (!pMutexInt)
    9797        return VERR_INVALID_PARAMETER;
    98     if (pMutexInt->u32Magic != RTSEMMUTEX_MAGIC)
    99     {
    100         AssertMsgFailed(("pMutexInt->u32Magic=%RX32 pMutexInt=%p\n", pMutexInt->u32Magic, pMutexInt));
    101         return VERR_INVALID_PARAMETER;
    102     }
     98    AssertReturn(pMutexInt->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE);
    10399
    104100    /*
    105101     * Invalidate it and signal the object just in case.
    106102     */
    107     ASMAtomicIncU32(&pMutexInt->u32Magic);
     103    AssertReturn(ASMAtomicCmpXchgU32(&pMutexInt->u32Magic, RTSEMMUTEX_MAGIC_DEAD, RTSEMMUTEX_MAGIC), VERR_INVALID_HANDLE);
    108104    RTMemFree(pMutexInt);
    109105    return VINF_SUCCESS;
     
    111107
    112108
    113 RTDECL(int)  RTSemMutexRequest(RTSEMMUTEX MutexSem, unsigned cMillies)
     109/**
     110 * Internal worker for RTSemMutexRequest and RTSemMutexRequestNoResume
     111 *
     112 * @returns IPRT status code.
     113 * @param   MutexSem            The mutex handle.
     114 * @param   cMillies            The timeout.
     115 * @param   fInterruptible      Whether it's interruptible
     116 *                              (RTSemMutexRequestNoResume) or not
     117 *                              (RTSemMutexRequest).
     118 */
     119static int rtSemMutexRequest(RTSEMMUTEX MutexSem, unsigned cMillies, BOOLEAN fInterruptible)
    114120{
    115121    /*
     
    119125    if (!pMutexInt)
    120126        return VERR_INVALID_PARAMETER;
    121     if (    !pMutexInt
    122         ||  pMutexInt->u32Magic != RTSEMMUTEX_MAGIC)
    123     {
    124         AssertMsgFailed(("pMutexInt->u32Magic=%RX32 pMutexInt=%p\n", pMutexInt ? pMutexInt->u32Magic : 0, pMutexInt));
    125         return VERR_INVALID_PARAMETER;
    126     }
     127    AssertReturn(pMutexInt->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE);
    127128
    128129    /*
     
    132133    AssertMsg(cMillies == RT_INDEFINITE_WAIT, ("timeouts are not supported when using fast mutexes!\n"));
    133134    ExAcquireFastMutex(&pMutexInt->Mutex);
    134 #else
     135#else  /* !RT_USE_FAST_MUTEX */
    135136    NTSTATUS rcNt;
    136137    if (cMillies == RT_INDEFINITE_WAIT)
    137         rcNt = KeWaitForSingleObject(&pMutexInt->Mutex, Executive, KernelMode, TRUE, NULL);
     138        rcNt = KeWaitForSingleObject(&pMutexInt->Mutex, Executive, KernelMode, fInterruptible, NULL);
    138139    else
    139140    {
    140141        LARGE_INTEGER Timeout;
    141142        Timeout.QuadPart = -(int64_t)cMillies * 10000;
    142         rcNt = KeWaitForSingleObject(&pMutexInt->Mutex, Executive, KernelMode, TRUE, &Timeout);
     143        rcNt = KeWaitForSingleObject(&pMutexInt->Mutex, Executive, KernelMode, fInterruptible, &Timeout);
    143144    }
    144145    switch (rcNt)
     
    148149                return VINF_SUCCESS;
    149150            return VERR_SEM_DESTROYED;
     151
    150152        case STATUS_ALERTED:
    151             return VERR_INTERRUPTED; /** @todo VERR_INTERRUPTED isn't correct anylonger. please fix r0drv stuff! */
    152153        case STATUS_USER_APC:
    153             return VERR_INTERRUPTED; /** @todo VERR_INTERRUPTED isn't correct anylonger. please fix r0drv stuff! */
     154            Assert(fInterruptible);
     155            return VERR_INTERRUPTED;
     156
    154157        case STATUS_TIMEOUT:
    155158            return VERR_TIMEOUT;
     159
    156160        default:
    157161            AssertMsgFailed(("pMutexInt->u32Magic=%RX32 pMutexInt=%p: wait returned %lx!\n",
     
    159163            return VERR_INTERNAL_ERROR;
    160164    }
    161 #endif
     165#endif /* !RT_USE_FAST_MUTEX */
    162166    return VINF_SUCCESS;
    163167}
    164168
    165169
    166 RTDECL(int)  RTSemMutexRequestDebug(RTSEMMUTEX MutexSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
     170RTDECL(int) RTSemMutexRequest(RTSEMMUTEX MutexSem, unsigned cMillies)
     171{
     172    return rtSemMutexRequest(MutexSem, cMillies, FALSE /*fInterruptible*/);
     173}
     174
     175
     176RTDECL(int) RTSemMutexRequestDebug(RTSEMMUTEX MutexSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
    167177{
    168178    return RTSemMutexRequest(MutexSem, cMillies);
    169179}
    170180
    171 /** @todo implement the NoResume versions */
    172 
    173 RTDECL(int)  RTSemMutexRelease(RTSEMMUTEX MutexSem)
     181
     182RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies)
     183{
     184    return rtSemMutexRequest(MutexSem, cMillies, TRUE /*fInterruptible*/);
     185}
     186
     187
     188RTDECL(int) RTSemMutexRequestNoResumeDebug(RTSEMMUTEX MutexSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
     189{
     190    return RTSemMutexRequestNoResume(MutexSem, cMillies);
     191}
     192
     193
     194RTDECL(int) RTSemMutexRelease(RTSEMMUTEX MutexSem)
    174195{
    175196    /*
     
    179200    if (!pMutexInt)
    180201        return VERR_INVALID_PARAMETER;
    181     if (    !pMutexInt
    182         ||  pMutexInt->u32Magic != RTSEMMUTEX_MAGIC)
    183     {
    184         AssertMsgFailed(("pMutexInt->u32Magic=%RX32 pMutexInt=%p\n", pMutexInt ? pMutexInt->u32Magic : 0, pMutexInt));
    185         return VERR_INVALID_PARAMETER;
    186     }
     202    AssertReturn(pMutexInt->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE);
    187203
    188204    /*
     
    192208    ExReleaseFastMutex(&pMutexInt->Mutex);
    193209#else
    194     KeReleaseMutex(&pMutexInt->Mutex, FALSE);
     210    KeReleaseMutex(&pMutexInt->Mutex, FALSE /*Wait*/);
    195211#endif
    196212    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