{
if (!initted) return 0;
- toDelete->preDelete();
-
-#ifndef WIN32
+ #ifndef WIN32
pthread_mutex_lock(&boxLock);
-#else
+ #else
WaitForSingleObject(boxLock, INFINITE);
-#endif
+ #endif
Log::getInstance()->log("BoxStack", Log::DEBUG, "Locked for remove");
if (numBoxes == 0)
- { // FIXME
- #ifndef WIN32
- pthread_mutex_unlock(&boxLock);
- #else
- ReleaseMutex(boxLock);
- #endif
- Log::getInstance()->log("BoxStack", Log::DEBUG, "Unlocked for remove");
- return 0;
+ {
+ #ifndef WIN32
+ pthread_mutex_unlock(&boxLock);
+ #else
+ ReleaseMutex(boxLock);
+ #endif
+ Log::getInstance()->log("BoxStack", Log::ERR, "Unlocked for remove numBoxes == 0");
+ return 0;
}
// Log::getInstance()->log("BoxStack", Log::DEBUG, "entering remove, numBoxes=%i", numBoxes);
if (i == -1)
{
// not a Box we have!
- { // FIXME
- #ifndef WIN32
- pthread_mutex_unlock(&boxLock);
- #else
- ReleaseMutex(boxLock);
- #endif
- Log::getInstance()->log("BoxStack", Log::DEBUG, "Unlocked for remove");
- return 0;
- }
+ // FIXME
+ #ifndef WIN32
+ pthread_mutex_unlock(&boxLock);
+ #else
+ ReleaseMutex(boxLock);
+ #endif
+ Log::getInstance()->log("BoxStack", Log::ERR, "Unlocked for remove - no boxx deleted");
+ return 0;
}
}
+#ifndef WIN32
+ pthread_mutex_unlock(&boxLock);
+#else
+ ReleaseMutex(boxLock);
+#endif
+
+toDelete->preDelete();
+
+#ifndef WIN32
+ pthread_mutex_lock(&boxLock);
+#else
+ WaitForSingleObject(boxLock, INFINITE);
+#endif
+
// Log::getInstance()->log("BoxStack", Log::DEBUG, "Starting deleteBox");
deleteBox(i);
// Log::getInstance()->log("BoxStack", Log::DEBUG, "Done deleteBox");
--numBoxes;
for(int j = i; j < numBoxes; j++) boxes[j] = boxes[j+1];
- // Delete the box
- delete toDelete;
-
// If there is only the wallpaper left signal command
if (numBoxes == 1)
{
ReleaseMutex(boxLock);
#endif
Log::getInstance()->log("BoxStack", Log::DEBUG, "Unlocked for remove");
+
+ // Delete the box
+ //AVO: do this delete outside the lock to allow for recursive calls within the destructor
+ // as this box is not in the stack any more, there is no chance for a second delete
+ Log::getInstance()->log("BoxStack", Log::DEBUG, "remove: going to delete boxx %p, num %d", toDelete, numBoxes);
+ delete toDelete;
return 1;
}
// If boxes[numBoxes - 1] isn't toDel then there's a problem
if (boxes[numBoxes - 1] == toDel)
{
- delete toDel;
--numBoxes;
}
+ else
+ {
+ Log::getInstance()->log("BoxStack", Log::ERR, "Can this actually happen? Why?");
+ toDel = NULL;
+ }
#ifndef WIN32
pthread_mutex_unlock(&boxLock);
ReleaseMutex(boxLock);
#endif
+ //AVO: do the delete outside the lock to allow for recursive deletes
+ Log::getInstance()->log("BoxStack", Log::DEBUG, "going to delete boxx %p, num=%d", toDel, numBoxes);
+ if (toDel) delete toDel;
}
-
}
int BoxStack::handleCommand(int command)