diff --git a/src/Common/CgroupsMemoryUsageObserver.cpp b/src/Common/CgroupsMemoryUsageObserver.cpp index e55fd44a524..661b80a6059 100644 --- a/src/Common/CgroupsMemoryUsageObserver.cpp +++ b/src/Common/CgroupsMemoryUsageObserver.cpp @@ -100,7 +100,7 @@ void CgroupsMemoryUsageObserver::setMemoryUsageLimits(uint64_t hard_limit_, uint void CgroupsMemoryUsageObserver::setOnMemoryAmountAvailableChanged(OnMemoryAmountAvailableChangedFn on_memory_amount_available_changed_) { - std::lock_guard limit_lock(limit_mutex); + std::lock_guard memory_amount_change_lock(memory_amount_change_mutex); on_memory_amount_available_changed = on_memory_amount_available_changed_; } @@ -299,7 +299,7 @@ void CgroupsMemoryUsageObserver::runThread() { LOG_INFO(log, "Memory amount available to the process changed from {} to {}", ReadableSize(last_available_memory_amount), ReadableSize(available_memory_amount)); last_available_memory_amount = available_memory_amount; - std::lock_guard limit_lock(limit_mutex); + std::lock_guard memory_amount_change_lock(memory_amount_change_mutex); on_memory_amount_available_changed(); } diff --git a/src/Common/CgroupsMemoryUsageObserver.h b/src/Common/CgroupsMemoryUsageObserver.h index eb755d04187..7ad0f882edd 100644 --- a/src/Common/CgroupsMemoryUsageObserver.h +++ b/src/Common/CgroupsMemoryUsageObserver.h @@ -51,7 +51,8 @@ private: size_t soft_limit TSA_GUARDED_BY(limit_mutex) = 0; OnMemoryLimitFn on_hard_limit TSA_GUARDED_BY(limit_mutex); OnMemoryLimitFn on_soft_limit TSA_GUARDED_BY(limit_mutex); - OnMemoryAmountAvailableChangedFn on_memory_amount_available_changed TSA_GUARDED_BY(limit_mutex); + std::mutex memory_amount_change_mutex; + OnMemoryAmountAvailableChangedFn on_memory_amount_available_changed TSA_GUARDED_BY(memory_amount_change_mutex); uint64_t last_memory_usage = 0; /// how much memory does the process use uint64_t last_available_memory_amount; /// how much memory can the process use @@ -86,6 +87,7 @@ private: #else class CgroupsMemoryUsageObserver { + using OnMemoryAmountAvailableChangedFn = std::function; public: explicit CgroupsMemoryUsageObserver(std::chrono::seconds) {}