BIND 10 trac2850_2, updated. de6e68cf258f9349795368f5bf773f8911a79acf [2850] Fix MemorySegmentMapped::allMemoryDeallocated() and make it non-const

BIND 10 source code commits bind10-changes at lists.isc.org
Mon May 13 08:37:49 UTC 2013


The branch, trac2850_2 has been updated
       via  de6e68cf258f9349795368f5bf773f8911a79acf (commit)
      from  3c98ade56f07c44740f1bde2e37f8fdc9842bd18 (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 de6e68cf258f9349795368f5bf773f8911a79acf
Author: Mukund Sivaraman <muks at isc.org>
Date:   Mon May 13 14:06:58 2013 +0530

    [2850] Fix MemorySegmentMapped::allMemoryDeallocated() and make it non-const

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

Summary of changes:
 src/lib/util/memory_segment.h                      |    2 +-
 src/lib/util/memory_segment_local.cc               |    2 +-
 src/lib/util/memory_segment_local.h                |    2 +-
 src/lib/util/memory_segment_mapped.cc              |   29 +++++++++++++++-----
 src/lib/util/memory_segment_mapped.h               |    2 +-
 .../util/tests/memory_segment_mapped_unittest.cc   |    9 +++++-
 6 files changed, 34 insertions(+), 12 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/util/memory_segment.h b/src/lib/util/memory_segment.h
index a93b5ad..a613fd9 100644
--- a/src/lib/util/memory_segment.h
+++ b/src/lib/util/memory_segment.h
@@ -157,7 +157,7 @@ public:
     /// \return Returns <code>true</code> if all allocated memory (including
     /// names associated by memory addresses by \c setNamedAddress()) was
     /// deallocated, <code>false</code> otherwise.
-    virtual bool allMemoryDeallocated() const = 0;
+    virtual bool allMemoryDeallocated() = 0;
 
     /// \brief Associate specified address in the segment with a given name.
     ///
diff --git a/src/lib/util/memory_segment_local.cc b/src/lib/util/memory_segment_local.cc
index b81fe5e..ec6ee66 100644
--- a/src/lib/util/memory_segment_local.cc
+++ b/src/lib/util/memory_segment_local.cc
@@ -47,7 +47,7 @@ MemorySegmentLocal::deallocate(void* ptr, size_t size) {
 }
 
 bool
-MemorySegmentLocal::allMemoryDeallocated() const {
+MemorySegmentLocal::allMemoryDeallocated() {
     return (allocated_size_ == 0 && named_addrs_.empty());
 }
 
diff --git a/src/lib/util/memory_segment_local.h b/src/lib/util/memory_segment_local.h
index de7249e..d3e556a 100644
--- a/src/lib/util/memory_segment_local.h
+++ b/src/lib/util/memory_segment_local.h
@@ -64,7 +64,7 @@ public:
     ///
     /// \return Returns <code>true</code> if all allocated memory was
     /// deallocated, <code>false</code> otherwise.
-    virtual bool allMemoryDeallocated() const;
+    virtual bool allMemoryDeallocated();
 
     /// \brief Local segment version of getNamedAddress.
     ///
diff --git a/src/lib/util/memory_segment_mapped.cc b/src/lib/util/memory_segment_mapped.cc
index 2d0992d..88bdaed 100644
--- a/src/lib/util/memory_segment_mapped.cc
+++ b/src/lib/util/memory_segment_mapped.cc
@@ -139,11 +139,22 @@ struct MemorySegmentMapped::Impl {
 
     void reserveMemory() {
         if (!read_only_) {
-            // Reserve a named address for use during setNamedAddress().
-            const offset_ptr<void>* reserved_storage =
-                base_sgmt_->find_or_construct<offset_ptr<void> >(
-                    RESERVED_NAMED_ADDRESS_STORAGE_NAME, std::nothrow)();
-            assert(reserved_storage);
+            // Reserve a named address for use during
+            // setNamedAddress(). Though this will almost always succeed
+            // during construction, it may fail later during a call from
+            // allMemoryDeallocated() when the segment has been in use
+            // for a while.
+            while (true) {
+                const offset_ptr<void>* reserved_storage =
+                    base_sgmt_->find_or_construct<offset_ptr<void> >(
+                        RESERVED_NAMED_ADDRESS_STORAGE_NAME, std::nothrow)();
+
+                if (reserved_storage) {
+                    break;
+                }
+
+                growSegment();
+            }
         }
     }
 
@@ -306,8 +317,12 @@ MemorySegmentMapped::deallocate(void* ptr, size_t) {
 }
 
 bool
-MemorySegmentMapped::allMemoryDeallocated() const {
-    return (impl_->base_sgmt_->all_memory_deallocated());
+MemorySegmentMapped::allMemoryDeallocated() {
+    impl_->freeReservedMemory();
+    const bool result = impl_->base_sgmt_->all_memory_deallocated();
+    impl_->reserveMemory();
+
+    return (result);
 }
 
 MemorySegment::NamedAddressResult
diff --git a/src/lib/util/memory_segment_mapped.h b/src/lib/util/memory_segment_mapped.h
index 492cf86..7702d88 100644
--- a/src/lib/util/memory_segment_mapped.h
+++ b/src/lib/util/memory_segment_mapped.h
@@ -175,7 +175,7 @@ public:
     /// read-only mode; in that case MemorySegmentError will be thrown.
     virtual void deallocate(void* ptr, size_t size);
 
-    virtual bool allMemoryDeallocated() const;
+    virtual bool allMemoryDeallocated();
 
     /// \brief Mapped segment version of setNamedAddress.
     ///
diff --git a/src/lib/util/tests/memory_segment_mapped_unittest.cc b/src/lib/util/tests/memory_segment_mapped_unittest.cc
index f8eeb5b..dc8dffc 100644
--- a/src/lib/util/tests/memory_segment_mapped_unittest.cc
+++ b/src/lib/util/tests/memory_segment_mapped_unittest.cc
@@ -467,7 +467,14 @@ TEST_F(MemorySegmentMappedTest, shrink) {
     EXPECT_EQ(shrinked_size, segment_->getSize());
 
     // Check that the segment is still usable after shrink.
-    void* p = segment_->allocate(sizeof(uint32_t));
+    void *p = NULL;
+    while (!p) {
+        try {
+            p = segment_->allocate(sizeof(uint32_t));
+        } catch (const MemorySegmentGrown&) {
+            // Do nothing. Just try again.
+        }
+    }
     segment_->deallocate(p, sizeof(uint32_t));
 }
 



More information about the bind10-changes mailing list