reader_permit: resources: remove operator bool and >=

These cannot be meaningfully define for a vector value like resources.
To prevent instinctive misuse, remove them. Operator bool is replaced
with `non_zero()` which hopefully better expresses what to expected.
The comparison operator is just removed and inlined into its own user,
which actually help said user's readability.

Closes #11813
This commit is contained in:
Botond Dénes
2022-10-20 09:53:29 +03:00
committed by Avi Kivity
parent 264f453b9d
commit 669b225c67
2 changed files with 5 additions and 9 deletions

View File

@@ -37,7 +37,7 @@ reader_permit::resource_units::resource_units(resource_units&& o) noexcept
}
reader_permit::resource_units::~resource_units() {
if (_resources) {
if (_resources.non_zero()) {
reset();
}
}
@@ -59,7 +59,7 @@ void reader_permit::resource_units::add(resource_units&& o) {
void reader_permit::resource_units::reset(reader_resources res) {
_permit.consume(res);
if (_resources) {
if (_resources.non_zero()) {
_permit.signal(_resources);
}
_resources = res;
@@ -143,7 +143,7 @@ public:
signal(_base_resources);
}
if (_resources) {
if (_resources.non_zero()) {
on_internal_error_noexcept(rcslog, format("reader_permit::impl::~impl(): permit {} detected a leak of {{count={}, memory={}}} resources",
description(),
_resources.count,
@@ -834,7 +834,7 @@ void reader_concurrency_semaphore::close_reader(flat_mutation_reader_v2 reader)
bool reader_concurrency_semaphore::has_available_units(const resources& r) const {
// Special case: when there is no active reader (based on count) admit one
// regardless of availability of memory.
return (bool(_resources) && _resources >= r) || _resources.count == _initial_resources.count;
return (_resources.non_zero() && _resources.count >= r.count && _resources.memory >= r.memory) || _resources.count == _initial_resources.count;
}
bool reader_concurrency_semaphore::all_used_permits_are_stalled() const {

View File

@@ -32,10 +32,6 @@ struct reader_resources {
, memory(memory) {
}
bool operator>=(const reader_resources& other) const {
return count >= other.count && memory >= other.memory;
}
reader_resources operator-(const reader_resources& other) const {
return reader_resources{count - other.count, memory - other.memory};
}
@@ -56,7 +52,7 @@ struct reader_resources {
return *this;
}
explicit operator bool() const {
bool non_zero() const {
return count > 0 || memory > 0;
}
};