diff --git a/xo-arena/include/xo/arena/DCircularBuffer.hpp b/xo-arena/include/xo/arena/DCircularBuffer.hpp index 7e49def3..c7c8abf9 100644 --- a/xo-arena/include/xo/arena/DCircularBuffer.hpp +++ b/xo-arena/include/xo/arena/DCircularBuffer.hpp @@ -132,12 +132,6 @@ namespace xo { **/ void report_append(span_type r); - /** expand hi end of mapped memory range to at least @p hi. - * - * Require: @p hi < @ref reserved_range_.hi - **/ - bool expand_to(byte * hi); - /** consume span (or prefix thereof) previously obtained from @ref occupied_range() * Caller represents that it won't need to read this memory again * unless overlaps with a pinned span. @@ -162,6 +156,12 @@ namespace xo { /** @defgroup mm-circularbuffer-private-methods CircularBuffer non-const methods **/ ///@{ + /** expand hi end of mapped memory range to at least @p hi. + * + * Require: @p hi < @ref reserved_range_.hi + **/ + bool _expand_to(byte * hi); + /** shrink occupied rnage to the smallest contiguous range that contains both: * all of .input_range_, and all pinned ranges in .pinned_spans_ **/ diff --git a/xo-arena/src/arena/DCircularBuffer.cpp b/xo-arena/src/arena/DCircularBuffer.cpp index 9e8b28b8..70efcd2d 100644 --- a/xo-arena/src/arena/DCircularBuffer.cpp +++ b/xo-arena/src/arena/DCircularBuffer.cpp @@ -171,7 +171,7 @@ namespace xo { } /* establish mapped range at least to dest.hi */ - this->expand_to(dest.hi()); + this->_expand_to(dest.hi()); /* report available memory */ return span_type(occupied_range_.hi(), mapped_range_.hi()); @@ -250,38 +250,6 @@ namespace xo { this->_check_reset_map_start(); } - bool - DCircularBuffer::expand_to(byte * hi) { - scope log(XO_DEBUG(config_.debug_flag_)); - - if (hi < mapped_range_.hi()) { - /* nothing todo */ - return true; - } - - size_t add_z = hi - mapped_range_.hi(); - size_t add_commit_z = padding::with_padding(add_z, buffer_align_z_); - byte * commit_start = mapped_range_.hi(); - - if (::mprotect(commit_start, - add_commit_z, - PROT_READ | PROT_WRITE) != 0) - { - if (log) { - log("commit failed"); - log(xtag("commit_start", commit_start), - xtag("add_z", add_z), - xtag("add_commit_z", add_commit_z)); - } - - // this->capture_error(error::commit_failed, add_commit_z); - return false; - } - - this->mapped_range_ += span(commit_start, add_commit_z); - return true; - } - void DCircularBuffer::pin_range(span_type r) { @@ -333,6 +301,38 @@ namespace xo { } } + bool + DCircularBuffer::_expand_to(byte * hi) { + scope log(XO_DEBUG(config_.debug_flag_)); + + if (hi < mapped_range_.hi()) { + /* nothing todo */ + return true; + } + + size_t add_z = hi - mapped_range_.hi(); + size_t add_commit_z = padding::with_padding(add_z, buffer_align_z_); + byte * commit_start = mapped_range_.hi(); + + if (::mprotect(commit_start, + add_commit_z, + PROT_READ | PROT_WRITE) != 0) + { + if (log) { + log("commit failed"); + log(xtag("commit_start", commit_start), + xtag("add_z", add_z), + xtag("add_commit_z", add_commit_z)); + } + + // this->capture_error(error::commit_failed, add_commit_z); + return false; + } + + this->mapped_range_ += span(commit_start, add_commit_z); + return true; + } + void DCircularBuffer::_shrink_occupied_to_fit() { diff --git a/xo-arena/utest/DCircularBuffer.test.cpp b/xo-arena/utest/DCircularBuffer.test.cpp index debfc41f..be869478 100644 --- a/xo-arena/utest/DCircularBuffer.test.cpp +++ b/xo-arena/utest/DCircularBuffer.test.cpp @@ -55,6 +55,8 @@ namespace xo { REQUIRE(buf.occupied_range().to_string_view() == std::string_view("defghijklmnopq")); } + + // TODO: test pin_range() / unpin_range() } /*namespace ut*/ } /*namespace xo*/