BIND 10 trac643, updated. dd4e05070a8868a7f42eab9096f0b4d506bbc027 Add clear() function to lru list, which is used to clear all the elements of list.

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Mar 11 11:47:55 UTC 2011


The branch, trac643 has been updated
       via  dd4e05070a8868a7f42eab9096f0b4d506bbc027 (commit)
      from  acbd9518519498fcf9d476b5417bcbbb2b9141be (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit dd4e05070a8868a7f42eab9096f0b4d506bbc027
Author: zhanglikun <zhanglikun at cnnic.cn>
Date:   Fri Mar 11 19:45:55 2011 +0800

    Add clear() function to lru list, which is used to clear all the elements of list.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/cache/message_cache.cc          |    5 +++++
 src/lib/cache/message_cache.h           |    2 +-
 src/lib/cache/rrset_cache.h             |    6 ++++--
 src/lib/nsas/lru_list.h                 |   26 ++++++++++++++++++++++++++
 src/lib/nsas/tests/lru_list_unittest.cc |   29 +++++++++++++++++++++++++++++
 5 files changed, 65 insertions(+), 3 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/cache/message_cache.cc b/src/lib/cache/message_cache.cc
index 53c73c1..e832f52 100644
--- a/src/lib/cache/message_cache.cc
+++ b/src/lib/cache/message_cache.cc
@@ -37,6 +37,11 @@ MessageCache::MessageCache(boost::shared_ptr<RRsetCache> rrset_cache,
 {
 }
 
+MessageCache::~MessageCache() {
+    // Destroy all the message entries in the cache.
+    message_lru_.clear();
+}
+
 bool
 MessageCache::lookup(const isc::dns::Name& qname,
                      const isc::dns::RRType& qtype,
diff --git a/src/lib/cache/message_cache.h b/src/lib/cache/message_cache.h
index 65c7381..50b2b8a 100644
--- a/src/lib/cache/message_cache.h
+++ b/src/lib/cache/message_cache.h
@@ -42,7 +42,7 @@ public:
                  uint32_t cache_size, uint16_t message_class);
 
     /// \brief Destructor function
-    virtual ~MessageCache() {}
+    virtual ~MessageCache();
 
     /// \brief Look up message in cache.
     /// \param message generated response message if the message entry
diff --git a/src/lib/cache/rrset_cache.h b/src/lib/cache/rrset_cache.h
index 5bf2730..104c2a5 100644
--- a/src/lib/cache/rrset_cache.h
+++ b/src/lib/cache/rrset_cache.h
@@ -40,12 +40,14 @@ private:
     RRsetCache(const RRsetCache&);
     RRsetCache& operator=(const RRsetCache&);
 public:
-    /// \brief Constructor
+    /// \brief Constructor and Destructor
     ///
     /// \param cache_size the size of rrset cache.
     /// \param rrset_class the class of rrset cache.
     RRsetCache(uint32_t cache_size, uint16_t rrset_class);
-    virtual ~RRsetCache() {}
+    virtual ~RRsetCache() {
+        rrset_lru_.clear(); // Clear the rrset entries in the list.
+    }
     //@}
 
     /// \brief Look up rrset in cache.
diff --git a/src/lib/nsas/lru_list.h b/src/lib/nsas/lru_list.h
index 993eb89..88654cb 100644
--- a/src/lib/nsas/lru_list.h
+++ b/src/lib/nsas/lru_list.h
@@ -109,6 +109,13 @@ public:
     /// \param element Reference to the element to touch.
     virtual void touch(boost::shared_ptr<T>& element);
 
+    /// \brief Drop All the Elements in the List .
+    ///
+    /// All the elements will be dropped from the list container, and their
+    /// drop handler(if there is one) will be called, left the size of list
+    /// to 0.
+    virtual void clear();
+
     /// \brief Return Size of the List
     ///
     /// An independent count is kept of the list size, as list.size() may take
@@ -228,6 +235,25 @@ void LruList<T>::touch(boost::shared_ptr<T>& element) {
     }
 }
 
+// Clear the list-  left the size of list to 0
+template <typename T>
+void LruList<T>::clear() {
+    // Protect list against concurrent access
+    isc::locks::scoped_lock<isc::locks::mutex> lock(mutex_);
+
+    // ... and update the count while we have the mutex.
+    count_ = 0;
+    typename std::list<boost::shared_ptr<T> >::iterator iter;
+    if (dropped_) {
+        for (iter = lru_.begin(); iter != lru_.end(); ++iter) {
+            // Call the drop handler.
+            (*dropped_)(iter->get());
+        }
+    }
+
+    lru_.clear();
+}
+
 }   // namespace nsas
 }   // namespace isc
 
diff --git a/src/lib/nsas/tests/lru_list_unittest.cc b/src/lib/nsas/tests/lru_list_unittest.cc
index 0161f2b..e286826 100644
--- a/src/lib/nsas/tests/lru_list_unittest.cc
+++ b/src/lib/nsas/tests/lru_list_unittest.cc
@@ -251,6 +251,35 @@ TEST_F(LruListTest, Dropped) {
     EXPECT_EQ(0, (entry3_->getClass().getCode() & 0x8000));
 }
 
+// Clear functor tests: tests whether all the elements in
+// the list are dropped properly and the size of list is
+// set to 0.
+TEST_F(LruListTest, Clear) {
+    // Create an object with an expiration handler.
+    LruList<TestEntry> lru(3, new Dropped());
+
+    // Fill the list
+    lru.add(entry1_);
+    lru.add(entry2_);
+    lru.add(entry3_);
+
+    EXPECT_EQ(RRClass::IN(), entry1_->getClass());
+    EXPECT_EQ(RRClass::CH(), entry2_->getClass());
+    EXPECT_EQ(RRClass::HS(), entry3_->getClass());
+
+    EXPECT_EQ(0, (entry1_->getClass().getCode() & 0x8000));
+    EXPECT_EQ(0, (entry2_->getClass().getCode() & 0x8000));
+    EXPECT_EQ(0, (entry3_->getClass().getCode() & 0x8000));
+
+    // Clear the lru list, and check the drop handler run
+    lru.clear();
+    EXPECT_NE(0, (entry1_->getClass().getCode() & 0x8000));
+    EXPECT_NE(0, (entry2_->getClass().getCode() & 0x8000));
+    EXPECT_NE(0, (entry3_->getClass().getCode() & 0x8000));
+ 
+    EXPECT_EQ(0, lru.size());
+}
+
 // Miscellaneous tests - pathological conditions
 TEST_F(LruListTest, Miscellaneous) {
 




More information about the bind10-changes mailing list