* Fixed a potential race condition: when wait_for_notifications() is called

from the block notifier, the cache could be deleted before we have the chance
  to lock it. We now lock the sCachesLock, and see if this cache is still valid.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28512 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2008-11-05 11:16:04 +00:00
parent 11ab7172d9
commit ddd20af422

View File

@ -1746,6 +1746,22 @@ notify_sync(int32 transactionID, int32 event, void* _cache)
}
/*! Must be called with the sCachesLock held. */
static bool
is_valid_cache(block_cache* cache)
{
ASSERT_LOCKED_MUTEX(&sCachesLock);
DoublyLinkedList<block_cache>::Iterator iterator = sCaches.GetIterator();
while (iterator.HasNext()) {
if (cache == iterator.Next())
return true;
}
return false;
}
/*! Waits until all pending notifications are carried out.
Safe to be called from the block writer/notifier thread.
You must not hold the \a cache lock when calling this function.
@ -1756,7 +1772,9 @@ wait_for_notifications(block_cache* cache)
if (find_thread(NULL) == sNotifierWriterThread) {
// We're the notifier thread, don't wait, but flush all pending
// notifications directly.
flush_pending_notifications(cache);
MutexLocker _(sCachesLock);
if (is_valid_cache(cache))
flush_pending_notifications(cache);
return;
}