Changeset 2759
- Timestamp:
- Aug 13, 2006, 12:52:32 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/synergy/lib/arch/CArchMultithreadOS2.cpp
r2752 r2759 152 152 { 153 153 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); 155 155 assert(rc == NO_ERROR); 156 156 rc = DosCreateEventSem(NULL, &cond->m_events[CArchCondImpl::kBroadcast], 0, FALSE); … … 175 175 // is anybody waiting? 176 176 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]); 178 179 unlockMutex(cond->m_waitCountMutex); 179 180 // wake one thread if anybody is waiting181 if (hasWaiter) {182 DosPostEventSem(cond->m_events[CArchCondImpl::kSignal]);183 }184 180 } 185 181 … … 189 185 // is anybody waiting? 190 186 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]); 192 189 unlockMutex(cond->m_waitCountMutex); 193 194 // wake all threads if anybody is waiting195 if (hasWaiter) {196 DosPostEventSem(cond->m_events[CArchCondImpl::kBroadcast]);197 }198 190 } 199 191 … … 236 228 237 229 // wait for a signal or broadcast 230 // we're using a a manual reset semaphore, that complicates matters. 238 231 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 } 243 256 DosCloseMuxWaitSem(hmux); 244 257 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)) { 260 260 ULONG ulIgnore; 261 261 DosResetEventSem(cond->m_events[CArchCondImpl::kBroadcast], &ulIgnore); 262 262 } 263 unlockMutex(cond->m_waitCountMutex); 263 264 264 265 // reacquire the mutex
Note:
See TracChangeset
for help on using the changeset viewer.