* VMCache::Unlock(): Renamed local variable consumerLocked to avoid shadowing

the parameter (CID 5329).
* _MergeWithOnlyConsumer(): Removed the somewhat weird consumerLocked
  parameter. The caller can unlock itself, if desired. Improves Unlock()
  readability.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40084 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2011-01-03 00:44:40 +00:00
parent b734adba63
commit a0d93d1416
2 changed files with 12 additions and 14 deletions
+1 -1
View File
@@ -192,7 +192,7 @@ private:
inline bool _IsMergeable() const; inline bool _IsMergeable() const;
void _MergeWithOnlyConsumer(bool consumerLocked); void _MergeWithOnlyConsumer();
void _RemoveConsumer(VMCache* consumer); void _RemoveConsumer(VMCache* consumer);
private: private:
+11 -13
View File
@@ -682,27 +682,28 @@ VMCache::Unlock(bool consumerLocked)
while (fRefCount == 1 && _IsMergeable()) { while (fRefCount == 1 && _IsMergeable()) {
VMCache* consumer = (VMCache*)list_get_first_item(&consumers); VMCache* consumer = (VMCache*)list_get_first_item(&consumers);
if (consumerLocked) { if (consumerLocked) {
_MergeWithOnlyConsumer(true); _MergeWithOnlyConsumer();
} else if (consumer->TryLock()) { } else if (consumer->TryLock()) {
_MergeWithOnlyConsumer(false); _MergeWithOnlyConsumer();
consumer->Unlock();
} else { } else {
// Someone else has locked the consumer ATM. Unlock this cache and // Someone else has locked the consumer ATM. Unlock this cache and
// wait for the consumer lock. Increment the cache's ref count // wait for the consumer lock. Increment the cache's ref count
// temporarily, so that no one else will try what we are doing or // temporarily, so that no one else will try what we are doing or
// delete the cache. // delete the cache.
fRefCount++; fRefCount++;
bool consumerLocked = consumer->SwitchLock(&fLock); bool consumerLockedTemp = consumer->SwitchLock(&fLock);
Lock(); Lock();
fRefCount--; fRefCount--;
if (consumerLocked) { if (consumerLockedTemp) {
if (fRefCount == 1 && _IsMergeable() if (fRefCount == 1 && _IsMergeable()
&& consumer == list_get_first_item(&consumers)) { && consumer == list_get_first_item(&consumers)) {
_MergeWithOnlyConsumer(false); // nothing has changed in the meantime -- merge
} else { _MergeWithOnlyConsumer();
// something changed, get rid of the consumer lock
consumer->Unlock();
} }
consumer->Unlock();
} }
} }
} }
@@ -1359,10 +1360,10 @@ VMCache::_NotifyPageEvents(vm_page* page, uint32 events)
/*! Merges the given cache with its only consumer. /*! Merges the given cache with its only consumer.
The caller must hold both the cache's and the consumer's lock. The method The caller must hold both the cache's and the consumer's lock. The method
will unlock the consumer lock. does release neither lock.
*/ */
void void
VMCache::_MergeWithOnlyConsumer(bool consumerLocked) VMCache::_MergeWithOnlyConsumer()
{ {
VMCache* consumer = (VMCache*)list_remove_head_item(&consumers); VMCache* consumer = (VMCache*)list_remove_head_item(&consumers);
@@ -1392,9 +1393,6 @@ VMCache::_MergeWithOnlyConsumer(bool consumerLocked)
// Release the reference the cache's consumer owned. The consumer takes // Release the reference the cache's consumer owned. The consumer takes
// over the cache's ref to its source (if any) instead. // over the cache's ref to its source (if any) instead.
ReleaseRefLocked(); ReleaseRefLocked();
if (!consumerLocked)
consumer->Unlock();
} }