xo-arena: tidy: make CircularBuffer::_expand_to() private
This commit is contained in:
parent
deaa55564e
commit
4065ba0bd5
3 changed files with 41 additions and 39 deletions
|
|
@ -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_
|
||||
**/
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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*/
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue