VirtualBox

Changeset 20448 in vbox for trunk/src


Ignore:
Timestamp:
Jun 9, 2009 10:21:09 PM (16 years ago)
Author:
vboxsync
Message:

Runtime/semevent-r0drv-freebsd: Use a sleeping mutex instead of a spinlock to fix the problems users are seeing (assertions with debugging enabled) while still being able to run on 100Hz hosts. No problems detected so far and Solaris doesn't use a spin mutex in this code too so it shouldn't do any harm (keeping fingers crossed)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/freebsd/semevent-r0drv-freebsd.c

    r20208 r20448  
    7676        pEventInt->cWaking = 0;
    7777        pEventInt->fSignaled = 0;
    78         mtx_init(&pEventInt->Mtx, "IPRT Event Semaphore", NULL, MTX_SPIN);
     78        mtx_init(&pEventInt->Mtx, "IPRT Event Semaphore", NULL, 0);
    7979        *pEventSem = pEventInt;
    8080        return VINF_SUCCESS;
     
    9494                    VERR_INVALID_HANDLE);
    9595
    96     mtx_lock_spin(&pEventInt->Mtx);
     96    mtx_lock(&pEventInt->Mtx);
    9797    ASMAtomicIncU32(&pEventInt->u32Magic); /* make the handle invalid */
    9898    if (pEventInt->cWaiters > 0)
     
    101101        ASMAtomicXchgU32(&pEventInt->cWaking, pEventInt->cWaking + pEventInt->cWaiters);
    102102        wakeup(pEventInt);
    103         mtx_unlock_spin(&pEventInt->Mtx);
     103        mtx_unlock(&pEventInt->Mtx);
    104104    }
    105105    else if (pEventInt->cWaking)
    106106        /* the last waking thread is gonna do the cleanup */
    107         mtx_unlock_spin(&pEventInt->Mtx);
     107        mtx_unlock(&pEventInt->Mtx);
    108108    else
    109109    {
    110         mtx_unlock_spin(&pEventInt->Mtx);
     110        mtx_unlock(&pEventInt->Mtx);
    111111        mtx_destroy(&pEventInt->Mtx);
    112112        RTMemFree(pEventInt);
     
    125125                    VERR_INVALID_HANDLE);
    126126
    127     mtx_lock_spin(&pEventInt->Mtx);
     127    mtx_lock(&pEventInt->Mtx);
    128128
    129129    if (pEventInt->cWaiters > 0)
     
    136136        ASMAtomicXchgU8(&pEventInt->fSignaled, true);
    137137
    138     mtx_unlock_spin(&pEventInt->Mtx);
     138    mtx_unlock(&pEventInt->Mtx);
    139139    return VINF_SUCCESS;
    140140}
     
    150150                    VERR_INVALID_HANDLE);
    151151
    152     mtx_lock_spin(&pEventInt->Mtx);
     152    mtx_lock(&pEventInt->Mtx);
    153153
    154154    if (pEventInt->fSignaled)
     
    173173        ASMAtomicIncU32(&pEventInt->cWaiters);
    174174
    175         mtx_unlock_spin(&pEventInt->Mtx);
    176 /** @todo r=bird: This doesn't handle cMillies == 0 correctly, it will assert
    177  *        and or sleep for ever according to r47861. (That's probably an old bug
    178  *        of my making.)
    179  *
    180  *        And it really looks like it's racing signalling on MP systems. (It
    181  *        *looks* like you leave the lock and then tries to go to sleep on a
    182  *        block id, someone spinning on the lock attempt to wake us up before we
    183  *        go to sleep. That's why the code was originally trying to use msleep
    184  *        here.). */
    185         rc = tsleep(pEventInt,          /* block id */
    186                     fInterruptible ? PZERO | PCATCH : PZERO,
    187                     "iprtev",           /* max 6 chars */
    188                     cMillies == RT_INDEFINITE_WAIT
    189                     ? 0
    190                     : tvtohz(&tv));
    191         mtx_lock_spin(&pEventInt->Mtx);
     175        /** @todo r=bird: This doesn't handle cMillies == 0 correctly, it will assert
     176         *        and or sleep for ever according to r47861. (That's probably an old bug
     177         *        of my making.)
     178         */
     179        rc = mtx_sleep(pEventInt,          /* block id */
     180                       &pEventInt->Mtx,    /* mtx */
     181                       fInterruptible ? PZERO | PCATCH : PZERO,
     182                       "iprtev",           /* max 6 chars */
     183                       cMillies == RT_INDEFINITE_WAIT
     184                       ? 0
     185                       : tvtohz(&tv));
    192186
    193187        switch (rc)
     
    207201                        /* The event was destroyed, as the last thread do the cleanup.
    208202                           we don't actually know whether */
    209                         mtx_unlock_spin(&pEventInt->Mtx);
     203                        mtx_unlock(&pEventInt->Mtx);
    210204                        mtx_destroy(&pEventInt->Mtx);
    211205                        RTMemFree(pEventInt);
     
    237231    }
    238232
    239     mtx_unlock_spin(&pEventInt->Mtx);
     233    mtx_unlock(&pEventInt->Mtx);
    240234    return rc;
    241235}
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