From ccf72bb0b8aa9c421bb2964acca2dcd868d10a94 Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期二, 18 五月 2021 11:41:46 +0800 Subject: [PATCH] use more rational node timeout, 60s. --- src/robust.cpp | 16 +++++++++++----- 1 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/robust.cpp b/src/robust.cpp index 26d41b9..4654652 100644 --- a/src/robust.cpp +++ b/src/robust.cpp @@ -35,24 +35,30 @@ bool FMutex::try_lock() { - if (mtx_.try_lock()) { - if (flock(fd_, LOCK_EX | LOCK_NB) == 0) { + if (flock(fd_, LOCK_EX | LOCK_NB) == 0) { + ++count_; + if (mtx_.try_lock()) { return true; } else { - mtx_.unlock(); + if (--count_ == 0) { + flock(fd_, LOCK_UN); + } } } return false; } void FMutex::lock() { - mtx_.lock(); flock(fd_, LOCK_EX); + ++count_; + mtx_.lock(); } void FMutex::unlock() { - flock(fd_, LOCK_UN); mtx_.unlock(); + if (--count_ == 0) { + flock(fd_, LOCK_UN); + } } } // namespace robust \ No newline at end of file -- Gitblit v1.8.0