Changeset 2759


Ignore:
Timestamp:
Aug 13, 2006, 12:52:32 AM (19 years ago)
Author:
bird
Message:

Can't use DCE_POSTONE or DCE_AUTORESET with MUX. too bad.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/synergy/lib/arch/CArchMultithreadOS2.cpp

    r2752 r2759  
    152152{
    153153        CArchCondImpl* cond                       = new CArchCondImpl;
    154         APIRET rc = DosCreateEventSem(NULL, &cond->m_events[CArchCondImpl::kSignal], DCE_AUTORESET, FALSE);
     154        APIRET rc = DosCreateEventSem(NULL, &cond->m_events[CArchCondImpl::kSignal], /*DCE_AUTORESET*/0, FALSE);
    155155        assert(rc == NO_ERROR);
    156156        rc = DosCreateEventSem(NULL, &cond->m_events[CArchCondImpl::kBroadcast], 0, FALSE);
     
    175175        // is anybody waiting?
    176176        lockMutex(cond->m_waitCountMutex);
    177         const bool hasWaiter = (cond->m_waitCount > 0);
     177        if (cond->m_waitCount > 0)
     178                DosPostEventSem(cond->m_events[CArchCondImpl::kSignal]);
    178179        unlockMutex(cond->m_waitCountMutex);
    179 
    180         // wake one thread if anybody is waiting
    181         if (hasWaiter) {
    182                 DosPostEventSem(cond->m_events[CArchCondImpl::kSignal]);
    183         }
    184180}
    185181
     
    189185        // is anybody waiting?
    190186        lockMutex(cond->m_waitCountMutex);
    191         const bool hasWaiter = (cond->m_waitCount > 0);
     187        if (cond->m_waitCount > 0)
     188                DosPostEventSem(cond->m_events[CArchCondImpl::kBroadcast]);
    192189        unlockMutex(cond->m_waitCountMutex);
    193 
    194         // wake all threads if anybody is waiting
    195         if (hasWaiter) {
    196                 DosPostEventSem(cond->m_events[CArchCondImpl::kBroadcast]);
    197         }
    198190}
    199191
     
    236228
    237229        // wait for a signal or broadcast
     230    // we're using a a manual reset semaphore, that complicates matters.
    238231        ULONG iSem = ~0UL;
    239         rc = DosWaitMuxWaitSem(hmux, os2Timeout, &iSem);
    240         if (rc != NO_ERROR) {
    241                 iSem = ~0UL;
    242         }
     232    for (;;) {
     233            rc = DosWaitMuxWaitSem(hmux, os2Timeout, &iSem);
     234        lockMutex(cond->m_waitCountMutex);
     235        if (rc != NO_ERROR) {
     236            iSem = ~0UL;
     237            break;
     238        }
     239
     240        // cancel takes priority
     241        if (   iSem != 2
     242            && DosWaitEventSem((HEV)handles[2].hsemCur, 0) == NO_ERROR)
     243            iSem = 2;
     244       
     245        // see if we got here first.
     246        if (iSem != 0)
     247            break;
     248        ULONG cPosts = 0;
     249        rc = DosResetEventSem((HEV)handles[0].hsemCur, &cPosts);
     250        if (rc == NO_ERROR && cPosts > 0) {
     251            while (--cPosts > 0)
     252                DosPostEventSem((HEV)handles[0].hsemCur);
     253            break;
     254        }
     255    }
    243256        DosCloseMuxWaitSem(hmux);
    244257
    245         // cancel takes priority
    246         if (   rc == NO_ERROR
    247                 && iSem != 2
    248                 && DosWaitEventSem((HEV)handles[2].hsemCur, 0) == NO_ERROR) {
    249                 iSem = 2;
    250         }
    251 
    252         // update the waiter count and check if we're the last waiter
    253         lockMutex(cond->m_waitCountMutex);
    254         --cond->m_waitCount;
    255         const bool last = (iSem == 1 && cond->m_waitCount == 0);
    256         unlockMutex(cond->m_waitCountMutex);
    257 
    258         // reset the broadcast event if we're the last waiter
    259         if (last) {
     258        // update the waiter count and reset the broadcast event if we're the last waiter
     259        if ((iSem == 1 && cond->m_waitCount == 0)) {
    260260                ULONG ulIgnore;
    261261                DosResetEventSem(cond->m_events[CArchCondImpl::kBroadcast], &ulIgnore);
    262262        }
     263        unlockMutex(cond->m_waitCountMutex);
    263264
    264265        // reacquire the mutex
Note: See TracChangeset for help on using the changeset viewer.