VirtualBox

Changeset 25648 in vbox for trunk/src/VBox/Runtime/r3


Ignore:
Timestamp:
Jan 5, 2010 2:32:58 PM (15 years ago)
Author:
vboxsync
Message:

iprt: Instrumented semeventmulti-linux.cpp and hacked more on the validator and the testcase.

Location:
trunk/src/VBox/Runtime/r3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/linux/semeventmulti-linux.cpp

    r25640 r25648  
    5252*******************************************************************************/
    5353#include <iprt/semaphore.h>
     54#include "internal/iprt.h"
     55
    5456#include <iprt/assert.h>
    55 #include <iprt/alloc.h>
    5657#include <iprt/asm.h>
    5758#include <iprt/err.h>
     59#include <iprt/lockvalidator.h>
     60#include <iprt/mem.h>
    5861#include <iprt/time.h>
    5962#include "internal/magics.h"
     63#include "internal/strict.h"
     64
    6065
    6166#include <errno.h>
     
    8287{
    8388    /** Magic value. */
    84     intptr_t volatile   iMagic;
     89    uint32_t volatile   u32Magic;
    8590    /** The futex state variable.
    8691     * -1 means signaled.
     
    8994     */
    9095    int32_t volatile    iState;
     96#ifdef RTSEMEVENTMULTI_STRICT
     97    /** Signallers. */
     98    RTLOCKVALRECSHRD    Signallers;
     99    /** Indicates that lock validation should be performed. */
     100    bool volatile       fEverHadSignallers;
     101#endif
    91102};
    92103
     
    116127    if (pThis)
    117128    {
    118         pThis->iMagic = RTSEMEVENTMULTI_MAGIC;
    119         pThis->iState = 0;
     129        pThis->u32Magic = RTSEMEVENTMULTI_MAGIC;
     130        pThis->iState   = 0;
     131#ifdef RTSEMEVENTMULTI_STRICT
     132        RTLockValidatorRecSharedInit(&pThis->Signallers,
     133                                     NIL_RTLOCKVALIDATORCLASS, RTLOCKVALIDATOR_SUB_CLASS_ANY,
     134                                     "RTSemEventMulti", pThis, true /*fSignaller*/);
     135        pThis->fEverHadSignallers = false;
     136#endif
    120137        *pEventMultiSem = pThis;
    121138        return VINF_SUCCESS;
     
    131148     */
    132149    struct RTSEMEVENTMULTIINTERNAL *pThis = EventMultiSem;
    133     AssertReturn(VALID_PTR(pThis) && pThis->iMagic == RTSEMEVENTMULTI_MAGIC,
     150    AssertReturn(VALID_PTR(pThis) && pThis->u32Magic == RTSEMEVENTMULTI_MAGIC,
    134151                 VERR_INVALID_HANDLE);
    135152
     
    137154     * Invalidate the semaphore and wake up anyone waiting on it.
    138155     */
    139     ASMAtomicWriteSize(&pThis->iMagic, RTSEMEVENTMULTI_MAGIC + 1);
     156    ASMAtomicWriteSize(&pThis->u32Magic, RTSEMEVENTMULTI_MAGIC + 1);
    140157    if (ASMAtomicXchgS32(&pThis->iState, -1) == 1)
    141158    {
     
    147164     * Free the semaphore memory and be gone.
    148165     */
     166#ifdef RTSEMEVENTMULTI_STRICT
     167    RTLockValidatorRecSharedDelete(&pThis->Signallers);
     168#endif
    149169    RTMemFree(pThis);
    150170    return VINF_SUCCESS;
     
    158178     */
    159179    struct RTSEMEVENTMULTIINTERNAL *pThis = EventMultiSem;
    160     AssertReturn(VALID_PTR(pThis) && pThis->iMagic == RTSEMEVENTMULTI_MAGIC,
     180    AssertReturn(VALID_PTR(pThis) && pThis->u32Magic == RTSEMEVENTMULTI_MAGIC,
    161181                 VERR_INVALID_HANDLE);
     182
     183#ifdef RTSEMEVENTMULTI_STRICT
     184    if (pThis->fEverHadSignallers)
     185    {
     186        int rc9 = RTLockValidatorRecSharedCheckSignaller(&pThis->Signallers, NIL_RTTHREAD);
     187        if (RT_FAILURE(rc9))
     188            return rc9;
     189    }
     190#endif
     191
     192
    162193    /*
    163194     * Signal it.
     
    181212     */
    182213    struct RTSEMEVENTMULTIINTERNAL *pThis = EventMultiSem;
    183     AssertReturn(VALID_PTR(pThis) && pThis->iMagic == RTSEMEVENTMULTI_MAGIC,
     214    AssertReturn(VALID_PTR(pThis) && pThis->u32Magic == RTSEMEVENTMULTI_MAGIC,
    184215                 VERR_INVALID_HANDLE);
    185216#ifdef RT_STRICT
     
    198229static int rtSemEventMultiWait(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies, bool fAutoResume)
    199230{
     231    PCRTLOCKVALSRCPOS pSrcPos = NULL;
     232
    200233    /*
    201234     * Validate input.
    202235     */
    203236    struct RTSEMEVENTMULTIINTERNAL *pThis = EventMultiSem;
    204     AssertReturn(VALID_PTR(pThis) && pThis->iMagic == RTSEMEVENTMULTI_MAGIC,
     237    AssertReturn(VALID_PTR(pThis) && pThis->u32Magic == RTSEMEVENTMULTI_MAGIC,
    205238                 VERR_INVALID_HANDLE);
    206239
     
    221254    if (cMillies != RT_INDEFINITE_WAIT)
    222255    {
     256        /* If the timeout is zero, then we're done. */
    223257        if (!cMillies)
    224258            return VERR_TIMEOUT;
     
    232266     * The wait loop.
    233267     */
     268#ifdef RTSEMEVENTMULTI_STRICT
     269    RTTHREAD hThreadSelf = RTThreadSelfAutoAdopt();
     270#else
     271    RTTHREAD hThreadSelf = RTThreadSelf();
     272#endif
    234273    for (unsigned i = 0;; i++)
    235274    {
     
    252291                ts.tv_nsec = i64Diff % 1000000000;
    253292            }
     293#ifdef RTSEMEVENTMULTI_STRICT
     294            if (pThis->fEverHadSignallers)
     295            {
     296                int rc9 = RTLockValidatorRecSharedCheckBlocking(&pThis->Signallers, hThreadSelf, pSrcPos, false,
     297                                                                RTTHREADSTATE_EVENT_MULTI, true);
     298                if (RT_FAILURE(rc9))
     299                    return rc9;
     300            }
     301#endif
     302            RTThreadBlocking(hThreadSelf, RTTHREADSTATE_EVENT_MULTI, true);
    254303            long rc = sys_futex(&pThis->iState, FUTEX_WAIT, 1, pTimeout, NULL, 0);
    255             if (RT_UNLIKELY(pThis->iMagic != RTSEMEVENTMULTI_MAGIC))
     304            RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_EVENT_MULTI);
     305            if (RT_UNLIKELY(pThis->u32Magic != RTSEMEVENTMULTI_MAGIC))
    256306                return VERR_SEM_DESTROYED;
    257307            if (rc == 0)
     
    263313            if (rc == -ETIMEDOUT)
    264314            {
    265 /** @something is broken here. shows up every now and again in the ata code. Should try to run the timeout against RTTimeMilliTS to check that it's doing the right thing... */
     315/** @todo something is broken here. shows up every now and again in the ata
     316 *        code. Should try to run the timeout against RTTimeMilliTS to
     317 *        check that it's doing the right thing... */
    266318                Assert(pTimeout);
    267319                return VERR_TIMEOUT;
     
    303355RTDECL(void) RTSemEventMultiSetSignaller(RTSEMEVENTMULTI hEventMultiSem, RTTHREAD hThread)
    304356{
    305     /** @todo implement RTSemEventMultiSetSignaller on OS/2 */
     357#ifdef RTSEMEVENTMULTI_STRICT
     358    struct RTSEMEVENTMULTIINTERNAL *pThis = hEventMultiSem;
     359    AssertPtrReturnVoid(pThis);
     360    AssertReturnVoid(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC);
     361
     362    ASMAtomicWriteBool(&pThis->fEverHadSignallers, true);
     363    RTLockValidatorRecSharedResetOwner(&pThis->Signallers, hThread, NULL);
     364#endif
    306365}
    307366
     
    309368RTDECL(void) RTSemEventMultiAddSignaller(RTSEMEVENTMULTI hEventMultiSem, RTTHREAD hThread)
    310369{
     370#ifdef RTSEMEVENTMULTI_STRICT
     371    struct RTSEMEVENTMULTIINTERNAL *pThis = hEventMultiSem;
     372    AssertPtrReturnVoid(pThis);
     373    AssertReturnVoid(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC);
     374
     375    ASMAtomicWriteBool(&pThis->fEverHadSignallers, true);
     376    RTLockValidatorRecSharedAddOwner(&pThis->Signallers, hThread, NULL);
     377#endif
    311378}
    312379
     
    314381RTDECL(void) RTSemEventMultiRemoveSignaller(RTSEMEVENTMULTI hEventMultiSem, RTTHREAD hThread)
    315382{
     383#ifdef RTSEMEVENTMULTI_STRICT
     384    struct RTSEMEVENTMULTIINTERNAL *pThis = hEventMultiSem;
     385    AssertPtrReturnVoid(pThis);
     386    AssertReturnVoid(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC);
     387
     388    RTLockValidatorRecSharedRemoveOwner(&pThis->Signallers, hThread);
     389#endif
    316390}
    317391
  • trunk/src/VBox/Runtime/r3/posix/semeventmulti-posix.cpp

    r25640 r25648  
    124124                        RTLockValidatorRecSharedInit(&pThis->Signallers,
    125125                                                     NIL_RTLOCKVALIDATORCLASS, RTLOCKVALIDATOR_SUB_CLASS_ANY,
    126                                                      "RTSemEvent", pThis, true /*fSignaller*/);
     126                                                     "RTSemEventMulti", pThis, true /*fSignaller*/);
    127127                        pThis->fEverHadSignallers = false;
    128128#endif
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