VirtualBox

Changeset 6747 in vbox


Ignore:
Timestamp:
Feb 2, 2008 12:57:41 AM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
27829
Message:

pInt[Event|EventMulti|Mutex]Sem -> pThis

Location:
trunk/src/VBox/Runtime/r3/linux
Files:
3 edited

Legend:

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

    r6738 r6747  
    9090     * Allocate semaphore handle.
    9191     */
    92     struct RTSEMEVENTINTERNAL *pIntEventSem = (struct RTSEMEVENTINTERNAL *)RTMemAlloc(sizeof(struct RTSEMEVENTINTERNAL));
    93     if (pIntEventSem)
    94     {
    95         pIntEventSem->iMagic = RTSEMEVENT_MAGIC;
    96         pIntEventSem->cWaiters = 0;
    97         *pEventSem = pIntEventSem;
     92    struct RTSEMEVENTINTERNAL *pThis = (struct RTSEMEVENTINTERNAL *)RTMemAlloc(sizeof(struct RTSEMEVENTINTERNAL));
     93    if (pThis)
     94    {
     95        pThis->iMagic = RTSEMEVENT_MAGIC;
     96        pThis->cWaiters = 0;
     97        *pEventSem = pThis;
    9898        return VINF_SUCCESS;
    9999    }
     
    107107     * Validate input.
    108108     */
    109     struct RTSEMEVENTINTERNAL *pIntEventSem = EventSem;
    110     AssertReturn(VALID_PTR(pIntEventSem) && pIntEventSem->iMagic == RTSEMEVENT_MAGIC,
     109    struct RTSEMEVENTINTERNAL *pThis = EventSem;
     110    AssertReturn(VALID_PTR(pThis) && pThis->iMagic == RTSEMEVENT_MAGIC,
    111111                 VERR_INVALID_HANDLE);
    112112
     
    114114     * Invalidate the semaphore and wake up anyone waiting on it.
    115115     */
    116     ASMAtomicXchgSize(&pIntEventSem->iMagic, RTSEMEVENT_MAGIC + 1);
    117     if (ASMAtomicXchgS32(&pIntEventSem->cWaiters, INT32_MIN / 2) > 0)
    118     {
    119         sys_futex(&pIntEventSem->cWaiters, FUTEX_WAKE, INT_MAX, NULL, NULL, 0);
     116    ASMAtomicXchgSize(&pThis->iMagic, RTSEMEVENT_MAGIC + 1);
     117    if (ASMAtomicXchgS32(&pThis->cWaiters, INT32_MIN / 2) > 0)
     118    {
     119        sys_futex(&pThis->cWaiters, FUTEX_WAKE, INT_MAX, NULL, NULL, 0);
    120120        usleep(1000);
    121121    }
     
    124124     * Free the semaphore memory and be gone.
    125125     */
    126     RTMemFree(pIntEventSem);
     126    RTMemFree(pThis);
    127127    return VINF_SUCCESS;
    128128}
     
    134134     * Validate input.
    135135     */
    136     struct RTSEMEVENTINTERNAL *pIntEventSem = EventSem;
    137     AssertReturn(VALID_PTR(pIntEventSem) && pIntEventSem->iMagic == RTSEMEVENT_MAGIC,
     136    struct RTSEMEVENTINTERNAL *pThis = EventSem;
     137    AssertReturn(VALID_PTR(pThis) && pThis->iMagic == RTSEMEVENT_MAGIC,
    138138                 VERR_INVALID_HANDLE);
    139139    /*
     
    142142    for (unsigned i = 0;; i++)
    143143    {
    144         int32_t iCur = pIntEventSem->cWaiters;
     144        int32_t iCur = pThis->cWaiters;
    145145        if (iCur == 0)
    146146        {
    147             if (ASMAtomicCmpXchgS32(&pIntEventSem->cWaiters, -1, 0))
     147            if (ASMAtomicCmpXchgS32(&pThis->cWaiters, -1, 0))
    148148                break; /* nobody is waiting */
    149149        }
     
    153153        {
    154154            /* somebody is waiting, try wake up one of them. */
    155             long cWoken = sys_futex(&pIntEventSem->cWaiters, FUTEX_WAKE, 1, NULL, NULL, 0);
     155            long cWoken = sys_futex(&pThis->cWaiters, FUTEX_WAKE, 1, NULL, NULL, 0);
    156156            if (RT_LIKELY(cWoken == 1))
    157157            {
    158                 ASMAtomicDecS32(&pIntEventSem->cWaiters);
     158                ASMAtomicDecS32(&pThis->cWaiters);
    159159                break;
    160160            }
     
    180180                    pthread_yield();
    181181                else
    182                     AssertReleaseMsg(i < 4096, ("iCur=%#x pIntEventSem=%p\n", iCur, pIntEventSem));
     182                    AssertReleaseMsg(i < 4096, ("iCur=%#x pThis=%p\n", iCur, pThis));
    183183            }
    184184        }
     
    193193     * Validate input.
    194194     */
    195     struct RTSEMEVENTINTERNAL *pIntEventSem = EventSem;
    196     AssertReturn(VALID_PTR(pIntEventSem) && pIntEventSem->iMagic == RTSEMEVENT_MAGIC,
     195    struct RTSEMEVENTINTERNAL *pThis = EventSem;
     196    AssertReturn(VALID_PTR(pThis) && pThis->iMagic == RTSEMEVENT_MAGIC,
    197197                 VERR_INVALID_HANDLE);
    198198
     
    200200     * Quickly check whether it's signaled.
    201201     */
    202     if (ASMAtomicCmpXchgS32(&pIntEventSem->cWaiters, 0, -1))
     202    if (ASMAtomicCmpXchgS32(&pThis->cWaiters, 0, -1))
    203203        return VINF_SUCCESS;
    204204
     
    223223         * Announce that we're among the waiters.
    224224         */
    225         int32_t iNew = ASMAtomicIncS32(&pIntEventSem->cWaiters);
     225        int32_t iNew = ASMAtomicIncS32(&pThis->cWaiters);
    226226        if (iNew == 0)
    227227            return VINF_SUCCESS;
     
    231231             * Go to sleep.
    232232             */
    233             long rc = sys_futex(&pIntEventSem->cWaiters, FUTEX_WAIT, iNew, pTimeout, NULL, 0);
    234             if (RT_UNLIKELY(pIntEventSem->iMagic != RTSEMEVENT_MAGIC))
     233            long rc = sys_futex(&pThis->cWaiters, FUTEX_WAIT, iNew, pTimeout, NULL, 0);
     234            if (RT_UNLIKELY(pThis->iMagic != RTSEMEVENT_MAGIC))
    235235                return VERR_SEM_DESTROYED;
    236236
     
    240240
    241241            /* No, then the kernel woke us up or we failed going to sleep. Adjust the accounting. */
    242             iNew = ASMAtomicDecS32(&pIntEventSem->cWaiters);
     242            iNew = ASMAtomicDecS32(&pThis->cWaiters);
    243243            Assert(iNew >= 0);
    244244
     
    268268        {
    269269            /* this can't happen. */
    270             if (RT_UNLIKELY(pIntEventSem->iMagic != RTSEMEVENT_MAGIC))
     270            if (RT_UNLIKELY(pThis->iMagic != RTSEMEVENT_MAGIC))
    271271                return VERR_SEM_DESTROYED;
    272272            AssertReleaseMsgFailed(("iNew=%d\n", iNew));
  • trunk/src/VBox/Runtime/r3/linux/semeventmulti-linux.cpp

    r6738 r6747  
    8989     * Allocate semaphore handle.
    9090     */
    91     struct RTSEMEVENTMULTIINTERNAL *pIntEventMultiSem = (struct RTSEMEVENTMULTIINTERNAL *)RTMemAlloc(sizeof(struct RTSEMEVENTMULTIINTERNAL));
    92     if (pIntEventMultiSem)
    93     {
    94         pIntEventMultiSem->iMagic = RTSEMEVENTMULTI_MAGIC;
    95         pIntEventMultiSem->iState = 0;
    96         *pEventMultiSem = pIntEventMultiSem;
     91    struct RTSEMEVENTMULTIINTERNAL *pThis = (struct RTSEMEVENTMULTIINTERNAL *)RTMemAlloc(sizeof(struct RTSEMEVENTMULTIINTERNAL));
     92    if (pThis)
     93    {
     94        pThis->iMagic = RTSEMEVENTMULTI_MAGIC;
     95        pThis->iState = 0;
     96        *pEventMultiSem = pThis;
    9797        return VINF_SUCCESS;
    9898    }
     
    106106     * Validate input.
    107107     */
    108     struct RTSEMEVENTMULTIINTERNAL *pIntEventMultiSem = EventMultiSem;
    109     AssertReturn(VALID_PTR(pIntEventMultiSem) && pIntEventMultiSem->iMagic == RTSEMEVENTMULTI_MAGIC,
     108    struct RTSEMEVENTMULTIINTERNAL *pThis = EventMultiSem;
     109    AssertReturn(VALID_PTR(pThis) && pThis->iMagic == RTSEMEVENTMULTI_MAGIC,
    110110                 VERR_INVALID_HANDLE);
    111111
     
    113113     * Invalidate the semaphore and wake up anyone waiting on it.
    114114     */
    115     ASMAtomicXchgSize(&pIntEventMultiSem->iMagic, RTSEMEVENTMULTI_MAGIC + 1);
    116     if (ASMAtomicXchgS32(&pIntEventMultiSem->iState, -1) == 1)
    117     {
    118         sys_futex(&pIntEventMultiSem->iState, FUTEX_WAKE, INT_MAX, NULL, NULL, 0);
     115    ASMAtomicXchgSize(&pThis->iMagic, RTSEMEVENTMULTI_MAGIC + 1);
     116    if (ASMAtomicXchgS32(&pThis->iState, -1) == 1)
     117    {
     118        sys_futex(&pThis->iState, FUTEX_WAKE, INT_MAX, NULL, NULL, 0);
    119119        usleep(1000);
    120120    }
     
    123123     * Free the semaphore memory and be gone.
    124124     */
    125     RTMemFree(pIntEventMultiSem);
     125    RTMemFree(pThis);
    126126    return VINF_SUCCESS;
    127127}
     
    133133     * Validate input.
    134134     */
    135     struct RTSEMEVENTMULTIINTERNAL *pIntEventMultiSem = EventMultiSem;
    136     AssertReturn(VALID_PTR(pIntEventMultiSem) && pIntEventMultiSem->iMagic == RTSEMEVENTMULTI_MAGIC,
     135    struct RTSEMEVENTMULTIINTERNAL *pThis = EventMultiSem;
     136    AssertReturn(VALID_PTR(pThis) && pThis->iMagic == RTSEMEVENTMULTI_MAGIC,
    137137                 VERR_INVALID_HANDLE);
    138138    /*
    139139     * Signal it.
    140140     */
    141     int32_t iOld = ASMAtomicXchgS32(&pIntEventMultiSem->iState, -1);
     141    int32_t iOld = ASMAtomicXchgS32(&pThis->iState, -1);
    142142    if (iOld > 0)
    143143    {
    144144        /* wake up sleeping threads. */
    145         long cWoken = sys_futex(&pIntEventMultiSem->iState, FUTEX_WAKE, INT_MAX, NULL, NULL, 0);
     145        long cWoken = sys_futex(&pThis->iState, FUTEX_WAKE, INT_MAX, NULL, NULL, 0);
    146146        AssertMsg(cWoken >= 0, ("%ld\n", cWoken)); NOREF(cWoken);
    147147    }
     
    156156     * Validate input.
    157157     */
    158     struct RTSEMEVENTMULTIINTERNAL *pIntEventMultiSem = EventMultiSem;
    159     AssertReturn(VALID_PTR(pIntEventMultiSem) && pIntEventMultiSem->iMagic == RTSEMEVENTMULTI_MAGIC,
     158    struct RTSEMEVENTMULTIINTERNAL *pThis = EventMultiSem;
     159    AssertReturn(VALID_PTR(pThis) && pThis->iMagic == RTSEMEVENTMULTI_MAGIC,
    160160                 VERR_INVALID_HANDLE);
    161161#ifdef RT_STRICT
    162     int32_t i = pIntEventMultiSem->iState;
     162    int32_t i = pThis->iState;
    163163    Assert(i == 0 || i == -1 || i == 1);
    164164#endif
     
    167167     * Reset it.
    168168     */
    169     ASMAtomicCmpXchgS32(&pIntEventMultiSem->iState, 0, -1);
     169    ASMAtomicCmpXchgS32(&pThis->iState, 0, -1);
    170170    return VINF_SUCCESS;
    171171}
     
    177177     * Validate input.
    178178     */
    179     struct RTSEMEVENTMULTIINTERNAL *pIntEventMultiSem = EventMultiSem;
    180     AssertReturn(VALID_PTR(pIntEventMultiSem) && pIntEventMultiSem->iMagic == RTSEMEVENTMULTI_MAGIC,
     179    struct RTSEMEVENTMULTIINTERNAL *pThis = EventMultiSem;
     180    AssertReturn(VALID_PTR(pThis) && pThis->iMagic == RTSEMEVENTMULTI_MAGIC,
    181181                 VERR_INVALID_HANDLE);
    182182
     
    184184     * Quickly check whether it's signaled.
    185185     */
    186     int32_t iCur = pIntEventMultiSem->iState;
     186    int32_t iCur = pThis->iState;
    187187    Assert(iCur == 0 || iCur == -1 || iCur == 1);
    188188    if (iCur == -1)
     
    212212         * threads waiting on the semaphore to keep things simple.
    213213         */
    214         iCur = pIntEventMultiSem->iState;
     214        iCur = pThis->iState;
    215215        Assert(iCur == 0 || iCur == -1 || iCur == 1);
    216216        if (    iCur == 1
    217             ||  ASMAtomicCmpXchgS32(&pIntEventMultiSem->iState, 1, 0))
     217            ||  ASMAtomicCmpXchgS32(&pThis->iState, 1, 0))
    218218        {
    219             long rc = sys_futex(&pIntEventMultiSem->iState, FUTEX_WAIT, 1, pTimeout, NULL, 0);
    220             if (RT_UNLIKELY(pIntEventMultiSem->iMagic != RTSEMEVENTMULTI_MAGIC))
     219            long rc = sys_futex(&pThis->iState, FUTEX_WAIT, 1, pTimeout, NULL, 0);
     220            if (RT_UNLIKELY(pThis->iMagic != RTSEMEVENTMULTI_MAGIC))
    221221                return VERR_SEM_DESTROYED;
    222222            if (rc == 0)
  • trunk/src/VBox/Runtime/r3/linux/semmutex-linux.cpp

    r6746 r6747  
    9393     * Allocate semaphore handle.
    9494     */
    95     struct RTSEMMUTEXINTERNAL *pIntMutexSem = (struct RTSEMMUTEXINTERNAL *)RTMemAlloc(sizeof(struct RTSEMMUTEXINTERNAL));
    96     if (pIntMutexSem)
    97     {
    98         pIntMutexSem->iMagic   = RTSEMMUTEX_MAGIC;
    99         pIntMutexSem->iState   = 0;
    100         pIntMutexSem->Owner    = (pthread_t)~0;
    101         pIntMutexSem->cNesting = 0;
    102 
    103         *pMutexSem = pIntMutexSem;
     95    struct RTSEMMUTEXINTERNAL *pThis = (struct RTSEMMUTEXINTERNAL *)RTMemAlloc(sizeof(struct RTSEMMUTEXINTERNAL));
     96    if (pThis)
     97    {
     98        pThis->iMagic   = RTSEMMUTEX_MAGIC;
     99        pThis->iState   = 0;
     100        pThis->Owner    = (pthread_t)~0;
     101        pThis->cNesting = 0;
     102
     103        *pMutexSem = pThis;
    104104        return VINF_SUCCESS;
    105105    }
     
    116116    if (MutexSem == NIL_RTSEMMUTEX)
    117117        return VERR_INVALID_HANDLE;
    118     struct RTSEMMUTEXINTERNAL *pIntMutexSem = MutexSem;
    119     AssertPtrReturn(pIntMutexSem, VERR_INVALID_HANDLE);
    120     AssertMsgReturn(pIntMutexSem->iMagic == RTSEMMUTEX_MAGIC,
    121                     ("MutexSem=%p iMagic=%#x\n", pIntMutexSem, pIntMutexSem->iMagic),
     118    struct RTSEMMUTEXINTERNAL *pThis = MutexSem;
     119    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     120    AssertMsgReturn(pThis->iMagic == RTSEMMUTEX_MAGIC,
     121                    ("MutexSem=%p iMagic=%#x\n", pThis, pThis->iMagic),
    122122                    VERR_INVALID_HANDLE);
    123123
     
    125125     * Invalidate the semaphore and wake up anyone waiting on it.
    126126     */
    127     ASMAtomicXchgSize(&pIntMutexSem->iMagic, RTSEMMUTEX_MAGIC + 1);
    128     if (ASMAtomicXchgS32(&pIntMutexSem->iState, 0) > 0)
    129     {
    130         sys_futex(&pIntMutexSem->iState, FUTEX_WAKE, INT_MAX, NULL, NULL, 0);
     127    ASMAtomicXchgSize(&pThis->iMagic, RTSEMMUTEX_MAGIC + 1);
     128    if (ASMAtomicXchgS32(&pThis->iState, 0) > 0)
     129    {
     130        sys_futex(&pThis->iState, FUTEX_WAKE, INT_MAX, NULL, NULL, 0);
    131131        usleep(1000);
    132132    }
    133     pIntMutexSem->Owner    = (pthread_t)~0;
    134     pIntMutexSem->cNesting = 0;
     133    pThis->Owner    = (pthread_t)~0;
     134    pThis->cNesting = 0;
    135135
    136136    /*
    137137     * Free the semaphore memory and be gone.
    138138     */
    139     RTMemFree(pIntMutexSem);
     139    RTMemFree(pThis);
    140140    return VINF_SUCCESS;
    141141}
     
    147147     * Validate input.
    148148     */
    149     struct RTSEMMUTEXINTERNAL *pIntMutexSem = MutexSem;
    150     AssertPtrReturn(pIntMutexSem, VERR_INVALID_HANDLE);
    151     AssertMsgReturn(pIntMutexSem->iMagic == RTSEMMUTEX_MAGIC,
    152                     ("MutexSem=%p iMagic=%#x\n", pIntMutexSem, pIntMutexSem->iMagic),
     149    struct RTSEMMUTEXINTERNAL *pThis = MutexSem;
     150    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     151    AssertMsgReturn(pThis->iMagic == RTSEMMUTEX_MAGIC,
     152                    ("MutexSem=%p iMagic=%#x\n", pThis, pThis->iMagic),
    153153                    VERR_INVALID_HANDLE);
    154154
     
    157157     */
    158158    pthread_t Self = pthread_self();
    159     if (    pIntMutexSem->Owner == Self
    160         &&  pIntMutexSem->cNesting > 0)
    161     {
    162         pIntMutexSem->cNesting++;
     159    if (    pThis->Owner == Self
     160        &&  pThis->cNesting > 0)
     161    {
     162        pThis->cNesting++;
    163163        return VINF_SUCCESS;
    164164    }
     
    179179     * Lock the mutex.
    180180     */
    181     if (RT_UNLIKELY(!ASMAtomicCmpXchgS32(&pIntMutexSem->iState, 1, 0)))
     181    if (RT_UNLIKELY(!ASMAtomicCmpXchgS32(&pThis->iState, 1, 0)))
    182182    {
    183183        for (;;)
    184184        {
    185             int32_t iOld = ASMAtomicXchgS32(&pIntMutexSem->iState, 2);
     185            int32_t iOld = ASMAtomicXchgS32(&pThis->iState, 2);
    186186
    187187            /*
     
    194194             * Go to sleep.
    195195             */
    196             long rc = sys_futex(&pIntMutexSem->iState, FUTEX_WAIT, 2, pTimeout, NULL, 0);
    197             if (RT_UNLIKELY(pIntMutexSem->iMagic != RTSEMMUTEX_MAGIC))
     196            long rc = sys_futex(&pThis->iState, FUTEX_WAIT, 2, pTimeout, NULL, 0);
     197            if (RT_UNLIKELY(pThis->iMagic != RTSEMMUTEX_MAGIC))
    198198                return VERR_SEM_DESTROYED;
    199199
     
    236236     * Set the owner and nesting.
    237237     */
    238     pIntMutexSem->Owner = Self;
    239     ASMAtomicXchgU32(&pIntMutexSem->cNesting, 1);
     238    pThis->Owner = Self;
     239    ASMAtomicXchgU32(&pThis->cNesting, 1);
    240240    return VINF_SUCCESS;
    241241}
     
    261261     * Validate input.
    262262     */
    263     struct RTSEMMUTEXINTERNAL *pIntMutexSem = MutexSem;
    264     AssertPtrReturn(pIntMutexSem, VERR_INVALID_HANDLE);
    265     AssertMsgReturn(pIntMutexSem->iMagic == RTSEMMUTEX_MAGIC,
    266                     ("MutexSem=%p iMagic=%#x\n", pIntMutexSem, pIntMutexSem->iMagic),
     263    struct RTSEMMUTEXINTERNAL *pThis = MutexSem;
     264    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     265    AssertMsgReturn(pThis->iMagic == RTSEMMUTEX_MAGIC,
     266                    ("MutexSem=%p iMagic=%#x\n", pThis, pThis->iMagic),
    267267                    VERR_INVALID_HANDLE);
    268268
     
    271271     */
    272272    pthread_t Self = pthread_self();
    273     if (RT_UNLIKELY(    pIntMutexSem->Owner != Self
    274                     ||  pIntMutexSem->cNesting == 0))
     273    if (RT_UNLIKELY(    pThis->Owner != Self
     274                    ||  pThis->cNesting == 0))
    275275    {
    276276        AssertMsgFailed(("Not owner of mutex %p!! Self=%08x Owner=%08x cNesting=%d\n",
    277                          pIntMutexSem, Self, pIntMutexSem->Owner, pIntMutexSem->cNesting));
     277                         pThis, Self, pThis->Owner, pThis->cNesting));
    278278        return VERR_NOT_OWNER;
    279279    }
     
    282282     * If nested we'll just pop a nesting.
    283283     */
    284     if (pIntMutexSem->cNesting > 1)
    285     {
    286         pIntMutexSem->cNesting--;
     284    if (pThis->cNesting > 1)
     285    {
     286        pThis->cNesting--;
    287287        return VINF_SUCCESS;
    288288    }
     
    291291     * Clear the state. (cNesting == 1)
    292292     */
    293     pIntMutexSem->Owner = (pthread_t)~0;
    294     ASMAtomicXchgU32(&pIntMutexSem->cNesting, 0);
     293    pThis->Owner = (pthread_t)~0;
     294    ASMAtomicXchgU32(&pThis->cNesting, 0);
    295295
    296296    /*
    297297     * Release the mutex.
    298298     */
    299     int32_t iNew = ASMAtomicDecS32(&pIntMutexSem->iState);
     299    int32_t iNew = ASMAtomicDecS32(&pThis->iState);
    300300    if (iNew != 0)
    301301    {
    302302        /* somebody is waiting, try wake up one of them. */
    303         ASMAtomicXchgS32(&pIntMutexSem->iState, 0);
    304         (void)sys_futex(&pIntMutexSem->iState, FUTEX_WAKE, 1, NULL, NULL, 0);
     303        ASMAtomicXchgS32(&pThis->iState, 0);
     304        (void)sys_futex(&pThis->iState, FUTEX_WAKE, 1, NULL, NULL, 0);
    305305    }
    306306    return VINF_SUCCESS;
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