From a91db513ebaf9b355d99d81fb5b7bfe16228f971 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 30 Oct 2018 14:21:36 +0300 Subject: [PATCH] Better create_local_lock. GitOrigin-RevId: ce705e7258ad05bde1ac6c72cc8a045c128fa8a6 --- tdutils/td/utils/port/FileFd.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tdutils/td/utils/port/FileFd.cpp b/tdutils/td/utils/port/FileFd.cpp index 225f495a..38d24623 100644 --- a/tdutils/td/utils/port/FileFd.cpp +++ b/tdutils/td/utils/port/FileFd.cpp @@ -286,7 +286,7 @@ Result FileFd::pread(MutableSlice slice, int64 offset) const { static std::mutex in_process_lock_mutex; static std::unordered_set locked_files; -static Status create_local_lock(const string &path, int32 max_tries) { +static Status create_local_lock(const string &path, int32 &max_tries) { while (true) { { // mutex lock scope std::lock_guard lock(in_process_lock_mutex); @@ -298,13 +298,12 @@ static Status create_local_lock(const string &path, int32 max_tries) { } if (--max_tries <= 0) { - break; + return Status::Error( + 0, PSLICE() << "Can't lock file \"" << path << "\", because it is already in use by current program"); } usleep_for(100000); } - return Status::Error( - 0, PSLICE() << "Can't lock file \"" << path << "\", because it is already in use by current program"); } Status FileFd::lock(const LockFlags flags, const string &path, int32 max_tries) {