You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by wk...@apache.org on 2023/12/12 17:16:49 UTC

(trafficserver) branch ETVolatile created (now 974daa7cc1)

This is an automated email from the ASF dual-hosted git repository.

wkaras pushed a change to branch ETVolatile
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


      at 974daa7cc1 Change volatile to atomic in EThread.h.

This branch includes the following new commits:

     new 974daa7cc1 Change volatile to atomic in EThread.h.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(trafficserver) 01/01: Change volatile to atomic in EThread.h.

Posted by wk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

wkaras pushed a commit to branch ETVolatile
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 974daa7cc1e6eee66b4bd55b98c775ea9d1a064c
Author: Walt Karas <wk...@yahooinc.com>
AuthorDate: Tue Dec 12 17:15:53 2023 +0000

    Change volatile to atomic in EThread.h.
---
 include/iocore/eventsystem/EThread.h  | 6 ++++--
 src/iocore/eventsystem/UnixEThread.cc | 8 ++++----
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/include/iocore/eventsystem/EThread.h b/include/iocore/eventsystem/EThread.h
index 8f7e069773..f0641a50e8 100644
--- a/include/iocore/eventsystem/EThread.h
+++ b/include/iocore/eventsystem/EThread.h
@@ -24,6 +24,8 @@
 
 #pragma once
 
+#include <atomic>
+
 #include "tscore/ink_platform.h"
 #include "tscore/ink_rand.h"
 #include "tscore/Version.h"
@@ -479,7 +481,7 @@ public:
     /// The slices.
     std::array<Slice, N_SLICES> _slice;
 
-    Slice *volatile current_slice = nullptr; ///< The current slice.
+    std::atomic<Slice *> current_slice{nullptr}; ///< The current slice.
 
     /** The number of time scales used in the event statistics.
         Currently these are 10s, 100s, 1000s.
@@ -599,7 +601,7 @@ inline auto
 EThread::Metrics::record_loop_time(ink_hrtime delta) -> self_type &
 {
   static auto constexpr DIVISOR = std::chrono::duration_cast<ts_nanoseconds>(LOOP_HISTOGRAM_BUCKET_SIZE).count();
-  current_slice->record_loop_duration(delta);
+  (*current_slice).record_loop_duration(delta);
   _loop_timing(delta / DIVISOR);
   return *this;
 }
diff --git a/src/iocore/eventsystem/UnixEThread.cc b/src/iocore/eventsystem/UnixEThread.cc
index 492b442cfe..0566a1c598 100644
--- a/src/iocore/eventsystem/UnixEThread.cc
+++ b/src/iocore/eventsystem/UnixEThread.cc
@@ -234,9 +234,9 @@ EThread::execute_regular()
         // Need @c const_cast to cast away @c volatile
         memcpy(prev_slice = this->metrics.next_slice(prev_slice), &SLICE_INIT, sizeof(SLICE_INIT));
       } while (metrics.current_slice != prev_slice);
-      metrics.current_slice->record_loop_start(loop_start_time);
+      (*metrics.current_slice).record_loop_start(loop_start_time);
     }
-    ++(metrics.current_slice->_count); // loop started, bump count.
+    ++((*metrics.current_slice)._count); // loop started, bump count.
 
     process_queue(&NegativeQueue, &ev_count, &nq_count);
 
@@ -277,7 +277,7 @@ EThread::execute_regular()
         // Therefore, we have to set the limitation of sleep time in order to handle the next retry in time.
         sleep_time = std::min(sleep_time, DELAY_FOR_RETRY);
       }
-      ++(metrics.current_slice->_wait);
+      ++((*metrics.current_slice)._wait);
     } else {
       sleep_time = 0;
     }
@@ -293,7 +293,7 @@ EThread::execute_regular()
 
     metrics.decay();
     metrics.record_loop_time(delta);
-    metrics.current_slice->record_event_count(ev_count);
+    (*metrics.current_slice).record_event_count(ev_count);
   }
 }