Fixed failure to unlock mutex in CXWindowsScreen::mainLoop()

when returning due to a quit event.
This commit is contained in:
crs 2003-09-03 21:49:57 +00:00
parent 8395f69899
commit 33e359a384
1 changed files with 18 additions and 7 deletions

View File

@ -370,9 +370,14 @@ void
CXWindowsScreen::mainLoop() CXWindowsScreen::mainLoop()
{ {
// wait for an event in a cancellable way and don't lock the // wait for an event in a cancellable way and don't lock the
// display while we're waiting. // display while we're waiting. we use CLock to ensure that
// we unlock on exit but we directly unlock/lock the mutex
// for certain sections when we mustn't hold the lock. it's
// very important that these sections not return (even by
// exception or cancellation) without first reestablishing
// the lock.
XEvent event; XEvent event;
m_mutex.lock(); CLock lock(&m_mutex);
for (;;) { for (;;) {
@ -418,8 +423,8 @@ CXWindowsScreen::mainLoop()
// wait for message from X server or for timeout. also check // wait for message from X server or for timeout. also check
// if the thread has been cancelled. poll() should return -1 // if the thread has been cancelled. poll() should return -1
// with EINTR when the thread is cancelled. // with EINTR when the thread is cancelled.
m_mutex.unlock();
CThread::testCancel(); CThread::testCancel();
m_mutex.unlock();
#if HAVE_POLL #if HAVE_POLL
poll(pfds, 1, timeout); poll(pfds, 1, timeout);
#else #else
@ -429,8 +434,8 @@ CXWindowsScreen::mainLoop()
SELECT_TYPE_ARG234 NULL, SELECT_TYPE_ARG234 NULL,
SELECT_TYPE_ARG5 timeoutPtr); SELECT_TYPE_ARG5 timeoutPtr);
#endif #endif
CThread::testCancel();
m_mutex.lock(); m_mutex.lock();
CThread::testCancel();
// process timers // process timers
processTimers(); processTimers();
@ -445,10 +450,16 @@ CXWindowsScreen::mainLoop()
} }
// wait // wait
try {
m_mutex.unlock(); m_mutex.unlock();
CThread::sleep(0.01); CThread::sleep(0.01);
m_mutex.lock(); m_mutex.lock();
} }
catch (...) {
m_mutex.lock();
throw;
}
}
#endif // !UNIX_LIKE #endif // !UNIX_LIKE