fix dead lock

This commit is contained in:
Han Fei 2024-03-14 13:25:24 +01:00
parent 4e12b5dc91
commit 95b218e7d4
2 changed files with 5 additions and 3 deletions

View File

@ -100,7 +100,7 @@ void CgroupsMemoryUsageObserver::setMemoryUsageLimits(uint64_t hard_limit_, uint
void CgroupsMemoryUsageObserver::setOnMemoryAmountAvailableChanged(OnMemoryAmountAvailableChangedFn on_memory_amount_available_changed_)
{
std::lock_guard<std::mutex> limit_lock(limit_mutex);
std::lock_guard<std::mutex> 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<std::mutex> limit_lock(limit_mutex);
std::lock_guard<std::mutex> memory_amount_change_lock(memory_amount_change_mutex);
on_memory_amount_available_changed();
}

View File

@ -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<void()>;
public:
explicit CgroupsMemoryUsageObserver(std::chrono::seconds) {}