mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-15 10:52:30 +00:00
26 lines
776 B
C++
26 lines
776 B
C++
|
#pragma once
|
||
|
|
||
|
#include <Common/VariableContext.h>
|
||
|
|
||
|
/// To be able to temporarily stop memory tracking from current thread.
|
||
|
struct MemoryTrackerBlockerInThread
|
||
|
{
|
||
|
private:
|
||
|
static thread_local uint64_t counter;
|
||
|
static thread_local VariableContext level;
|
||
|
|
||
|
VariableContext previous_level;
|
||
|
public:
|
||
|
/// level_ - block in level and above
|
||
|
explicit MemoryTrackerBlockerInThread(VariableContext level_ = VariableContext::User);
|
||
|
~MemoryTrackerBlockerInThread();
|
||
|
|
||
|
MemoryTrackerBlockerInThread(const MemoryTrackerBlockerInThread &) = delete;
|
||
|
MemoryTrackerBlockerInThread & operator=(const MemoryTrackerBlockerInThread &) = delete;
|
||
|
|
||
|
static bool isBlocked(VariableContext current_level)
|
||
|
{
|
||
|
return counter > 0 && current_level >= level;
|
||
|
}
|
||
|
};
|