VirtualBox

Changeset 25638 in vbox for trunk/src/VBox/Runtime/r3/posix


Ignore:
Timestamp:
Jan 4, 2010 4:08:04 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
56338
Message:

iprt,pdmcritsect: Added RTSemEvent[Set|Add|Remove]Signaller so that we can validate who is signalling an event if we like and, more importantly, detect deadlocks involving event semaphores. More attempts at dealing with the races (and bugs) in the all-other-threads-blocking detection in tstRTLockValidator.cpp, adding RTThreadGetReallySleeping and RTThreadGetNativeState in the process.

Location:
trunk/src/VBox/Runtime/r3/posix
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/posix/semevent-posix.cpp

    r14318 r25638  
    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
     
    3333*******************************************************************************/
    3434#include <iprt/semaphore.h>
     35#include "internal/iprt.h"
     36
     37#include <iprt/asm.h>
    3538#include <iprt/assert.h>
    36 #include <iprt/alloc.h>
    37 #include <iprt/asm.h>
    3839#include <iprt/err.h>
     40#include <iprt/mem.h>
     41#include <iprt/lockvalidator.h>
     42
     43#include "internal/strict.h"
    3944
    4045#include <errno.h>
     
    7277    /** Number of waiters. */
    7378    volatile uint32_t   cWaiters;
     79#ifdef RTSEMEVENT_STRICT
     80    /** Signallers. */
     81    RTLOCKVALRECSHRD    Signallers;
     82    /** Indicates that lock validation should be performed. */
     83    bool volatile       fEverHadSignallers;
     84#endif
    7485};
    7586
     
    8596
    8697
    87 /**
    88  * Validate an Event semaphore handle passed to one of the interface.
    89  *
    90  * @returns true if valid.
    91  * @returns false if invalid.
    92  * @param   pIntEventSem    Pointer to the event semaphore to validate.
    93  */
    94 inline bool rtsemEventValid(struct RTSEMEVENTINTERNAL *pIntEventSem)
    95 {
    96     if ((uintptr_t)pIntEventSem < 0x10000)
    97         return false;
    98 
    99     uint32_t    u32 = pIntEventSem->u32State; /* this is volatile, so a explicit read like this is needed. */
    100     if (    u32 != EVENT_STATE_NOT_SIGNALED
    101         &&  u32 != EVENT_STATE_SIGNALED)
    102         return false;
    103 
    104     return true;
    105 }
    106 
    107 
    10898RTDECL(int)  RTSemEventCreate(PRTSEMEVENT pEventSem)
    10999{
     
    113103     * Allocate semaphore handle.
    114104     */
    115     struct RTSEMEVENTINTERNAL *pIntEventSem = (struct RTSEMEVENTINTERNAL *)RTMemAlloc(sizeof(struct RTSEMEVENTINTERNAL));
    116     if (pIntEventSem)
     105    struct RTSEMEVENTINTERNAL *pThis = (struct RTSEMEVENTINTERNAL *)RTMemAlloc(sizeof(struct RTSEMEVENTINTERNAL));
     106    if (pThis)
    117107    {
    118108        /*
     
    123113        if (!rc)
    124114        {
    125             rc = pthread_cond_init(&pIntEventSem->Cond, &CondAttr);
     115            rc = pthread_cond_init(&pThis->Cond, &CondAttr);
    126116            if (!rc)
    127117            {
     
    133123                if (!rc)
    134124                {
    135                     rc = pthread_mutex_init(&pIntEventSem->Mutex, &MutexAttr);
     125                    rc = pthread_mutex_init(&pThis->Mutex, &MutexAttr);
    136126                    if (!rc)
    137127                    {
     
    139129                        pthread_condattr_destroy(&CondAttr);
    140130
    141                         ASMAtomicXchgU32(&pIntEventSem->u32State, EVENT_STATE_NOT_SIGNALED);
    142                         ASMAtomicXchgU32(&pIntEventSem->cWaiters, 0);
    143 
    144                         *pEventSem = pIntEventSem;
     131                        ASMAtomicXchgU32(&pThis->u32State, EVENT_STATE_NOT_SIGNALED);
     132                        ASMAtomicXchgU32(&pThis->cWaiters, 0);
     133#ifdef RTSEMEVENT_STRICT
     134                        RTLockValidatorRecSharedInit(&pThis->Signallers,
     135                                                     NIL_RTLOCKVALIDATORCLASS, RTLOCKVALIDATOR_SUB_CLASS_ANY,
     136                                                     "RTSemEvent", pThis, true /*fSignaller*/);
     137                        pThis->fEverHadSignallers = false;
     138#endif
     139
     140                        *pEventSem = pThis;
    145141                        return VINF_SUCCESS;
    146142                    }
    147143                    pthread_mutexattr_destroy(&MutexAttr);
    148144                }
    149                 pthread_cond_destroy(&pIntEventSem->Cond);
     145                pthread_cond_destroy(&pThis->Cond);
    150146            }
    151147            pthread_condattr_destroy(&CondAttr);
     
    153149
    154150        rc = RTErrConvertFromErrno(rc);
    155         RTMemFree(pIntEventSem);
     151        RTMemFree(pThis);
    156152    }
    157153    else
     
    167163     * Validate handle.
    168164     */
    169     if (EventSem == NIL_RTSEMEVENT)     /* don't bitch */
     165    struct RTSEMEVENTINTERNAL *pThis = EventSem;
     166    if (pThis == NIL_RTSEMEVENT)        /* don't bitch */
    170167        return VERR_INVALID_HANDLE;
    171     if (!rtsemEventValid(EventSem))
    172     {
    173         AssertMsgFailed(("Invalid handle %p!\n", EventSem));
    174         return VERR_INVALID_HANDLE;
    175     }
     168    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     169    uint32_t    u32 = pThis->u32State;
     170    AssertReturn(u32 == EVENT_STATE_NOT_SIGNALED || u32 == EVENT_STATE_SIGNALED, VERR_INVALID_HANDLE);
    176171
    177172    /*
    178173     * Abort all waiters forcing them to return failure.
    179      *
    180      */
    181     struct RTSEMEVENTINTERNAL *pIntEventSem = EventSem;
     174     */
    182175    int rc;
    183176    for (int i = 30; i > 0; i--)
    184177    {
    185         ASMAtomicXchgU32(&pIntEventSem->u32State, EVENT_STATE_UNINITIALIZED);
    186         rc = pthread_cond_destroy(&pIntEventSem->Cond);
     178        ASMAtomicXchgU32(&pThis->u32State, EVENT_STATE_UNINITIALIZED);
     179        rc = pthread_cond_destroy(&pThis->Cond);
    187180        if (rc != EBUSY)
    188181            break;
    189         pthread_cond_broadcast(&pIntEventSem->Cond);
     182        pthread_cond_broadcast(&pThis->Cond);
    190183        usleep(1000);
    191184    }
     
    202195    for (int i = 30; i > 0; i--)
    203196    {
    204         rc = pthread_mutex_destroy(&pIntEventSem->Mutex);
     197        rc = pthread_mutex_destroy(&pThis->Mutex);
    205198        if (rc != EBUSY)
    206199            break;
     
    216209     * Free the semaphore memory and be gone.
    217210     */
    218     RTMemFree(pIntEventSem);
     211#ifdef RTSEMEVENT_STRICT
     212    RTLockValidatorRecSharedDelete(&pThis->Signallers);
     213#endif
     214    RTMemFree(pThis);
    219215    return VINF_SUCCESS;
    220216}
     
    226222     * Validate input.
    227223     */
    228     if (!rtsemEventValid(EventSem))
    229     {
    230         AssertMsgFailed(("Invalid handle %p!\n", EventSem));
    231         return VERR_INVALID_HANDLE;
    232     }
     224    struct RTSEMEVENTINTERNAL *pThis = EventSem;
     225    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     226    uint32_t    u32 = pThis->u32State;
     227    AssertReturn(u32 == EVENT_STATE_NOT_SIGNALED || u32 == EVENT_STATE_SIGNALED, VERR_INVALID_HANDLE);
     228
     229#ifdef RTSEMEVENT_STRICT
     230    if (pThis->fEverHadSignallers)
     231    {
     232        int rc9 = RTLockValidatorRecSharedCheckSignaller(&pThis->Signallers, NIL_RTTHREAD);
     233        if (RT_FAILURE(rc9))
     234            return rc9;
     235    }
     236#endif
    233237
    234238    /*
    235239     * Lock the mutex semaphore.
    236240     */
    237     struct RTSEMEVENTINTERNAL *pIntEventSem = EventSem;
    238     int rc = pthread_mutex_lock(&pIntEventSem->Mutex);
     241    int rc = pthread_mutex_lock(&pThis->Mutex);
    239242    if (rc)
    240243    {
     
    246249     * Check the state.
    247250     */
    248     if (pIntEventSem->u32State == EVENT_STATE_NOT_SIGNALED)
    249     {
    250         ASMAtomicXchgU32(&pIntEventSem->u32State, EVENT_STATE_SIGNALED);
    251         rc = pthread_cond_signal(&pIntEventSem->Cond);
     251    if (pThis->u32State == EVENT_STATE_NOT_SIGNALED)
     252    {
     253        ASMAtomicXchgU32(&pThis->u32State, EVENT_STATE_SIGNALED);
     254        rc = pthread_cond_signal(&pThis->Cond);
    252255        AssertMsg(!rc, ("Failed to signal event sem %p, rc=%d.\n", EventSem, rc));
    253256    }
    254     else if (pIntEventSem->u32State == EVENT_STATE_SIGNALED)
    255     {
    256         rc = pthread_cond_signal(&pIntEventSem->Cond); /* give'm another kick... */
     257    else if (pThis->u32State == EVENT_STATE_SIGNALED)
     258    {
     259        rc = pthread_cond_signal(&pThis->Cond); /* give'm another kick... */
    257260        AssertMsg(!rc, ("Failed to signal event sem %p, rc=%d. (2)\n", EventSem, rc));
    258261    }
     
    263266     * Release the mutex and return.
    264267     */
    265     int rc2 = pthread_mutex_unlock(&pIntEventSem->Mutex);
     268    int rc2 = pthread_mutex_unlock(&pThis->Mutex);
    266269    AssertMsg(!rc2, ("Failed to unlock event sem %p, rc=%d.\n", EventSem, rc));
    267270    if (rc)
     
    274277
    275278
    276 static int  rtSemEventWait(RTSEMEVENT EventSem, unsigned cMillies, bool fAutoResume)
    277 {
     279DECL_FORCE_INLINE(int) rtSemEventWait(RTSEMEVENT EventSem, unsigned cMillies, bool fAutoResume)
     280{
     281    PCRTLOCKVALSRCPOS  pSrcPos = NULL;
     282
    278283    /*
    279284     * Validate input.
    280285     */
    281     if (!rtsemEventValid(EventSem))
    282     {
    283         AssertMsgFailed(("Invalid handle %p!\n", EventSem));
    284         return VERR_INVALID_HANDLE;
    285     }
     286    struct RTSEMEVENTINTERNAL *pThis = EventSem;
     287    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     288    uint32_t    u32 = pThis->u32State;
     289    AssertReturn(u32 == EVENT_STATE_NOT_SIGNALED || u32 == EVENT_STATE_SIGNALED, VERR_INVALID_HANDLE);
    286290
    287291    /*
    288292     * Timed or indefinite wait?
    289293     */
    290     struct RTSEMEVENTINTERNAL *pIntEventSem = EventSem;
    291294    if (cMillies == RT_INDEFINITE_WAIT)
    292295    {
    293296        /* for fairness, yield before going to sleep. */
    294         if (    ASMAtomicIncU32(&pIntEventSem->cWaiters) > 1
    295             &&  pIntEventSem->u32State == EVENT_STATE_SIGNALED)
     297        if (    ASMAtomicIncU32(&pThis->cWaiters) > 1
     298            &&  pThis->u32State == EVENT_STATE_SIGNALED)
    296299            pthread_yield();
    297300
    298301         /* take mutex */
    299         int rc = pthread_mutex_lock(&pIntEventSem->Mutex);
     302        int rc = pthread_mutex_lock(&pThis->Mutex);
    300303        if (rc)
    301304        {
    302             ASMAtomicDecU32(&pIntEventSem->cWaiters);
     305            ASMAtomicDecU32(&pThis->cWaiters);
    303306            AssertMsgFailed(("Failed to lock event sem %p, rc=%d.\n", EventSem, rc));
    304307            return RTErrConvertFromErrno(rc);
     
    308311        {
    309312            /* check state. */
    310             if (pIntEventSem->u32State == EVENT_STATE_SIGNALED)
    311             {
    312                 ASMAtomicXchgU32(&pIntEventSem->u32State, EVENT_STATE_NOT_SIGNALED);
    313                 ASMAtomicDecU32(&pIntEventSem->cWaiters);
    314                 rc = pthread_mutex_unlock(&pIntEventSem->Mutex);
     313            if (pThis->u32State == EVENT_STATE_SIGNALED)
     314            {
     315                ASMAtomicXchgU32(&pThis->u32State, EVENT_STATE_NOT_SIGNALED);
     316                ASMAtomicDecU32(&pThis->cWaiters);
     317                rc = pthread_mutex_unlock(&pThis->Mutex);
    315318                AssertMsg(!rc, ("Failed to unlock event sem %p, rc=%d.\n", EventSem, rc)); NOREF(rc);
    316319                return VINF_SUCCESS;
    317320            }
    318             if (pIntEventSem->u32State == EVENT_STATE_UNINITIALIZED)
    319             {
    320                 rc = pthread_mutex_unlock(&pIntEventSem->Mutex);
     321            if (pThis->u32State == EVENT_STATE_UNINITIALIZED)
     322            {
     323                rc = pthread_mutex_unlock(&pThis->Mutex);
    321324                AssertMsg(!rc, ("Failed to unlock event sem %p, rc=%d.\n", EventSem, rc)); NOREF(rc);
    322325                return VERR_SEM_DESTROYED;
     
    324327
    325328            /* wait */
    326             rc = pthread_cond_wait(&pIntEventSem->Cond, &pIntEventSem->Mutex);
     329#ifdef RTSEMEVENT_STRICT
     330            RTTHREAD hThreadSelf = RTThreadSelfAutoAdopt();
     331            if (pThis->fEverHadSignallers)
     332            {
     333                rc = RTLockValidatorRecSharedCheckBlocking(&pThis->Signallers, hThreadSelf, pSrcPos, false,
     334                                                           RTTHREADSTATE_EVENT, true);
     335                if (RT_FAILURE(rc))
     336                {
     337                    ASMAtomicDecU32(&pThis->cWaiters);
     338                    pthread_mutex_unlock(&pThis->Mutex);
     339                    return rc;
     340                }
     341            }
     342#else
     343            RTTHREAD hThreadSelf = RTThreadSelf();
     344#endif
     345            RTThreadBlocking(hThreadSelf, RTTHREADSTATE_EVENT, true);
     346            rc = pthread_cond_wait(&pThis->Cond, &pThis->Mutex);
     347            RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_EVENT);
    327348            if (rc)
    328349            {
    329350                AssertMsgFailed(("Failed to wait on event sem %p, rc=%d.\n", EventSem, rc));
    330                 ASMAtomicDecU32(&pIntEventSem->cWaiters);
    331                 int rc2 = pthread_mutex_unlock(&pIntEventSem->Mutex);
     351                ASMAtomicDecU32(&pThis->cWaiters);
     352                int rc2 = pthread_mutex_unlock(&pThis->Mutex);
    332353                AssertMsg(!rc2, ("Failed to unlock event sem %p, rc=%d.\n", EventSem, rc2)); NOREF(rc2);
    333354                return RTErrConvertFromErrno(rc);
     
    361382
    362383        /* for fairness, yield before going to sleep. */
    363         if (ASMAtomicIncU32(&pIntEventSem->cWaiters) > 1)
     384        if (ASMAtomicIncU32(&pThis->cWaiters) > 1 && cMillies)
    364385            pthread_yield();
    365386
    366387        /* take mutex */
    367 #ifdef RT_OS_DARWIN
    368         int rc = pthread_mutex_lock(&pIntEventSem->Mutex);
    369 #else
    370         int rc = pthread_mutex_timedlock(&pIntEventSem->Mutex, &ts);
    371 #endif
     388        int rc = pthread_mutex_lock(&pThis->Mutex);
    372389        if (rc)
    373390        {
    374             ASMAtomicDecU32(&pIntEventSem->cWaiters);
     391            ASMAtomicDecU32(&pThis->cWaiters);
    375392            AssertMsg(rc == ETIMEDOUT, ("Failed to lock event sem %p, rc=%d.\n", EventSem, rc));
    376393            return RTErrConvertFromErrno(rc);
     
    380397        {
    381398            /* check state. */
    382             if (pIntEventSem->u32State == EVENT_STATE_SIGNALED)
    383             {
    384                 ASMAtomicXchgU32(&pIntEventSem->u32State, EVENT_STATE_NOT_SIGNALED);
    385                 ASMAtomicDecU32(&pIntEventSem->cWaiters);
    386                 rc = pthread_mutex_unlock(&pIntEventSem->Mutex);
     399            if (pThis->u32State == EVENT_STATE_SIGNALED)
     400            {
     401                ASMAtomicXchgU32(&pThis->u32State, EVENT_STATE_NOT_SIGNALED);
     402                ASMAtomicDecU32(&pThis->cWaiters);
     403                rc = pthread_mutex_unlock(&pThis->Mutex);
    387404                AssertMsg(!rc, ("Failed to unlock event sem %p, rc=%d.\n", EventSem, rc)); NOREF(rc);
    388405                return VINF_SUCCESS;
    389406            }
    390             if (pIntEventSem->u32State == EVENT_STATE_UNINITIALIZED)
    391             {
    392                 rc = pthread_mutex_unlock(&pIntEventSem->Mutex);
     407            if (pThis->u32State == EVENT_STATE_UNINITIALIZED)
     408            {
     409                rc = pthread_mutex_unlock(&pThis->Mutex);
    393410                AssertMsg(!rc, ("Failed to unlock event sem %p, rc=%d.\n", EventSem, rc)); NOREF(rc);
    394411                return VERR_SEM_DESTROYED;
    395412            }
    396413
     414            /* we're done if the timeout is 0. */
     415            if (!cMillies)
     416            {
     417                ASMAtomicDecU32(&pThis->cWaiters);
     418                rc = pthread_mutex_unlock(&pThis->Mutex);
     419                return VERR_SEM_BUSY;
     420            }
     421
    397422            /* wait */
    398             rc = pthread_cond_timedwait(&pIntEventSem->Cond, &pIntEventSem->Mutex, &ts);
     423#ifdef RTSEMEVENT_STRICT
     424            RTTHREAD hThreadSelf = RTThreadSelfAutoAdopt();
     425            if (pThis->fEverHadSignallers)
     426            {
     427                rc = RTLockValidatorRecSharedCheckBlocking(&pThis->Signallers, hThreadSelf, pSrcPos, false,
     428                                                           RTTHREADSTATE_EVENT, true);
     429                if (RT_FAILURE(rc))
     430                {
     431                    ASMAtomicDecU32(&pThis->cWaiters);
     432                    pthread_mutex_unlock(&pThis->Mutex);
     433                    return rc;
     434                }
     435            }
     436#else
     437            RTTHREAD hThreadSelf = RTThreadSelf();
     438#endif
     439            RTThreadBlocking(hThreadSelf, RTTHREADSTATE_EVENT, true);
     440            rc = pthread_cond_timedwait(&pThis->Cond, &pThis->Mutex, &ts);
     441            RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_EVENT);
    399442            if (rc && (rc != EINTR || !fAutoResume)) /* according to SuS this function shall not return EINTR, but linux man page says differently. */
    400443            {
    401444                AssertMsg(rc == ETIMEDOUT, ("Failed to wait on event sem %p, rc=%d.\n", EventSem, rc));
    402                 ASMAtomicDecU32(&pIntEventSem->cWaiters);
    403                 int rc2 = pthread_mutex_unlock(&pIntEventSem->Mutex);
     445                ASMAtomicDecU32(&pThis->cWaiters);
     446                int rc2 = pthread_mutex_unlock(&pThis->Mutex);
    404447                AssertMsg(!rc2, ("Failed to unlock event sem %p, rc2=%d.\n", EventSem, rc2)); NOREF(rc2);
    405448                return RTErrConvertFromErrno(rc);
     
    423466}
    424467
     468
     469RTDECL(void) RTSemEventSetSignaller(RTSEMEVENT hEventSem, RTTHREAD hThread)
     470{
     471#ifdef RTSEMEVENT_STRICT
     472    struct RTSEMEVENTINTERNAL *pThis = hEventSem;
     473    AssertPtrReturnVoid(pThis);
     474    uint32_t u32 = pThis->u32State;
     475    AssertReturnVoid(u32 == EVENT_STATE_NOT_SIGNALED || u32 == EVENT_STATE_SIGNALED);
     476
     477    ASMAtomicWriteBool(&pThis->fEverHadSignallers, true);
     478    RTLockValidatorRecSharedResetOwner(&pThis->Signallers, hThread, NULL);
     479#endif
     480}
     481
     482
     483RTDECL(void) RTSemEventAddSignaller(RTSEMEVENT hEventSem, RTTHREAD hThread)
     484{
     485#ifdef RTSEMEVENT_STRICT
     486    struct RTSEMEVENTINTERNAL *pThis = hEventSem;
     487    AssertPtrReturnVoid(pThis);
     488    uint32_t u32 = pThis->u32State;
     489    AssertReturnVoid(u32 == EVENT_STATE_NOT_SIGNALED || u32 == EVENT_STATE_SIGNALED);
     490
     491    ASMAtomicWriteBool(&pThis->fEverHadSignallers, true);
     492    RTLockValidatorRecSharedAddOwner(&pThis->Signallers, hThread, NULL);
     493#endif
     494}
     495
     496
     497RTDECL(void) RTSemEventRemoveSignaller(RTSEMEVENT hEventSem, RTTHREAD hThread)
     498{
     499#ifdef RTSEMEVENT_STRICT
     500    struct RTSEMEVENTINTERNAL *pThis = hEventSem;
     501    AssertPtrReturnVoid(pThis);
     502    uint32_t u32 = pThis->u32State;
     503    AssertReturnVoid(u32 == EVENT_STATE_NOT_SIGNALED || u32 == EVENT_STATE_SIGNALED);
     504
     505    RTLockValidatorRecSharedRemoveOwner(&pThis->Signallers, hThread);
     506#endif
     507}
     508
  • trunk/src/VBox/Runtime/r3/posix/semmutex-posix.cpp

    r25628 r25638  
    188188#ifdef RTSEMMUTEX_STRICT
    189189        hThreadSelf = RTThreadSelfAutoAdopt();
    190         int rc9 = RTLockValidatorRecExclCheckOrderAndBlocking(&pThis->ValidatorRec, hThreadSelf, pSrcPos, true, RTTHREADSTATE_MUTEX);
     190        int rc9 = RTLockValidatorRecExclCheckOrderAndBlocking(&pThis->ValidatorRec, hThreadSelf, pSrcPos, true,
     191                                                              RTTHREADSTATE_MUTEX, true);
    191192        if (RT_FAILURE(rc9))
    192193            return rc9;
    193194#else
    194195        hThreadSelf = RTThreadSelf();
    195         RTThreadBlocking(hThreadSelf, RTTHREADSTATE_MUTEX);
     196        RTThreadBlocking(hThreadSelf, RTTHREADSTATE_MUTEX, true);
    196197#endif
    197198    }
  • trunk/src/VBox/Runtime/r3/posix/semrw-posix.cpp

    r25620 r25638  
    127127#ifdef RTSEMRW_STRICT
    128128                RTLockValidatorRecExclInit(&pThis->ValidatorWrite, NIL_RTLOCKVALIDATORCLASS, RTLOCKVALIDATOR_SUB_CLASS_NONE, "RTSemRW", pThis);
    129                 RTLockValidatorRecSharedInit(&pThis->ValidatorRead,  NIL_RTLOCKVALIDATORCLASS, RTLOCKVALIDATOR_SUB_CLASS_NONE, "RTSemRW", pThis);
     129                RTLockValidatorRecSharedInit(&pThis->ValidatorRead,  NIL_RTLOCKVALIDATORCLASS, RTLOCKVALIDATOR_SUB_CLASS_NONE, "RTSemRW", pThis, false /*fSignaller*/);
    130130                RTLockValidatorRecMakeSiblings(&pThis->ValidatorWrite.Core, &pThis->ValidatorRead.Core);
    131131#endif
     
    224224#ifdef RTSEMRW_STRICT
    225225        hThreadSelf = RTThreadSelfAutoAdopt();
    226         int rc9 = RTLockValidatorRecSharedCheckOrderAndBlocking(&pThis->ValidatorRead, hThreadSelf, pSrcPos, true, RTTHREADSTATE_RW_READ);
     226        int rc9 = RTLockValidatorRecSharedCheckOrderAndBlocking(&pThis->ValidatorRead, hThreadSelf, pSrcPos, true,
     227                                                                RTTHREADSTATE_RW_READ, true);
    227228        if (RT_FAILURE(rc9))
    228229            return rc9;
    229230#else
    230231        hThreadSelf = RTThreadSelf();
    231         RTThreadBlocking(hThreadSelf, RTTHREADSTATE_RW_READ);
     232        RTThreadBlocking(hThreadSelf, RTTHREADSTATE_RW_READ, true);
    232233#endif
    233234    }
     
    280281    ASMAtomicIncU32(&pThis->cReaders);
    281282#ifdef RTSEMRW_STRICT
    282     RTLockValidatorSharedRecAddOwner(&pThis->ValidatorRead, hThreadSelf, pSrcPos);
     283    RTLockValidatorRecSharedAddOwner(&pThis->ValidatorRead, hThreadSelf, pSrcPos);
    283284#endif
    284285    return VINF_SUCCESS;
     
    416417#ifdef RTSEMRW_STRICT
    417418        hThreadSelf = RTThreadSelfAutoAdopt();
    418         int rc9 = RTLockValidatorRecExclCheckOrderAndBlocking(&pThis->ValidatorWrite, hThreadSelf, pSrcPos, true, RTTHREADSTATE_RW_WRITE);
     419        int rc9 = RTLockValidatorRecExclCheckOrderAndBlocking(&pThis->ValidatorWrite, hThreadSelf, pSrcPos, true,
     420                                                              RTTHREADSTATE_RW_WRITE, true);
    419421        if (RT_FAILURE(rc9))
    420422            return rc9;
    421423#else
    422424        hThreadSelf = RTThreadSelf();
    423         RTThreadBlocking(hThreadSelf, RTTHREADSTATE_RW_WRITE);
     425        RTThreadBlocking(hThreadSelf, RTTHREADSTATE_RW_WRITE, true);
    424426#endif
    425427    }
  • trunk/src/VBox/Runtime/r3/posix/thread-posix.cpp

    r13837 r25638  
    3737#include <pthread.h>
    3838#include <signal.h>
     39#if defined(RT_OS_LINUX)
     40# include <unistd.h>
     41# include <sys/syscall.h>
     42#endif
    3943#if defined(RT_OS_SOLARIS)
    4044# include <sched.h>
     
    170174    PRTTHREADINT  pThread = (PRTTHREADINT)pvArgs;
    171175
     176#if defined(RT_OS_LINUX)
     177    /*
     178     * Set the TID.
     179     */
     180    pThread->tid = syscall(__NR_gettid);
     181    ASMMemoryFence();
     182#endif
     183
    172184    /*
    173185     * Block SIGALRM - required for timer-posix.cpp.
     
    204216    if (!pThread->cbStack)
    205217        pThread->cbStack = 512*1024;
     218
     219#ifdef RT_OS_LINUX
     220    pThread->tid = -1;
     221#endif
    206222
    207223    /*
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