Skip to content

Commit

Permalink
improve the comment per htuch's suggestion.
Browse files Browse the repository at this point in the history
Signed-off-by: Xin Zhuang <stevenzzz@google.com>
  • Loading branch information
stevenzzzz committed Jul 31, 2019
1 parent 1bd43be commit f074e9d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions source/common/config/config_provider_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,21 @@ class ConfigSubscriptionCommonBase
using ConfigUpdateCb =
std::function<ConfigProvider::ConfigConstSharedPtr(ConfigProvider::ConfigConstSharedPtr)>;
void applyConfigUpdate(
const ConfigUpdateFn& update_fn, const Event::PostCb& complete_cb = []() {}) {
const ConfigUpdateCb& update_fn, const Event::PostCb& complete_cb = []() {}) {
// It is safe to call shared_from_this here as this is in main thread, and destruction of a
// ConfigSubscriptionCommonBase owner (i.e., a provider) happens in main thread as well.
auto shared_this = shared_from_this();
tls_->runOnAllThreads(
[this, update_fn]() {
tls_->getTyped<ThreadLocalConfig>().config_ = update_fn(this->getConfig());
},
/*During the update propagation, a subscription may get teared down in main thread due to
/* During the update propagation, a subscription may get teared down in main thread due to
all owners/providers destructed in a xDS update (e.g. LDS demolishes a RouteConfigProvider
and its subscription). Hold a reference to the shared subscription instance to make sure the
update can be safely pushed to workers in such an event.*/
and its subscription).
If such a race condition happens, hold a reference to the "*this" subscription instance in
this cb will ensure the shared "*this" gets posted back to main thread, after all the
workers finish calling the update_fn, at which point it's safe to destruct "*this"
instance. */
[shared_this, complete_cb]() { complete_cb(); });
}

Expand Down

0 comments on commit f074e9d

Please sign in to comment.