Merge pull request #17658 from azat/MemoryTracker-nested-blocking

Make LockExceptionInThread/BlockerInThread nested
This commit is contained in:
alexey-milovidov 2020-12-01 20:53:10 +03:00 committed by GitHub
commit f25adea3b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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; }
};
};