You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2016/05/11 20:31:53 UTC
[trafficserver] 29/33: TS-4425: Switch proxy/hdrs over to
Ptr::get().
This is an automated email from the ASF dual-hosted git repository.
jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git
commit e61ea1b55470304a467f5ac7cf7d9b425470e56e
Author: James Peach <jp...@apache.org>
AuthorDate: Sat May 7 13:59:01 2016 -0700
TS-4425: Switch proxy/hdrs over to Ptr::get().
---
proxy/hdrs/HdrHeap.cc | 44 +++++++++++++++++++++-----------------------
proxy/hdrs/HdrHeap.h | 44 ++++++++++++++++++++++----------------------
proxy/hdrs/HdrTSOnly.cc | 2 +-
3 files changed, 44 insertions(+), 46 deletions(-)
diff --git a/proxy/hdrs/HdrHeap.cc b/proxy/hdrs/HdrHeap.cc
index 9f01e19..cc0721c 100644
--- a/proxy/hdrs/HdrHeap.cc
+++ b/proxy/hdrs/HdrHeap.cc
@@ -43,7 +43,6 @@ Allocator hdrHeapAllocator("hdrHeap", HDR_HEAP_DEFAULT_SIZE);
static HdrHeap proto_heap;
Allocator strHeapAllocator("hdrStrHeap", HDR_STR_HEAP_DEFAULT_SIZE);
-static HdrStrHeap str_proto_heap;
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
@@ -99,11 +98,11 @@ HdrHeap::init()
// We need to clear m_ptr directly since it's garbage and
// using the operator functions will to free() what ever
// garbage it is pointing to
- m_read_write_heap.m_ptr = NULL;
+ m_read_write_heap.detach();
for (int i = 0; i < HDR_BUF_RONLY_HEAPS; i++) {
m_ronly_heap[i].m_heap_start = NULL;
- m_ronly_heap[i].m_ref_count_ptr.m_ptr = NULL;
+ m_ronly_heap[i].m_ref_count_ptr.detach();
m_ronly_heap[i].m_locked = false;
m_ronly_heap[i].m_heap_len = 0;
}
@@ -332,8 +331,8 @@ HdrHeap::demote_rw_str_heap()
for (int i = 0; i < HDR_BUF_RONLY_HEAPS; i++) {
if (m_ronly_heap[i].m_heap_start == NULL) {
// We've found a slot
- m_ronly_heap[i].m_ref_count_ptr = m_read_write_heap;
- m_ronly_heap[i].m_heap_start = (char *)m_read_write_heap.m_ptr;
+ m_ronly_heap[i].m_ref_count_ptr = m_read_write_heap.object();
+ m_ronly_heap[i].m_heap_start = (char *)m_read_write_heap.get();
m_ronly_heap[i].m_heap_len = m_read_write_heap->m_heap_size - m_read_write_heap->m_free_size;
// Debug("hdrs", "Demoted rw heap of %d size", m_read_write_heap->m_heap_size);
@@ -479,7 +478,7 @@ HdrHeap::sanity_check_strs()
// Build up a string check table
if (m_read_write_heap) {
- heaps[num_heaps].start = ((char *)m_read_write_heap.m_ptr) + sizeof(HdrStrHeap);
+ heaps[num_heaps].start = ((char *)m_read_write_heap.get()) + sizeof(HdrStrHeap);
int heap_size = m_read_write_heap->m_heap_size - (sizeof(HdrStrHeap) + m_read_write_heap->m_free_size);
@@ -669,12 +668,12 @@ HdrHeap::marshal(char *buf, int len)
marshal_hdr->m_size = ptr_heap_size + HDR_HEAP_HDR_SIZE;
marshal_hdr->m_next = NULL;
marshal_hdr->m_free_size = 0;
- marshal_hdr->m_read_write_heap.m_ptr = NULL;
+ marshal_hdr->m_read_write_heap.detach();
marshal_hdr->m_lost_string_space = this->m_lost_string_space;
// We'have one read-only string heap after marshalling
marshal_hdr->m_ronly_heap[0].m_heap_start = (char *)(intptr_t)marshal_hdr->m_size; // offset
- marshal_hdr->m_ronly_heap[0].m_ref_count_ptr.m_ptr = NULL;
+ marshal_hdr->m_ronly_heap[0].m_ref_count_ptr.detach();
for (int i = 1; i < HDR_BUF_RONLY_HEAPS; i++)
marshal_hdr->m_ronly_heap[i].m_heap_start = NULL;
@@ -691,7 +690,7 @@ HdrHeap::marshal(char *buf, int len)
MarshalXlate str_xlation[HDR_BUF_RONLY_HEAPS + 1];
if (m_read_write_heap) {
- char *copy_start = ((char *)m_read_write_heap.m_ptr) + sizeof(HdrStrHeap);
+ char *copy_start = ((char *)m_read_write_heap.get()) + sizeof(HdrStrHeap);
int nto_copy = m_read_write_heap->m_heap_size - (sizeof(HdrStrHeap) + m_read_write_heap->m_free_size);
if (nto_copy > len) {
@@ -904,7 +903,7 @@ HdrHeap::unmarshal(int buf_length, int obj_type, HdrHeapObjImpl **found_obj, Ref
m_free_start = ((char *)this) + m_size;
m_ronly_heap[0].m_heap_start = ((char *)this) + (intptr_t)m_ronly_heap[0].m_heap_start;
- // Crazy Invarient - If we are sitting in a ref counted block,
+ // Crazy Invariant - If we are sitting in a ref counted block,
// the HdrHeap lifetime is externally determined. Whoever
// unmarshalls us should keep the block around as long as
// they want to use the header. However, the strings can
@@ -915,8 +914,9 @@ HdrHeap::unmarshal(int buf_length, int obj_type, HdrHeapObjImpl **found_obj, Ref
// the lifetime is explicit but copies will increase
// the refcount
if (block_ref) {
- m_ronly_heap[0].m_ref_count_ptr.m_ptr = block_ref;
+ m_ronly_heap[0].m_ref_count_ptr.swizzle(block_ref);
}
+
// Loop over objects and swizzle there pointer to
// live offsets
char *obj_data = m_data_start;
@@ -962,11 +962,11 @@ HdrHeap::unmarshal(int buf_length, int obj_type, HdrHeapObjImpl **found_obj, Ref
return unmarshal_size;
}
-inline int
+inline bool
HdrHeap::attach_str_heap(char *h_start, int h_len, RefCountObj *h_ref_obj, int *index)
{
if (*index >= HDR_BUF_RONLY_HEAPS) {
- return 0;
+ return false;
}
// Loop over existing entries to see if this one is already present
@@ -980,7 +980,7 @@ HdrHeap::attach_str_heap(char *h_start, int h_len, RefCountObj *h_ref_obj, int *
// to was attached
if (h_len > m_ronly_heap[z].m_heap_len)
m_ronly_heap[z].m_heap_len = h_len;
- return 1;
+ return true;
}
}
@@ -990,7 +990,7 @@ HdrHeap::attach_str_heap(char *h_start, int h_len, RefCountObj *h_ref_obj, int *
m_ronly_heap[*index].m_locked = false;
*index = *index + 1;
- return 1;
+ return true;
}
// void HdrHeap::inhertit_string_heaps(const HdrHeap* inherit_from)
@@ -1005,7 +1005,7 @@ HdrHeap::inherit_string_heaps(const HdrHeap *inherit_from)
if (inherit_from == (const HdrHeap *)this)
return;
- int index, result;
+ int index;
int first_free = HDR_BUF_RONLY_HEAPS; // default is out of array bounds
int free_slots = 0;
int inherit_str_size = 0;
@@ -1055,16 +1055,14 @@ HdrHeap::inherit_string_heaps(const HdrHeap *inherit_from)
if (inherit_from->m_read_write_heap) {
int str_size =
inherit_from->m_read_write_heap->m_heap_size - STR_HEAP_HDR_SIZE - inherit_from->m_read_write_heap->m_free_size;
- result = attach_str_heap(((char *)inherit_from->m_read_write_heap.m_ptr) + STR_HEAP_HDR_SIZE, str_size,
- inherit_from->m_read_write_heap, &first_free);
- ink_release_assert(result != 0);
+ ink_release_assert(attach_str_heap(((char *)inherit_from->m_read_write_heap.get()) + STR_HEAP_HDR_SIZE, str_size,
+ inherit_from->m_read_write_heap.get(), &first_free));
}
// Copy over read only string heaps
for (int i = 0; i < HDR_BUF_RONLY_HEAPS; i++) {
if (inherit_from->m_ronly_heap[i].m_heap_start) {
- result = attach_str_heap(inherit_from->m_ronly_heap[i].m_heap_start, inherit_from->m_ronly_heap[i].m_heap_len,
- inherit_from->m_ronly_heap[i].m_ref_count_ptr.m_ptr, &first_free);
- ink_release_assert(result != 0);
+ ink_release_assert(attach_str_heap(inherit_from->m_ronly_heap[i].m_heap_start, inherit_from->m_ronly_heap[i].m_heap_len,
+ inherit_from->m_ronly_heap[i].m_ref_count_ptr.get(), &first_free));
}
}
@@ -1201,7 +1199,7 @@ REGRESSION_TEST(HdrHeap_Coalesce)(RegressionTest *t, int /* atype ATS_UNUSED */,
HdrHeap *heap = new_HdrHeap();
URLImpl *url = url_create(heap);
- tb.check(heap->m_read_write_heap.m_ptr == NULL, "Checking that we have no rw heap.");
+ tb.check(heap->m_read_write_heap.get() == NULL, "Checking that we have no rw heap.");
url_path_set(heap, url, buf, next_required_overflow_size, true);
tb.check(heap->m_read_write_heap->m_free_size == 0, "Checking that we've completely consumed the rw heap");
for (int i = 0; i < HDR_BUF_RONLY_HEAPS; ++i) {
diff --git a/proxy/hdrs/HdrHeap.h b/proxy/hdrs/HdrHeap.h
index cf206cd..afe25c5 100644
--- a/proxy/hdrs/HdrHeap.h
+++ b/proxy/hdrs/HdrHeap.h
@@ -60,6 +60,9 @@
#define HDR_HEAP_HDR_SIZE ROUND(sizeof(HdrHeap), HDR_PTR_SIZE)
#define STR_HEAP_HDR_SIZE sizeof(HdrStrHeap)
+class CoreUtils;
+class IOBufferBlock;
+
enum {
HDR_HEAP_OBJ_EMPTY = 0,
HDR_HEAP_OBJ_RAW = 1,
@@ -135,22 +138,6 @@ enum {
HDR_BUF_MAGIC_CORRUPT = 0xbadbadcc
};
-struct StrHeapDesc {
- StrHeapDesc();
- Ptr<RefCountObj> m_ref_count_ptr;
- char *m_heap_start;
- int32_t m_heap_len;
- bool m_locked;
-
- bool
- contains(const char *str) const
- {
- return (str >= m_heap_start && str < (m_heap_start + m_heap_len));
- }
-};
-
-class IOBufferBlock;
-
class HdrStrHeap : public RefCountObj
{
public:
@@ -171,7 +158,19 @@ public:
}
};
-class CoreUtils;
+struct StrHeapDesc {
+ StrHeapDesc();
+ Ptr<RefCountObj> m_ref_count_ptr;
+ char *m_heap_start;
+ int32_t m_heap_len;
+ bool m_locked;
+
+ bool
+ contains(const char *str) const
+ {
+ return (str >= m_heap_start && str < (m_heap_start + m_heap_len));
+ }
+};
class HdrHeap
{
@@ -211,7 +210,8 @@ public:
lock_ronly_str_heap(int i)
{
m_ronly_heap[i].m_locked = true;
- };
+ }
+
void
unlock_ronly_str_heap(int i)
{
@@ -233,7 +233,7 @@ public:
m_ronly_heap[i].m_locked = false;
}
}
- };
+ }
// Sanity Check Functions
void sanity_check_strs();
@@ -265,7 +265,7 @@ public:
void coalesce_str_heaps(int incoming_size = 0);
void evacuate_from_str_heaps(HdrStrHeap *new_heap);
size_t required_space_for_evacuation();
- int attach_str_heap(char *h_start, int h_len, RefCountObj *h_ref_obj, int *index);
+ bool 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 heap containing the pointer
@@ -278,7 +278,7 @@ public:
HeapGuard(HdrHeap *heap, const char *str)
{
if (heap->m_read_write_heap && heap->m_read_write_heap->contains(str)) {
- m_ptr = heap->m_read_write_heap;
+ m_ptr = heap->m_read_write_heap.get();
} else {
for (int i = 0; i < HDR_BUF_RONLY_HEAPS; ++i) {
if (heap->m_ronly_heap[i].contains(str)) {
@@ -290,7 +290,7 @@ public:
}
// There's no need to have a destructor here, the default dtor will take care of
- // releaseing the (potentially) locked heap.
+ // releasing the (potentially) locked heap.
/// The heap we protect (if any)
Ptr<RefCountObj> m_ptr;
diff --git a/proxy/hdrs/HdrTSOnly.cc b/proxy/hdrs/HdrTSOnly.cc
index 6a59f7c..28e0dc4 100644
--- a/proxy/hdrs/HdrTSOnly.cc
+++ b/proxy/hdrs/HdrTSOnly.cc
@@ -171,7 +171,7 @@ RETRY:
// Add block to heap in this slot
m_ronly_heap[i].m_heap_start = (char *)use_start;
m_ronly_heap[i].m_heap_len = (int)(b->end() - b->start());
- m_ronly_heap[i].m_ref_count_ptr = b->data;
+ m_ronly_heap[i].m_ref_count_ptr = b->data.object();
// printf("Attaching block at %X for %d in slot %d\n",
// m_ronly_heap[i].m_heap_start,
// m_ronly_heap[i].m_heap_len,
--
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.