|
|
|
@ -40,19 +40,15 @@
|
|
|
|
|
#include "base/ansi_scrubber.hh"
|
|
|
|
|
#include "shared_buffer.hh"
|
|
|
|
|
|
|
|
|
|
static const bool DEBUG_TRACE = false;
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
shared_buffer_ref::share(shared_buffer& sb, const char* data, size_t len)
|
|
|
|
|
{
|
|
|
|
|
#ifdef HAVE_EXECINFO_H
|
|
|
|
|
if (DEBUG_TRACE) {
|
|
|
|
|
void* frames[128];
|
|
|
|
|
int rc;
|
|
|
|
|
#if SHARED_BUFFER_TRACE
|
|
|
|
|
void* frames[128];
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
rc = backtrace(frames, 128);
|
|
|
|
|
this->sb_backtrace.reset(backtrace_symbols(frames, rc));
|
|
|
|
|
}
|
|
|
|
|
rc = backtrace(frames, 128);
|
|
|
|
|
this->sb_backtrace.reset(backtrace_symbols(frames, rc));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
this->disown();
|
|
|
|
@ -95,8 +91,36 @@ shared_buffer_ref::shared_buffer_ref(shared_buffer_ref&& other) noexcept
|
|
|
|
|
this->sb_data = nullptr;
|
|
|
|
|
this->sb_length = 0;
|
|
|
|
|
} else if (other.sb_owner != nullptr) {
|
|
|
|
|
auto owner_ref_iter = std::find(other.sb_owner->sb_refs.begin(),
|
|
|
|
|
other.sb_owner->sb_refs.end(),
|
|
|
|
|
auto owner_ref_iter = std::find(other.sb_owner->sb_refs.rbegin(),
|
|
|
|
|
other.sb_owner->sb_refs.rend(),
|
|
|
|
|
&other);
|
|
|
|
|
*owner_ref_iter = this;
|
|
|
|
|
this->sb_owner = std::exchange(other.sb_owner, nullptr);
|
|
|
|
|
this->sb_data = std::exchange(other.sb_data, nullptr);
|
|
|
|
|
this->sb_length = std::exchange(other.sb_length, 0);
|
|
|
|
|
} else {
|
|
|
|
|
this->sb_owner = nullptr;
|
|
|
|
|
this->sb_data = other.sb_data;
|
|
|
|
|
this->sb_length = other.sb_length;
|
|
|
|
|
other.sb_data = nullptr;
|
|
|
|
|
other.sb_length = 0;
|
|
|
|
|
}
|
|
|
|
|
this->sb_metadata = other.sb_metadata;
|
|
|
|
|
other.sb_metadata = {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shared_buffer_ref&
|
|
|
|
|
shared_buffer_ref::operator=(shared_buffer_ref&& other)
|
|
|
|
|
{
|
|
|
|
|
this->disown();
|
|
|
|
|
|
|
|
|
|
if (other.sb_data == nullptr) {
|
|
|
|
|
this->sb_owner = nullptr;
|
|
|
|
|
this->sb_data = nullptr;
|
|
|
|
|
this->sb_length = 0;
|
|
|
|
|
} else if (other.sb_owner != nullptr) {
|
|
|
|
|
auto owner_ref_iter = std::find(other.sb_owner->sb_refs.rbegin(),
|
|
|
|
|
other.sb_owner->sb_refs.rend(),
|
|
|
|
|
&other);
|
|
|
|
|
*owner_ref_iter = this;
|
|
|
|
|
this->sb_owner = std::exchange(other.sb_owner, nullptr);
|
|
|
|
@ -111,6 +135,8 @@ shared_buffer_ref::shared_buffer_ref(shared_buffer_ref&& other) noexcept
|
|
|
|
|
}
|
|
|
|
|
this->sb_metadata = other.sb_metadata;
|
|
|
|
|
other.sb_metadata = {};
|
|
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|