VirtualBox

Changeset 25714 in vbox for trunk/src/VBox/Runtime/r0drv/nt


Ignore:
Timestamp:
Jan 11, 2010 12:40:15 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
56453
Message:

iprt: Adjuested the remaining RTSemMutex implementations.

File:
1 edited

Legend:

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

    r25433 r25714  
    55
    66/*
    7  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     7 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    6464
    6565
    66 /* Undefine debug mappings. */
    67 #undef RTSemMutexRequest
    68 #undef RTSemMutexRequestNoResume
    69 
    70 
    71 RTDECL(int) RTSemMutexCreate(PRTSEMMUTEX pMutexSem)
    72 {
    73     Assert(sizeof(RTSEMMUTEXINTERNAL) > sizeof(void *));
    74     PRTSEMMUTEXINTERNAL pMutexInt = (PRTSEMMUTEXINTERNAL)RTMemAlloc(sizeof(*pMutexInt));
    75     if (pMutexInt)
    76     {
    77         pMutexInt->u32Magic = RTSEMMUTEX_MAGIC;
    78 #ifdef RT_USE_FAST_MUTEX
    79         ExInitializeFastMutex(&pMutexInt->Mutex);
     66
     67RTDECL(int)  RTSemMutexCreate(PRTSEMMUTEX phMutexSem)
     68{
     69    return RTSemMutexCreateEx(phMutexSem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, NULL);
     70}
     71
     72
     73RTDECL(int) RTSemMutexCreateEx(PRTSEMMUTEX phMutexSem, uint32_t fFlags,
     74                               RTLOCKVALCLASS hClass, uint32_t uSubClass, const char *pszNameFmt, ...)
     75{
     76    AssertReturn(!(fFlags & ~RTSEMMUTEX_FLAGS_NO_LOCK_VAL), VERR_INVALID_PARAMETER);
     77
     78    AssertCompile(sizeof(RTSEMMUTEXINTERNAL) > sizeof(void *));
     79    PRTSEMMUTEXINTERNAL pThis = (PRTSEMMUTEXINTERNAL)RTMemAlloc(sizeof(*pThis));
     80    if (!pThis)
     81        return VERR_NO_MEMORY;
     82
     83    pThis->u32Magic = RTSEMMUTEX_MAGIC;
     84#ifdef RT_USE_FAST_MUTEX
     85    ExInitializeFastMutex(&pThis->Mutex);
    8086#else
    81         KeInitializeMutex(&pMutexInt->Mutex, 0);
     87    KeInitializeMutex(&pThis->Mutex, 0);
    8288#endif
    83         *pMutexSem = pMutexInt;
     89
     90    *phMutexSem = pThis;
     91    return VINF_SUCCESS;
     92}
     93
     94
     95RTDECL(int) RTSemMutexDestroy(RTSEMMUTEX MutexSem)
     96{
     97    /*
     98     * Validate input.
     99     */
     100    PRTSEMMUTEXINTERNAL pThis = (PRTSEMMUTEXINTERNAL)MutexSem;
     101    if (pThis == NIL_RTSEMMUTEX)
    84102        return VINF_SUCCESS;
    85     }
    86     return VERR_NO_MEMORY;
    87 }
    88 
    89 
    90 RTDECL(int) RTSemMutexDestroy(RTSEMMUTEX MutexSem)
    91 {
    92     /*
    93      * Validate input.
    94      */
    95     PRTSEMMUTEXINTERNAL pMutexInt = (PRTSEMMUTEXINTERNAL)MutexSem;
    96     if (!pMutexInt)
    97         return VERR_INVALID_PARAMETER;
    98     AssertReturn(pMutexInt->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE);
     103    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     104    AssertReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE);
    99105
    100106    /*
    101107     * Invalidate it and signal the object just in case.
    102108     */
    103     AssertReturn(ASMAtomicCmpXchgU32(&pMutexInt->u32Magic, RTSEMMUTEX_MAGIC_DEAD, RTSEMMUTEX_MAGIC), VERR_INVALID_HANDLE);
    104     RTMemFree(pMutexInt);
     109    AssertReturn(ASMAtomicCmpXchgU32(&pThis->u32Magic, RTSEMMUTEX_MAGIC_DEAD, RTSEMMUTEX_MAGIC), VERR_INVALID_HANDLE);
     110    RTMemFree(pThis);
    105111    return VINF_SUCCESS;
    106112}
     
    122128     * Validate input.
    123129     */
    124     PRTSEMMUTEXINTERNAL pMutexInt = (PRTSEMMUTEXINTERNAL)MutexSem;
    125     if (!pMutexInt)
    126         return VERR_INVALID_PARAMETER;
    127     AssertReturn(pMutexInt->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE);
     130    PRTSEMMUTEXINTERNAL pThis = (PRTSEMMUTEXINTERNAL)MutexSem;
     131    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     132    AssertReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE);
    128133
    129134    /*
     
    132137#ifdef RT_USE_FAST_MUTEX
    133138    AssertMsg(cMillies == RT_INDEFINITE_WAIT, ("timeouts are not supported when using fast mutexes!\n"));
    134     ExAcquireFastMutex(&pMutexInt->Mutex);
     139    ExAcquireFastMutex(&pThis->Mutex);
    135140#else  /* !RT_USE_FAST_MUTEX */
    136141    NTSTATUS rcNt;
    137142    if (cMillies == RT_INDEFINITE_WAIT)
    138         rcNt = KeWaitForSingleObject(&pMutexInt->Mutex, Executive, KernelMode, fInterruptible, NULL);
     143        rcNt = KeWaitForSingleObject(&pThis->Mutex, Executive, KernelMode, fInterruptible, NULL);
    139144    else
    140145    {
    141146        LARGE_INTEGER Timeout;
    142147        Timeout.QuadPart = -(int64_t)cMillies * 10000;
    143         rcNt = KeWaitForSingleObject(&pMutexInt->Mutex, Executive, KernelMode, fInterruptible, &Timeout);
     148        rcNt = KeWaitForSingleObject(&pThis->Mutex, Executive, KernelMode, fInterruptible, &Timeout);
    144149    }
    145150    switch (rcNt)
    146151    {
    147152        case STATUS_SUCCESS:
    148             if (pMutexInt->u32Magic == RTSEMMUTEX_MAGIC)
     153            if (pThis->u32Magic == RTSEMMUTEX_MAGIC)
    149154                return VINF_SUCCESS;
    150155            return VERR_SEM_DESTROYED;
     
    159164
    160165        default:
    161             AssertMsgFailed(("pMutexInt->u32Magic=%RX32 pMutexInt=%p: wait returned %lx!\n",
    162                              pMutexInt->u32Magic, pMutexInt, (long)rcNt));
     166            AssertMsgFailed(("pThis->u32Magic=%RX32 pThis=%p: wait returned %lx!\n",
     167                             pThis->u32Magic, pThis, (long)rcNt));
    163168            return VERR_INTERNAL_ERROR;
    164169    }
     
    168173
    169174
     175#undef RTSemMutexRequest
    170176RTDECL(int) RTSemMutexRequest(RTSEMMUTEX MutexSem, unsigned cMillies)
    171177{
     
    180186
    181187
     188#undef RTSemMutexRequestNoResume
    182189RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies)
    183190{
     
    197204     * Validate input.
    198205     */
    199     PRTSEMMUTEXINTERNAL pMutexInt = (PRTSEMMUTEXINTERNAL)MutexSem;
    200     if (!pMutexInt)
    201         return VERR_INVALID_PARAMETER;
    202     AssertReturn(pMutexInt->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE);
     206    PRTSEMMUTEXINTERNAL pThis = (PRTSEMMUTEXINTERNAL)MutexSem;
     207    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     208    AssertReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE);
    203209
    204210    /*
     
    206212     */
    207213#ifdef RT_USE_FAST_MUTEX
    208     ExReleaseFastMutex(&pMutexInt->Mutex);
     214    ExReleaseFastMutex(&pThis->Mutex);
    209215#else
    210     KeReleaseMutex(&pMutexInt->Mutex, FALSE /*Wait*/);
     216    KeReleaseMutex(&pThis->Mutex, FALSE /*Wait*/);
    211217#endif
    212218    return VINF_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette