Skip to content

Commit

Permalink
MB-49348: Have atomic_setIfBigger return status
Browse files Browse the repository at this point in the history
Change-Id: Iabc94acc35dd400ebf04aad5376a18140b26a8cd
Reviewed-on: http://review.couchbase.org/c/platform/+/165140
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: Dave Rigby <daver@couchbase.com>
  • Loading branch information
BenHuddleston authored and daverigby committed Nov 5, 2021
1 parent ca3c338 commit 004a18a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions include/platform/atomic.h
Expand Up @@ -14,14 +14,15 @@
#include <mutex>

template <typename T>
void atomic_setIfBigger(std::atomic<T>& obj, const T& newValue) {
bool atomic_setIfBigger(std::atomic<T>& obj, const T& newValue) {
T oldValue = obj.load();
while (newValue > oldValue) {
if (obj.compare_exchange_strong(oldValue, newValue)) {
break;
return true;
}
oldValue = obj.load();
}
return false;
}

template <typename T>
Expand Down

0 comments on commit 004a18a

Please sign in to comment.