[haiku-commits] r40084 - in haiku/trunk: headers/private/kernel/vm src/system/kernel/vm

  • From: ingo_weinhold@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 3 Jan 2011 01:44:40 +0100 (CET)

Author: bonefish
Date: 2011-01-03 01:44:40 +0100 (Mon, 03 Jan 2011)
New Revision: 40084
Changeset: http://dev.haiku-os.org/changeset/40084

Modified:
   haiku/trunk/headers/private/kernel/vm/VMCache.h
   haiku/trunk/src/system/kernel/vm/VMCache.cpp
Log:
* 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.


Modified: haiku/trunk/headers/private/kernel/vm/VMCache.h
===================================================================
--- haiku/trunk/headers/private/kernel/vm/VMCache.h     2011-01-03 00:09:27 UTC 
(rev 40083)
+++ haiku/trunk/headers/private/kernel/vm/VMCache.h     2011-01-03 00:44:40 UTC 
(rev 40084)
@@ -192,7 +192,7 @@
 
        inline  bool                            _IsMergeable() const;
 
-                       void                            
_MergeWithOnlyConsumer(bool consumerLocked);
+                       void                            
_MergeWithOnlyConsumer();
                        void                            
_RemoveConsumer(VMCache* consumer);
 
 private:

Modified: haiku/trunk/src/system/kernel/vm/VMCache.cpp
===================================================================
--- haiku/trunk/src/system/kernel/vm/VMCache.cpp        2011-01-03 00:09:27 UTC 
(rev 40083)
+++ haiku/trunk/src/system/kernel/vm/VMCache.cpp        2011-01-03 00:44:40 UTC 
(rev 40084)
@@ -682,27 +682,28 @@
        while (fRefCount == 1 && _IsMergeable()) {
                VMCache* consumer = (VMCache*)list_get_first_item(&consumers);
                if (consumerLocked) {
-                       _MergeWithOnlyConsumer(true);
+                       _MergeWithOnlyConsumer();
                } else if (consumer->TryLock()) {
-                       _MergeWithOnlyConsumer(false);
+                       _MergeWithOnlyConsumer();
+                       consumer->Unlock();
                } else {
                        // Someone else has locked the consumer ATM. Unlock 
this cache and
                        // wait for the consumer lock. Increment the cache's 
ref count
                        // temporarily, so that no one else will try what we 
are doing or
                        // delete the cache.
                        fRefCount++;
-                       bool consumerLocked = consumer->SwitchLock(&fLock);
+                       bool consumerLockedTemp = consumer->SwitchLock(&fLock);
                        Lock();
                        fRefCount--;
 
-                       if (consumerLocked) {
+                       if (consumerLockedTemp) {
                                if (fRefCount == 1 && _IsMergeable()
                                                && consumer == 
list_get_first_item(&consumers)) {
-                                       _MergeWithOnlyConsumer(false);
-                               } else {
-                                       // something changed, get rid of the 
consumer lock
-                                       consumer->Unlock();
+                                       // nothing has changed in the meantime 
-- merge
+                                       _MergeWithOnlyConsumer();
                                }
+
+                               consumer->Unlock();
                        }
                }
        }
@@ -1359,10 +1360,10 @@
 
 /*!    Merges the given cache with its only consumer.
        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
-VMCache::_MergeWithOnlyConsumer(bool consumerLocked)
+VMCache::_MergeWithOnlyConsumer()
 {
        VMCache* consumer = (VMCache*)list_remove_head_item(&consumers);
 
@@ -1392,9 +1393,6 @@
        // Release the reference the cache's consumer owned. The consumer takes
        // over the cache's ref to its source (if any) instead.
        ReleaseRefLocked();
-
-       if (!consumerLocked)
-               consumer->Unlock();
 }
 
 


Other related posts:

  • » [haiku-commits] r40084 - in haiku/trunk: headers/private/kernel/vm src/system/kernel/vm - ingo_weinhold