// callbacks (getting new value from observable and storing it into value_
// is not atomic).
std::lock_guard<std::mutex> lg(updateMutex_);
- updateValue();
+ if (!updateValue()) {
+ // Value didn't change, so we can skip the version update.
+ return;
+ }
bool expected = false;
if (updateRequested_.compare_exchange_strong(expected, true)) {
}
private:
- void updateValue() {
+ bool updateValue() {
auto newValue = Traits::get(observable_);
+ auto newValuePtr = newValue.get();
if (!newValue) {
throw std::logic_error("Observable returned nullptr.");
}
value_.swap(newValue);
+ return newValuePtr != newValue.get();
}
folly::Synchronized<std::shared_ptr<const T>> value_;