trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zw...@apache.org
Subject git commit: Header heap fixes.
Date Sat, 17 Mar 2012 22:50:33 GMT
Updated Branches:
  refs/heads/master 925b7d72d -> 41fa47f35


Header heap fixes.

Authors and reviews: amc, bcall, igalic, jplevyak, jpeach, leif


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/41fa47f3
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/41fa47f3
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/41fa47f3

Branch: refs/heads/master
Commit: 41fa47f35540a0d4e939a6b456d73a4c7d61d40b
Parents: 925b7d7
Author: Leif Hedstrom <leif@ogre.com>
Authored: Sat Mar 17 16:48:08 2012 -0600
Committer: Leif Hedstrom <leif@ogre.com>
Committed: Sat Mar 17 16:48:08 2012 -0600

----------------------------------------------------------------------
 proxy/hdrs/HdrHeap.cc |    2 ++
 proxy/hdrs/HdrHeap.h  |   29 ++++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/41fa47f3/proxy/hdrs/HdrHeap.cc
----------------------------------------------------------------------
diff --git a/proxy/hdrs/HdrHeap.cc b/proxy/hdrs/HdrHeap.cc
index a2f5b5e..9bf2be4 100644
--- a/proxy/hdrs/HdrHeap.cc
+++ b/proxy/hdrs/HdrHeap.cc
@@ -335,7 +335,9 @@ HdrHeap::expand_str(const char *old_str, int old_len, int new_len)
 char *
 HdrHeap::duplicate_str(const char *str, int nbytes)
 {
+  ProtectHeaps protect(this); // Don't let the source get de-allocated.
   char *new_str = allocate_str(nbytes);
+
   memcpy(new_str, str, nbytes);
   return (new_str);
 }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/41fa47f3/proxy/hdrs/HdrHeap.h
----------------------------------------------------------------------
diff --git a/proxy/hdrs/HdrHeap.h b/proxy/hdrs/HdrHeap.h
index 77d7a36..4d76f6b 100644
--- a/proxy/hdrs/HdrHeap.h
+++ b/proxy/hdrs/HdrHeap.h
@@ -251,11 +251,38 @@ public:
   void evacuate_from_str_heaps(HdrStrHeap * new_heap);
   int attach_str_heap(char *h_start, int h_len, RefCountObj * h_ref_obj, int *index);
 
+  /** Struct to prevent garbage collection on heaps.
+      This bumps the reference count to the heaps while the
+      instance of this class exists. When it goes out of scope
+      the references are dropped. This is useful inside a method or
+      block to keep all the heap data around until leaving the scope.
+  */
+  struct ProtectHeaps {
+    /// Construct the protection.
+    ProtectHeaps(HdrHeap* heap)
+      : m_read_write_heap(heap->m_read_write_heap)
+    {
+      for (int i=0; i < HDR_BUF_RONLY_HEAPS; ++i)
+        m_ronly_heap[i] = heap->m_ronly_heap[i].m_ref_count_ptr;
+    }
+
+    /// Drop the protection.
+    ~ProtectHeaps()
+    {
+      // The default destructor takes care of the rw-heap
+      for (int i=0; i < HDR_BUF_RONLY_HEAPS; ++i)
+        m_ronly_heap[i] = NULL;
+    }
+
+    Ptr<HdrStrHeap> m_read_write_heap; ///< Reference to RW heap.
+    /// References to string heaps.
+    Ptr<RefCountObj> m_ronly_heap[HDR_BUF_RONLY_HEAPS];
+  };
+
   // String Heap access
   Ptr<HdrStrHeap> m_read_write_heap;
   StrHeapDesc m_ronly_heap[HDR_BUF_RONLY_HEAPS];
   int m_lost_string_space;
-
 };
 
 inline void


Mime
View raw message