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


##########
iocore/eventsystem/UnixEThread.cc:
##########
@@ -384,9 +384,17 @@ EThread::summarize_stats(EventMetrics 
summary[N_EVENT_TIMESCALES])
   // not N_EVENT_TIMESCALES times.
   EventMetrics sum;
 
+  // The current metric block is null until the thread enters its event loop.
+  // The stat sync can run before then during startup, so such a thread has no
+  // loop samples to report.
+  EventMetrics volatile *current = current_metric;
+  if (current == nullptr) {
+    return;
+  }

Review Comment:
   The `volatile` is only there to match the type of the member. 
`current_metric` is declared as `volatile EventMetrics *` (a pointer to 
volatile `EventMetrics`; the pointer itself is not volatile), so copying it 
into a plain `EventMetrics *` would drop the qualifier and not compile without 
a cast. `prev()` already takes `EventMetrics volatile *` and casts the 
qualifier away itself, so the local just keeps the existing type.
   
   It adds no ordering or atomicity. The local exists so the null check and 
`prev()` use the same snapshot of the pointer instead of reading the member 
twice. That cross-thread read is the same unsynchronized read the code already 
did before this change; on master the member is `std::atomic<Slice *>` and is 
loaded with acquire.



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