bneradt commented on code in PR #13807:
URL: https://github.com/apache/trafficserver/pull/13807#discussion_r4482913853


##########
plugins/experimental/jax_fingerprint/config.h:
##########
@@ -52,21 +57,87 @@ struct StringHash {
   }
 };
 
+/** Settings that can be changed by reloading the configuration file at 
runtime. */
+struct RuntimeSettings {
+  Mode                                                         mode            
= Mode::OVERWRITE;
+  std::string                                                  header_name     
= "";
+  std::string                                                  via_header_name 
= "";
+  std::unordered_set<std::string, StringHash, std::equal_to<>> servernames;
+};
+
 struct PluginConfig {
   PluginConfig() { Dbg(dbg_ctl, "New config (%p) has been created", this); }
   ~PluginConfig() { Dbg(dbg_ctl, "Config for (%p) has been deleted", this); }
 
-  PluginType    plugin_type     = PluginType::GLOBAL;
-  Mode          mode            = Mode::OVERWRITE;
-  struct Method method          = {"uninitialized", 
Method::Type::CONNECTION_BASED, nullptr, nullptr};
-  std::string   header_name     = "";
-  std::string   via_header_name = "";
-  std::string   log_filename    = "";
-  std::string   log_symbol      = "";
-  std::string   export_name     = "";
-  int           user_arg_index  = -1;
-  TSCont        handler         = nullptr; // For remap plugin
-  bool          standalone      = false;
-  std::unordered_set<std::string, StringHash, std::equal_to<>> servernames;
-  TSTextLogObject                                              log_handle = 
nullptr;
+  PluginType      plugin_type    = PluginType::GLOBAL;
+  struct Method   method         = {"uninitialized", 
Method::Type::CONNECTION_BASED, nullptr, nullptr};
+  std::string     log_filename   = "";
+  std::string     log_symbol     = "";
+  std::string     export_name    = "";
+  int             user_arg_index = -1;
+  TSCont          handler        = nullptr; // For remap plugin
+  bool            standalone     = false;
+  TSTextLogObject log_handle     = nullptr;
+
+  /** Get a snapshot of the runtime settings that stays valid while it is 
held. */
+  std::shared_ptr<RuntimeSettings const>
+  get_settings() const
+  {
+    std::shared_lock lock(_settings_mutex);
+    return _settings;
+  }
+
+  void
+  set_settings(std::shared_ptr<RuntimeSettings const> settings)
+  {
+    std::unique_lock lock(_settings_mutex);
+    _settings = std::move(settings);
+  }
+
+private:
+  mutable std::shared_mutex              _settings_mutex;
+  std::shared_ptr<RuntimeSettings const> _settings = 
std::make_shared<RuntimeSettings const>();

Review Comment:
   I'm keeping the `shared_mutex`. Readers take only the shared lock, and since 
reloads are rare it is essentially never contended, so the per-request cost is 
one uncontended atomic operation. `std::atomic<std::shared_ptr>` is not 
available in every standard library CI builds with (libc++ lacks it), and the 
`std::atomic_load`/`std::atomic_store` free functions are deprecated in C++20, 
so either option would need a fallback for no measurable gain.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to