cmcfarlen commented on code in PR #14005:
URL: https://github.com/apache/trafficserver/pull/14005#discussion_r4516785654


##########
src/iocore/eventsystem/ConfigProcessor.cc:
##########
@@ -216,6 +229,100 @@ ConfigProcessor::release(unsigned int id, ConfigInfo 
*info)
   }
 }
 
+struct ConfigProcessor::ThreadPins {
+  struct Pin {
+    uint64_t                    generation = 0;
+    std::shared_ptr<ConfigInfo> config;
+    bool                        listed = false;
+  };
+
+  std::array<Pin, MAX_CONFIGS> pins;
+  // Slots this thread has pinned at some point, so the per-loop sweep skips 
the rest.
+  static_assert(MAX_CONFIGS <= 256, "slot indices in used are stored as 
uint8_t");
+  std::array<uint8_t, MAX_CONFIGS> used{};
+  size_t                           used_count = 0;
+};
+
+std::shared_ptr<ConfigInfo> &
+ConfigProcessor::_pin(unsigned int id)
+{
+  unsigned int const idx        = id - 1;
+  auto              &pin        = _thread_pins->pins[idx];
+  uint64_t const     generation = 
_generations[idx].value.load(std::memory_order_acquire);
+
+  if (!pin.config || pin.generation != generation) {
+    if (!pin.listed) {
+      pin.listed                                     = true;
+      _thread_pins->used[_thread_pins->used_count++] = 
static_cast<uint8_t>(idx);
+    }
+    // A scope in the current event may still use the replaced configuration, 
but set() keeps its own
+    // reference for the release timeout, so dropping the pin here cannot free 
it.
+    pin.config.reset();

Review Comment:
   Good catch, fixed in a43d3aad01. A refreshed pin is now parked in a 
per-thread `displaced` list that `release_stale_pins()` clears between events, 
so a `get_pinned()` result stays valid for the whole event whether or not 
`set()`'s delayed reference has expired. Added a test that refreshes a slot 
after the processor's delayed reference is gone; it fails without the fix.



-- 
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