2022-01-10 19:39:10 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-01-24 06:22:57 +00:00
|
|
|
#include <cstdint>
|
2022-01-10 19:39:10 +00:00
|
|
|
#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;
|
2022-07-26 19:03:26 +00:00
|
|
|
|
|
|
|
/// level_ - block in level and above
|
|
|
|
explicit MemoryTrackerBlockerInThread(VariableContext level_);
|
|
|
|
|
2022-01-10 19:39:10 +00:00
|
|
|
public:
|
2022-07-26 19:03:26 +00:00
|
|
|
explicit MemoryTrackerBlockerInThread();
|
2022-01-10 19:39:10 +00:00
|
|
|
~MemoryTrackerBlockerInThread();
|
|
|
|
|
|
|
|
MemoryTrackerBlockerInThread(const MemoryTrackerBlockerInThread &) = delete;
|
|
|
|
MemoryTrackerBlockerInThread & operator=(const MemoryTrackerBlockerInThread &) = delete;
|
|
|
|
|
|
|
|
static bool isBlocked(VariableContext current_level)
|
|
|
|
{
|
|
|
|
return counter > 0 && current_level >= level;
|
|
|
|
}
|
2022-07-26 19:03:26 +00:00
|
|
|
|
|
|
|
friend class MemoryTracker;
|
2022-01-10 19:39:10 +00:00
|
|
|
};
|