Put Arena destructor and move constructors in header

This commit is contained in:
2025-09-15 17:01:38 -04:00
parent ae0c014298
commit 1acdc1e753
5 changed files with 32 additions and 45 deletions

View File

@@ -5,36 +5,6 @@
#include <limits>
#include <vector>
Arena::~Arena() {
while (current_block_) {
Block *prev = current_block_->prev;
std::free(current_block_);
current_block_ = prev;
}
}
Arena::Arena(Arena &&other) noexcept
: initial_block_size_(other.initial_block_size_),
current_block_(other.current_block_) {
other.current_block_ = nullptr;
}
Arena &Arena::operator=(Arena &&other) noexcept {
if (this != &other) {
while (current_block_) {
Block *prev = current_block_->prev;
std::free(current_block_);
current_block_ = prev;
}
initial_block_size_ = other.initial_block_size_;
current_block_ = other.current_block_;
other.current_block_ = nullptr;
}
return *this;
}
void Arena::reset() {
if (!current_block_) {
return;

View File

@@ -154,7 +154,13 @@ public:
* Traverses the intrusive linked list backwards from current_block_,
* freeing each block. This ensures no memory leaks.
*/
~Arena();
~Arena() {
while (current_block_) {
Block *prev = current_block_->prev;
std::free(current_block_);
current_block_ = prev;
}
}
/// Copy construction is not allowed (would be expensive and error-prone)
Arena(const Arena &) = delete;
@@ -173,7 +179,11 @@ public:
* - used_bytes(), total_bytes() return 0
* - Destructor is safe to call
*/
Arena(Arena &&other) noexcept;
Arena(Arena &&other) noexcept
: initial_block_size_(other.initial_block_size_),
current_block_(other.current_block_) {
other.current_block_ = nullptr;
}
/**
* @brief Move assignment operator - transfers ownership of all blocks.
@@ -191,7 +201,21 @@ public:
* - used_bytes(), total_bytes() return 0
* - Destructor is safe to call
*/
Arena &operator=(Arena &&other) noexcept;
Arena &operator=(Arena &&other) noexcept {
if (this != &other) {
while (current_block_) {
Block *prev = current_block_->prev;
std::free(current_block_);
current_block_ = prev;
}
initial_block_size_ = other.initial_block_size_;
current_block_ = other.current_block_;
other.current_block_ = nullptr;
}
return *this;
}
/**
* @brief Allocate raw memory with the specified size and alignment.

View File

@@ -106,7 +106,7 @@ private:
// Lock-free pipeline configuration
static constexpr int lg_size = 16; // Ring buffer size (2^16 slots)
static constexpr auto wait_strategy = WaitStrategy::WaitIfUpstreamIdle;
static constexpr auto wait_strategy = WaitStrategy::WaitIfStageEmpty;
// 4-stage pipeline: sequence -> resolve -> persist -> release
StaticThreadPipeline<PipelineEntry, wait_strategy, 1, 1, 1, 1> pipeline_;

View File

@@ -210,17 +210,7 @@ void HttpHandler::on_batch_complete(std::span<Connection *const> batch) {
void HttpHandler::on_data_arrived(std::string_view data, Connection &conn) {
auto *state = static_cast<HttpConnectionState *>(conn.user_data);
if (!state) {
// Create a temporary arena and add error response directly to avoid
// sequence issues
auto json_response = R"({"error":"Internal server error"})";
auto http_response =
format_json_response(500, json_response, state->pending.arena, 0, true);
state->send_ordered_response(conn, state->get_next_sequence_id(),
http_response, std::move(state->pending.arena),
true);
return;
}
assert(state);
// TODO: Enforce the configured max_request_size_bytes limit here.
// Should track cumulative bytes received for the current HTTP request

View File

@@ -27,3 +27,6 @@ request_id_retention_versions = 100000000
max_buffer_size_bytes = 10485760 # 10MB
# Interval for sending keepalive comments to prevent idle timeouts (seconds)
keepalive_interval_seconds = 30
[benchmark]
ok_resolve_iterations = 0