Core stores the current version of the object held by Observer. It also keeps all dependencies and dependents of the Observer.
Definition at line 38 of file Core.h.
size_t folly::observer_detail::Core::refresh |
( |
size_t |
version, |
|
|
bool |
force = false |
|
) |
| |
Check if the observed object needs to be re-computed. Returns the version of last change. If force is true, re-computes the observed object, even if dependencies didn't change.
This should be only called from ObserverManager thread.
Definition at line 44 of file Core.cpp.
References folly::Synchronized< T, Mutex >::copy(), creator_, data_, dependencies_, dependents_, folly::exceptionStr(), folly::observer_detail::ObserverManager::inManagerThread(), folly::observer_detail::ObserverManager::DependencyRecorder::markRefreshDependency(), folly::gen::move, refreshMutex_, folly::observer_detail::ObserverManager::DependencyRecorder::release(), folly::observer_detail::ObserverManager::scheduleRefresh(), SCOPE_EXIT, folly::observer_detail::ObserverManager::DependencyRecorder::unmarkRefreshDependency(), version, version_, and versionLastChange_.
Referenced by getData(), and getVersionLastChange().
64 bool needRefresh = force ||
version_ == 0;
66 ObserverManager::DependencyRecorder dependencyRecorder(*
this);
71 for (
const auto& dependency : dependencies) {
78 LOG(ERROR) <<
"Exception while checking dependencies for updates: " 96 throw std::logic_error(
"Observer creator returned nullptr.");
103 LOG(ERROR) <<
"Exception while refreshing Observer: " 118 auto newDependencies = dependencyRecorder.release();
120 for (
const auto& dependency : newDependencies) {
121 if (!dependencies.count(dependency)) {
122 dependency->addDependent(this->shared_from_this());
126 for (
const auto& dependency : dependencies) {
127 if (!newDependencies.count(dependency)) {
128 dependency->removeStaleDependents();
132 dependencies =
std::move(newDependencies);
138 for (
const auto& dependentWeak : dependents) {
139 if (
auto dependent = dependentWeak.lock()) {
static bool inManagerThread()
fbstring exceptionStr(const std::exception &e)
constexpr detail::Map< Move > move
std::atomic< size_t > versionLastChange_
folly::Synchronized< Dependents > dependents_
static void markRefreshDependency(const Core &core)
folly::Synchronized< Dependencies > dependencies_
std::unordered_set< Ptr > Dependencies
folly::Function< std::shared_ptr< const void >)> creator_
folly::Synchronized< VersionedData > data_
static void unmarkRefreshDependency(const Core &core)
static void scheduleRefresh(Core::Ptr core, size_t minVersion, bool force=false)
std::atomic< size_t > version_
void copy(T *target) const