2020-03-19 13:29:59 +00:00
|
|
|
#pragma once
|
2020-03-19 11:45:52 +00:00
|
|
|
#include <atomic>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2020-03-19 14:30:43 +00:00
|
|
|
/// This class helps to calculate rows_before_limit_at_least.
|
2020-03-19 11:45:52 +00:00
|
|
|
class RowsBeforeLimitCounter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void add(uint64_t rows)
|
|
|
|
{
|
|
|
|
setAppliedLimit();
|
|
|
|
rows_before_limit.fetch_add(rows, std::memory_order_release);
|
|
|
|
}
|
|
|
|
|
2020-06-03 19:50:11 +00:00
|
|
|
void set(uint64_t rows)
|
|
|
|
{
|
|
|
|
setAppliedLimit();
|
|
|
|
rows_before_limit.store(rows, std::memory_order_release);
|
|
|
|
}
|
|
|
|
|
2020-03-19 11:45:52 +00:00
|
|
|
uint64_t get() const { return rows_before_limit.load(std::memory_order_acquire); }
|
|
|
|
|
2020-04-12 20:05:58 +00:00
|
|
|
void setAppliedLimit() { has_applied_limit.store(true, std::memory_order_release); }
|
2020-03-19 11:45:52 +00:00
|
|
|
bool hasAppliedLimit() const { return has_applied_limit.load(std::memory_order_acquire); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::atomic<uint64_t> rows_before_limit = 0;
|
|
|
|
std::atomic_bool has_applied_limit = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
using RowsBeforeLimitCounterPtr = std::shared_ptr<RowsBeforeLimitCounter>;
|
|
|
|
|
|
|
|
}
|