From 6d31b06c437ed530c555b66ad191cda197763ca2 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Mon, 2 Jun 2008 22:14:59 +0000 Subject: [PATCH] Fix removeAll in BoxStack --- boxstack.cc | 63 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/boxstack.cc b/boxstack.cc index 896b42c..0778ddb 100644 --- a/boxstack.cc +++ b/boxstack.cc @@ -425,24 +425,59 @@ void BoxStack::removeAll() // 1.. Don't delete wallpaper. No point. // Need locking on this one?? + + // This is pretty silly now that preDelete needs mutex unlocked + + Boxx* toDel = NULL; + + while(numBoxes > 1) + { + #ifndef WIN32 + pthread_mutex_lock(&boxLock); + #else + WaitForSingleObject(boxLock, INFINITE); + #endif -#ifndef WIN32 - pthread_mutex_lock(&boxLock); -#else - WaitForSingleObject(boxLock, INFINITE); -#endif + if (numBoxes == 1) + { + #ifndef WIN32 + pthread_mutex_unlock(&boxLock); + #else + ReleaseMutex(boxLock); + #endif + break; + } + + toDel = boxes[numBoxes - 1]; + + #ifndef WIN32 + pthread_mutex_unlock(&boxLock); + #else + ReleaseMutex(boxLock); + #endif + + toDel->preDelete(); + + #ifndef WIN32 + pthread_mutex_lock(&boxLock); + #else + WaitForSingleObject(boxLock, INFINITE); + #endif + + // If boxes[numBoxes - 1] isn't toDel then there's a problem + if (boxes[numBoxes - 1] == toDel) + { + delete toDel; + --numBoxes; + } + #ifndef WIN32 + pthread_mutex_unlock(&boxLock); + #else + ReleaseMutex(boxLock); + #endif - for (; numBoxes > 1; --numBoxes) - { - delete boxes[numBoxes-1]; } - -#ifndef WIN32 - pthread_mutex_unlock(&boxLock); -#else - ReleaseMutex(boxLock); -#endif } -- 2.39.5