23 namespace observer_detail {
64 bool needRefresh = force ||
version_ == 0;
71 for (
const auto& dependency : dependencies) {
73 if (dependency->refresh(version) >
version_) {
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()) {
152 for (
const auto& dependecy : dependencies) {
153 dependecy->removeStaleDependents();
165 dependents.push_back(
std::move(dependent));
172 for (
size_t i = 0;
i < dependents.size(); ++
i) {
173 if (dependents[
i].expired()) {
175 dependents.pop_back();
Core(folly::Function< std::shared_ptr< const void >()> creator)
static bool inManagerThread()
fbstring exceptionStr(const std::exception &e)
constexpr detail::Map< Move > move
std::atomic< size_t > versionLastChange_
—— Concurrent Priority Queue Implementation ——
folly::Synchronized< Dependents > dependents_
static void markRefreshDependency(const Core &core)
folly::Synchronized< Dependencies > dependencies_
std::shared_ptr< Core > Ptr
std::unordered_set< Ptr > Dependencies
size_t refresh(size_t version, bool force=false)
static void markDependency(Core::Ptr dependency)
void addDependent(Core::WeakPtr dependent)
folly::Function< std::shared_ptr< const void >)> creator_
folly::Synchronized< VersionedData > data_
std::weak_ptr< Core > WeakPtr
std::vector< WeakPtr > Dependents
static void unmarkRefreshDependency(const Core &core)
static size_t getVersion()
void swap(SwapTrackingAlloc< T > &, SwapTrackingAlloc< T > &)
static void scheduleRefresh(Core::Ptr core, size_t minVersion, bool force=false)
std::atomic< size_t > version_
void removeStaleDependents()
static Ptr create(folly::Function< std::shared_ptr< const void >()> creator)
void copy(T *target) const