Initial commit

This commit is contained in:
Jan Mühlig
2021-03-22 18:38:54 +01:00
commit ad8c48083c
128 changed files with 33166 additions and 0 deletions

40
src/mx/tasking/load.h Normal file
View File

@@ -0,0 +1,40 @@
#pragma once
#include <bitset>
#include <cstdint>
namespace mx::tasking {
/**
* Persists the channel load for the last 64 requests.
*/
class Load
{
public:
constexpr Load() = default;
~Load() = default;
Load &operator+=(const bool hit) noexcept
{
_hits <<= 1;
_hits.set(0, hit);
return *this;
}
Load &operator|=(const Load &other) noexcept
{
_hits |= other._hits;
return *this;
}
/**
* @return Number of successful requests.
*/
[[nodiscard]] std::size_t count() const noexcept { return _hits.count(); }
bool operator<(const Load &other) const noexcept { return _hits.count() < other._hits.count(); }
bool operator<(const std::size_t other) const noexcept { return _hits.count() < other; }
private:
// Bitvector of the last 64 requests.
std::bitset<64> _hits{0U};
};
} // namespace mx::tasking