MB-20079: Ensure updateWaketimeIfLessThan performs a compare_exchange 27/70027/4
authorDaniel Owen <owend@couchbase.com>
Thu, 17 Nov 2016 17:00:25 +0000 (17:00 +0000)
committerDave Rigby <daver@couchbase.com>
Fri, 18 Nov 2016 09:20:40 +0000 (09:20 +0000)
The patch MB-20079: Use std::chrono::steady_clock (ProcessClock) with
changeID: I2fc9688abb782fe2c9e80efb6da840be3643d4a5 introduced a bug
where the waketime could be incorrectly updated, due to not performing
a compare_exchange_strong.

This patch reverts to using a compare_exchange_strong, ensuring that
waketime is only updated if it is less than the input time_point.

Change-Id: Ib68689f9a76c6a0455422c293ad62e9c4d04f3d7
Reviewed-on: http://review.couchbase.org/70027
Reviewed-by: Dave Rigby <daver@couchbase.com>
Tested-by: buildbot <build@couchbase.com>
src/tasks.h

index 1d82a2f..6d49af6 100644 (file)
@@ -193,9 +193,7 @@ protected:
 
     void updateWaketimeIfLessThan(const ProcessClock::time_point tp) {
         const auto tp_ns = to_ns_since_epoch(tp).count();
-        if (tp_ns > waketime) {
-            waketime = tp_ns;
-        }
+        atomic_setIfBigger(waketime, tp_ns);
     }
 
 private: