Make LockExceptionInThread/BlockerInThread nested

This commit is contained in:
Azat Khuzhin 2020-12-01 10:34:25 +03:00
parent 0739ed8f97
commit 0bf6ed2e94
2 changed files with 10 additions and 10 deletions

View File

@ -64,8 +64,8 @@ namespace ProfileEvents
static constexpr size_t log_peak_memory_usage_every = 1ULL << 30;
thread_local bool MemoryTracker::BlockerInThread::is_blocked = false;
thread_local bool MemoryTracker::LockExceptionInThread::is_blocked = false;
thread_local uint64_t MemoryTracker::BlockerInThread::counter = 0;
thread_local uint64_t MemoryTracker::LockExceptionInThread::counter = 0;
MemoryTracker total_memory_tracker(nullptr, VariableContext::Global);

View File

@ -136,11 +136,11 @@ public:
private:
BlockerInThread(const BlockerInThread &) = delete;
BlockerInThread & operator=(const BlockerInThread &) = delete;
static thread_local bool is_blocked;
static thread_local uint64_t counter;
public:
BlockerInThread() { is_blocked = true; }
~BlockerInThread() { is_blocked = false; }
static bool isBlocked() { return is_blocked; }
BlockerInThread() { ++counter; }
~BlockerInThread() { --counter; }
static bool isBlocked() { return counter > 0; }
};
/// To be able to avoid MEMORY_LIMIT_EXCEEDED Exception in destructors:
@ -160,11 +160,11 @@ public:
private:
LockExceptionInThread(const LockExceptionInThread &) = delete;
LockExceptionInThread & operator=(const LockExceptionInThread &) = delete;
static thread_local bool is_blocked;
static thread_local uint64_t counter;
public:
LockExceptionInThread() { is_blocked = true; }
~LockExceptionInThread() { is_blocked = false; }
static bool isBlocked() { return is_blocked; }
LockExceptionInThread() { ++counter; }
~LockExceptionInThread() { --counter; }
static bool isBlocked() { return counter > 0; }
};
};