Commit 692d08fb authored by Pranjal Raihan's avatar Pranjal Raihan Committed by Facebook GitHub Bot

Refer to type names consistently

Summary: Consistently use `Observer` and `Snapshot` like everywhere else in these files instead of `folly::Observer::{Observer,Snapshot}`.

Reviewed By: yfeldblum

Differential Revision: D27685699

fbshipit-source-id: 7eca35b9d113d8d9cd8ca631be2ad54c827431ea
parent 89383c3a
......@@ -143,7 +143,7 @@ template <typename T>
T AtomicObserver<T>::get() const {
auto version = cachedVersion_.load(std::memory_order_acquire);
if (UNLIKELY(observer_.needRefresh(version))) {
folly::SharedMutex::WriteHolder guard{refreshLock_};
SharedMutex::WriteHolder guard{refreshLock_};
version = cachedVersion_.load(std::memory_order_acquire);
if (LIKELY(observer_.needRefresh(version))) {
auto snapshot = *observer_;
......@@ -178,10 +178,9 @@ template <typename T>
ReadMostlyAtomicObserver<T>::ReadMostlyAtomicObserver(Observer<T> observer)
: observer_(std::move(observer)),
cachedValue_(**observer_),
callback_(
observer_.addCallback([this](folly::observer::Snapshot<T> snapshot) {
cachedValue_.store(*snapshot, std::memory_order_relaxed);
})) {}
callback_(observer_.addCallback([this](Snapshot<T> snapshot) {
cachedValue_.store(*snapshot, std::memory_order_relaxed);
})) {}
template <typename T>
T ReadMostlyAtomicObserver<T>::get() const {
......@@ -191,11 +190,10 @@ T ReadMostlyAtomicObserver<T>::get() const {
template <typename T>
ReadMostlyTLObserver<T>::ReadMostlyTLObserver(Observer<T> observer)
: observer_(std::move(observer)),
callback_(
observer_.addCallback([this](folly::observer::Snapshot<T> snapshot) {
globalData_.lock()->reset(snapshot.getShared());
globalVersion_ = snapshot.getVersion();
})) {}
callback_(observer_.addCallback([this](Snapshot<T> snapshot) {
globalData_.lock()->reset(snapshot.getShared());
globalVersion_ = snapshot.getVersion();
})) {}
template <typename T>
ReadMostlyTLObserver<T>::ReadMostlyTLObserver(
......@@ -203,7 +201,7 @@ ReadMostlyTLObserver<T>::ReadMostlyTLObserver(
: ReadMostlyTLObserver(other.observer_) {}
template <typename T>
folly::ReadMostlySharedPtr<const T> ReadMostlyTLObserver<T>::getShared() const {
ReadMostlySharedPtr<const T> ReadMostlyTLObserver<T>::getShared() const {
if (localSnapshot_->version_ == globalVersion_.load()) {
if (auto data = localSnapshot_->data_.lock()) {
return data;
......@@ -213,7 +211,7 @@ folly::ReadMostlySharedPtr<const T> ReadMostlyTLObserver<T>::getShared() const {
}
template <typename T>
folly::ReadMostlySharedPtr<const T> ReadMostlyTLObserver<T>::refresh() const {
ReadMostlySharedPtr<const T> ReadMostlyTLObserver<T>::refresh() const {
auto version = globalVersion_.load();
auto globalData = globalData_.lock();
*localSnapshot_ = LocalSnapshot(*globalData, version);
......@@ -229,7 +227,7 @@ inline CallbackHandle::CallbackHandle() {}
template <typename T>
CallbackHandle::CallbackHandle(
Observer<T> observer, folly::Function<void(Snapshot<T>)> callback) {
Observer<T> observer, Function<void(Snapshot<T>)> callback) {
context_ = std::make_shared<Context>();
context_->observer = makeObserver([observer = std::move(observer),
callback = std::move(callback),
......@@ -265,7 +263,7 @@ inline void CallbackHandle::cancel() {
template <typename T>
CallbackHandle Observer<T>::addCallback(
folly::Function<void(Snapshot<T>)> callback) const {
Function<void(Snapshot<T>)> callback) const {
return CallbackHandle(*this, std::move(callback));
}
......
......@@ -208,8 +208,7 @@ class CallbackHandle {
public:
CallbackHandle();
template <typename T>
CallbackHandle(
Observer<T> observer, folly::Function<void(Snapshot<T>)> callback);
CallbackHandle(Observer<T> observer, Function<void(Snapshot<T>)> callback);
CallbackHandle(const CallbackHandle&) = delete;
CallbackHandle(CallbackHandle&&) = default;
CallbackHandle& operator=(const CallbackHandle&) = delete;
......@@ -249,7 +248,7 @@ class Observer {
return version < core_->getVersionLastChange();
}
CallbackHandle addCallback(folly::Function<void(Snapshot<T>)> callback) const;
CallbackHandle addCallback(Function<void(Snapshot<T>)> callback) const;
private:
template <typename Observable, typename Traits>
......@@ -330,14 +329,12 @@ class AtomicObserver {
T get() const;
T operator*() const { return get(); }
folly::observer::Observer<T> getUnderlyingObserver() const {
return observer_;
}
Observer<T> getUnderlyingObserver() const { return observer_; }
private:
mutable std::atomic<T> cachedValue_{};
mutable std::atomic<size_t> cachedVersion_{};
mutable folly::SharedMutex refreshLock_;
mutable SharedMutex refreshLock_;
Observer<T> observer_;
};
......@@ -350,13 +347,11 @@ class TLObserver {
const Snapshot<T>& getSnapshotRef() const;
const Snapshot<T>& operator*() const { return getSnapshotRef(); }
folly::observer::Observer<T> getUnderlyingObserver() const {
return observer_;
}
Observer<T> getUnderlyingObserver() const { return observer_; }
private:
Observer<T> observer_;
folly::ThreadLocal<Snapshot<T>> snapshot_;
ThreadLocal<Snapshot<T>> snapshot_;
};
template <typename T>
......@@ -370,9 +365,7 @@ class ReadMostlyAtomicObserver {
T get() const;
T operator*() const { return get(); }
folly::observer::Observer<T> getUnderlyingObserver() const {
return observer_;
}
Observer<T> getUnderlyingObserver() const { return observer_; }
private:
Observer<T> observer_;
......@@ -386,32 +379,28 @@ class ReadMostlyTLObserver {
explicit ReadMostlyTLObserver(Observer<T> observer);
ReadMostlyTLObserver(const ReadMostlyTLObserver<T>& other);
folly::ReadMostlySharedPtr<const T> getShared() const;
ReadMostlySharedPtr<const T> getShared() const;
folly::observer::Observer<T> getUnderlyingObserver() const {
return observer_;
}
Observer<T> getUnderlyingObserver() const { return observer_; }
private:
folly::ReadMostlySharedPtr<const T> refresh() const;
ReadMostlySharedPtr<const T> refresh() const;
struct LocalSnapshot {
LocalSnapshot() {}
LocalSnapshot(
const folly::ReadMostlyMainPtr<const T>& data, int64_t version)
LocalSnapshot(const ReadMostlyMainPtr<const T>& data, int64_t version)
: data_(data), version_(version) {}
folly::ReadMostlyWeakPtr<const T> data_;
ReadMostlyWeakPtr<const T> data_;
int64_t version_;
};
Observer<T> observer_;
folly::Synchronized<folly::ReadMostlyMainPtr<const T>, std::mutex>
globalData_;
Synchronized<ReadMostlyMainPtr<const T>, std::mutex> globalData_;
std::atomic<int64_t> globalVersion_;
folly::ThreadLocal<LocalSnapshot> localSnapshot_;
ThreadLocal<LocalSnapshot> localSnapshot_;
// Construct callback last so that it's joined before members it may
// be accessing are destructed
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment