From 02e735581c04950830d4b9f9c03a99aed61b165a Mon Sep 17 00:00:00 2001 From: Pieter du Preez Date: Wed, 20 Nov 2019 14:59:28 +0100 Subject: [PATCH] Force RedLockMutex::extend_lock() to return -1ms on failure. (#39) This is done by checking if the flag that RedLockMutexVessel::extend_lock() returns. If false, the lock failed and -1ms is returned. --- src/sw/redis++/recipes/redlock.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sw/redis++/recipes/redlock.h b/src/sw/redis++/recipes/redlock.h index 53a88f5f..5fcb21e6 100644 --- a/src/sw/redis++/recipes/redlock.h +++ b/src/sw/redis++/recipes/redlock.h @@ -286,7 +286,12 @@ class RedLockMutex const RedLockMutexVessel::LockInfo lock_info = {true, std::chrono::steady_clock::now(), ttl, _resource, random_string}; const auto result = _redlock_mutex.extend_lock(lock_info, ttl); - return result.time_remaining; + if (!result.locked) { + return std::chrono::milliseconds(-1); + } + else { + return result.time_remaining; + } } std::chrono::milliseconds extend_lock(const std::string &random_string,