VirtualBox

Changeset 28533 in vbox for trunk/src/VBox/Runtime/r0drv


Ignore:
Timestamp:
Apr 20, 2010 5:38:34 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
60339
Message:

Solaris/r0drv: RTSemMutex, removed cWaking, fSignaled added cRefs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/solaris/semmutex-r0drv-solaris.c

    r28532 r28533  
    5959    /** The number of recursions. */
    6060    uint32_t                    cRecursions;
    61     /** Whether we are being woken up by a release. */
    62     uint8_t volatile            fSignaled;
    63     /** The number of waiting threads. */
     61    /** The number of threads waiting for the mutex. */
    6462    uint32_t volatile           cWaiters;
    65     /** The number of threads in the process of waking up. */
    66     uint32_t volatile           cWaking;
     63    /** The number of threads referencing us. */
     64    uint32_t volatile           cRefs;
    6765    /** The owner thread, NIL_RTNATIVETHREAD if none. */
    6866    RTNATIVETHREAD              hOwnerThread;
     
    8886    pThis->u32Magic     = RTSEMMUTEX_MAGIC;
    8987    pThis->cRecursions  = 0;
    90     pThis->fSignaled    = false;
    9188    pThis->cWaiters     = 0;
    92     pThis->cWaking      = 0;
    93     pThis->hOwnerThread   = NIL_RTNATIVETHREAD;
     89    pThis->cRefs        = 1;
     90    pThis->hOwnerThread = NIL_RTNATIVETHREAD;
    9491    mutex_init(&pThis->Mtx, "IPRT Mutex", MUTEX_DRIVER, (void *)ipltospl(DISP_LEVEL));
    9592    cv_init(&pThis->Cnd, "IPRT CVM", CV_DRIVER, NULL);
     
    113110    mutex_enter(&pThis->Mtx);
    114111
     112    ASMAtomicDecU32(&pThis->cRefs);
     113
    115114    /*
    116115     * Invalidate the magic to indicate the mutex is being destroyed.
     
    122121         * Wake up all waiters, last waiter thread cleans up.
    123122         */
    124         ASMAtomicXchgU32(&pThis->cWaking, pThis->cWaking + pThis->cWaiters);
    125123        cv_broadcast(&pThis->Cnd);
    126124        mutex_exit(&pThis->Mtx);
    127125    }
    128     else if (pThis->cWaking)
    129     {
    130         /*
    131          * We're not the last waiting thread to be woken up. Just relinquish & bail.
    132          */
    133         mutex_exit(&pThis->Mtx);
    134     }
    135     else
     126    else if (pThis->cRefs == 0)
    136127    {
    137128        /*
     
    142133        mutex_destroy(&pThis->Mtx);
    143134        RTMemFree(pThis);
     135    }
     136    else
     137    {
     138        /*
     139         * We're not the last waiting thread to be woken up. Just relinquish & bail.
     140         */
     141        mutex_exit(&pThis->Mtx);
    144142    }
    145143
     
    166164
    167165    /*
    168      * Now we wait (sleep; although might spin and then sleep).
     166     * Now we wait (sleep; although might spin and then sleep) & reference the mutex.
    169167     */
    170168    ASMAtomicIncU32(&pThis->cWaiters);
     169    ASMAtomicIncU32(&pThis->cRefs);
    171170
    172171    if (cMillies != RT_INDEFINITE_WAIT)
     
    191190    }
    192191
     192    ASMAtomicDecU32(&pThis->cWaiters);
    193193    if (rc > 0)
    194194    {
    195195        if (pThis->u32Magic == RTSEMMUTEX_MAGIC)
    196196        {
    197             if (pThis->fSignaled)
     197            if (pThis->hOwnerThread == NIL_RTNATIVETHREAD)
    198198            {
    199199                /*
    200200                 * Woken up by a release from another thread.
    201201                 */
    202                 ASMAtomicDecU32(&pThis->cWaking);
    203                 ASMAtomicXchgU8(&pThis->fSignaled, false);
    204                 pThis->cRecursions++;
     202                Assert(pThis->cRecursions == 0);
     203                pThis->cRecursions = 1;
    205204                pThis->hOwnerThread = RTThreadNativeSelf();
    206205                rc = VINF_SUCCESS;
     
    212211                 */
    213212                rc= VERR_INTERRUPTED;
    214                 ASMAtomicDecU32(&pThis->cWaiters);
    215213            }
    216214        }
     
    222220             */
    223221            rc = VERR_SEM_DESTROYED;
    224             if (!ASMAtomicDecU32(&pThis->cWaking))
     222            if (!ASMAtomicDecU32(&pThis->cRefs))
    225223            {
    226224                mutex_exit(&pThis->Mtx);
     
    238236         */
    239237        rc = VERR_TIMEOUT;
    240         ASMAtomicDecU32(&pThis->cWaiters);
    241238    }
    242239    else
     
    246243         */
    247244        rc = VERR_INTERRUPTED;
    248         ASMAtomicDecU32(&pThis->cWaiters);
    249245    }
    250246
     
    266262    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    267263    AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE);
     264    Assert(pThis->cRefs >= 1);
    268265
    269266    /*
     
    280277    /*
    281278     * Not a recursion, make sure we don't sneak in when another thread
    282      * is being woken up (fSignaled).
     279     * is being woken up.
    283280     */
    284281    else if (   pThis->hOwnerThread == NIL_RTNATIVETHREAD
    285              && pThis->cWaiters == 0
    286              && pThis->fSignaled == false)
     282             && pThis->cWaiters == 0)
    287283    {
    288284        pThis->cRecursions  = 1;
     
    358354             */
    359355            if (pThis->cWaiters > 0)
    360             {
    361                 ASMAtomicXchgU8(&pThis->fSignaled, true);
    362                 ASMAtomicDecU32(&pThis->cWaiters);
    363                 ASMAtomicIncU32(&pThis->cWaking);
    364356                cv_signal(&pThis->Cnd);
    365             }
    366357        }
    367358        rc = 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