From 34cd75f77d0ca94dbdba4e6cc9451fe4d33e78b3 Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期三, 19 五月 2021 19:14:13 +0800 Subject: [PATCH] add api BHQueryProcs. --- src/robust.cpp | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/robust.cpp b/src/robust.cpp index 08d2073..4654652 100644 --- a/src/robust.cpp +++ b/src/robust.cpp @@ -36,24 +36,29 @@ bool FMutex::try_lock() { if (flock(fd_, LOCK_EX | LOCK_NB) == 0) { + ++count_; if (mtx_.try_lock()) { return true; } else { - flock(fd_, LOCK_UN); + if (--count_ == 0) { + flock(fd_, LOCK_UN); + } } } return false; } void FMutex::lock() { - //Note: the lock order affects performance a lot, - // locking fd_ first is about 100 times faster than locking mtx_ first. flock(fd_, LOCK_EX); + ++count_; mtx_.lock(); } void FMutex::unlock() { mtx_.unlock(); - flock(fd_, LOCK_UN); + if (--count_ == 0) { + flock(fd_, LOCK_UN); + } } + } // namespace robust \ No newline at end of file -- Gitblit v1.8.0