-
Notifications
You must be signed in to change notification settings - Fork 5.5k
runtime: making runtime accessible from non-worker threads #7695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alyssawilk
merged 5 commits into
envoyproxy:master
from
alyssawilk:runtime_other_threads
Jul 25, 2019
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
077a9ce
runtime: making runtime accessible from non-worker threads
alyssawilk c046080
format
alyssawilk 48fe419
Merge branch 'master' into runtime_other_threads
alyssawilk 233ce92
Changing to shared pointer model
alyssawilk c95c531
const + cast
alyssawilk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,8 @@ namespace Runtime { | |
| bool runtimeFeatureEnabled(absl::string_view feature) { | ||
| ASSERT(absl::StartsWith(feature, "envoy.reloadable_features")); | ||
| if (Runtime::LoaderSingleton::getExisting()) { | ||
| return Runtime::LoaderSingleton::getExisting()->snapshot().runtimeFeatureEnabled(feature); | ||
| return Runtime::LoaderSingleton::getExisting()->threadsafeSnapshot()->runtimeFeatureEnabled( | ||
| feature); | ||
| } | ||
| ENVOY_LOG_TO_LOGGER(Envoy::Logger::Registry::getLog(Envoy::Logger::Id::runtime), warn, | ||
| "Unable to use runtime singleton for feature {}", feature); | ||
|
|
@@ -552,12 +553,29 @@ void RtdsSubscription::validateUpdateSize(uint32_t num_resources) { | |
|
|
||
| void LoaderImpl::loadNewSnapshot() { | ||
| ThreadLocal::ThreadLocalObjectSharedPtr ptr = createNewSnapshot(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: just use a local var of snapshot shared pointer type, and you can void the dynamic cast below. |
||
| tls_->set([ptr = std::move(ptr)](Event::Dispatcher&) -> ThreadLocal::ThreadLocalObjectSharedPtr { | ||
| return ptr; | ||
| }); | ||
| tls_->set([ptr](Event::Dispatcher&) -> ThreadLocal::ThreadLocalObjectSharedPtr { return ptr; }); | ||
|
|
||
| { | ||
| absl::MutexLock lock(&snapshot_mutex_); | ||
| thread_safe_snapshot_ = std::dynamic_pointer_cast<Snapshot>(ptr); | ||
| } | ||
| } | ||
|
|
||
| const Snapshot& LoaderImpl::snapshot() { | ||
| ASSERT(tls_->currentThreadRegistered(), "snapshot can only be called from a worker thread"); | ||
| return tls_->getTyped<Snapshot>(); | ||
| } | ||
|
|
||
| const Snapshot& LoaderImpl::snapshot() { return tls_->getTyped<Snapshot>(); } | ||
| const std::shared_ptr<Snapshot> LoaderImpl::threadsafeSnapshot() { | ||
| if (tls_->currentThreadRegistered()) { | ||
| return std::dynamic_pointer_cast<Snapshot>(tls_->get()); | ||
| } | ||
|
|
||
| { | ||
| absl::ReaderMutexLock lock(&snapshot_mutex_); | ||
| return thread_safe_snapshot_; | ||
| } | ||
| } | ||
|
|
||
| void LoaderImpl::mergeValues(const std::unordered_map<std::string, std::string>& values) { | ||
| if (admin_layer_ == nullptr) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want
std::shared_ptr<const Snapshot>?