You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2022/12/21 19:09:33 UTC

[trafficserver] branch 10-Dev updated: RefCountObj - further improvements wrt copy construction. (#9235)

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

amc pushed a commit to branch 10-Dev
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/10-Dev by this push:
     new f77fd958e RefCountObj - further improvements wrt copy construction. (#9235)
f77fd958e is described below

commit f77fd958e79b54cf6a0c13168660d708762b5ad5
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Wed Dec 21 13:09:24 2022 -0600

    RefCountObj - further improvements wrt copy construction. (#9235)
---
 include/tscore/Ptr.h                              | 24 +++++++----------------
 iocore/eventsystem/P_UnixEThread.h                |  1 +
 iocore/eventsystem/unit_tests/test_EventSystem.cc |  1 +
 iocore/net/P_UDPConnection.h                      |  1 +
 plugins/experimental/memcache/tsmemcache.cc       |  1 +
 proxy/logging/LogBuffer.h                         |  1 +
 proxy/logging/LogFile.cc                          | 21 --------------------
 proxy/logging/LogFile.h                           |  2 +-
 proxy/logging/LogFormat.cc                        |  2 +-
 9 files changed, 14 insertions(+), 40 deletions(-)

diff --git a/include/tscore/Ptr.h b/include/tscore/Ptr.h
index 0f221c831..27a0221db 100644
--- a/include/tscore/Ptr.h
+++ b/include/tscore/Ptr.h
@@ -23,8 +23,7 @@
 
 #pragma once
 
-#include "tscore/ink_atomic.h"
-
+#include <atomic>
 #include <cstddef>
 
 ////////////////////////////////////////////////////////////////////
@@ -47,32 +46,23 @@ class RefCountObj : public ForceVFPTToTop
 {
 public:
   RefCountObj() {}
-  RefCountObj(const RefCountObj &s)
-  {
-    (void)s;
-    return;
-  }
-
+  RefCountObj(const RefCountObj &) = delete;
   ~RefCountObj() override {}
-  RefCountObj &
-  operator=(const RefCountObj &s)
-  {
-    (void)s;
-    return (*this);
-  }
+
+  RefCountObj &operator=(const RefCountObj &) = delete;
 
   // Increment the reference count, returning the new count.
   int
   refcount_inc()
   {
-    return ink_atomic_increment((int *)&m_refcount, 1) + 1;
+    return ++m_refcount;
   }
 
   // Decrement the reference count, returning the new count.
   int
   refcount_dec()
   {
-    return ink_atomic_increment((int *)&m_refcount, -1) - 1;
+    return --m_refcount;
   }
 
   int
@@ -88,7 +78,7 @@ public:
   }
 
 private:
-  int m_refcount = 0;
+  std::atomic<int> m_refcount = 0;
 };
 
 ////////////////////////////////////////////////////////////////////////
diff --git a/iocore/eventsystem/P_UnixEThread.h b/iocore/eventsystem/P_UnixEThread.h
index 21ca05240..b1824630c 100644
--- a/iocore/eventsystem/P_UnixEThread.h
+++ b/iocore/eventsystem/P_UnixEThread.h
@@ -32,6 +32,7 @@
 
 #include "I_EThread.h"
 #include "I_EventProcessor.h"
+#include "tscore/ink_atomic.h"
 #include <execinfo.h>
 
 const ink_hrtime DELAY_FOR_RETRY = HRTIME_MSECONDS(10);
diff --git a/iocore/eventsystem/unit_tests/test_EventSystem.cc b/iocore/eventsystem/unit_tests/test_EventSystem.cc
index 5de42b03c..776724fad 100644
--- a/iocore/eventsystem/unit_tests/test_EventSystem.cc
+++ b/iocore/eventsystem/unit_tests/test_EventSystem.cc
@@ -25,6 +25,7 @@
 #include "catch.hpp"
 
 #include "I_EventSystem.h"
+#include "tscore/ink_atomic.h"
 #include "tscore/I_Layout.h"
 #include "tscore/TSSystemState.h"
 
diff --git a/iocore/net/P_UDPConnection.h b/iocore/net/P_UDPConnection.h
index 10e57c2d9..95aedbcc8 100644
--- a/iocore/net/P_UDPConnection.h
+++ b/iocore/net/P_UDPConnection.h
@@ -30,6 +30,7 @@
  ****************************************************************************/
 #pragma once
 
+#include "tscore/ink_atomic.h"
 #include "I_UDPNet.h"
 
 class UDPConnectionInternal : public UDPConnection
diff --git a/plugins/experimental/memcache/tsmemcache.cc b/plugins/experimental/memcache/tsmemcache.cc
index 9443c97cc..daabb181b 100644
--- a/plugins/experimental/memcache/tsmemcache.cc
+++ b/plugins/experimental/memcache/tsmemcache.cc
@@ -24,6 +24,7 @@
 #include "tsmemcache.h"
 #include "I_NetVConnection.h"
 #include "I_NetProcessor.h"
+#include "tscore/ink_atomic.h"
 
 /*
   TODO
diff --git a/proxy/logging/LogBuffer.h b/proxy/logging/LogBuffer.h
index dafccecc2..bd8d32fab 100644
--- a/proxy/logging/LogBuffer.h
+++ b/proxy/logging/LogBuffer.h
@@ -24,6 +24,7 @@
 #pragma once
 
 #include "tscore/ink_platform.h"
+#include "tscore/ink_atomic.h"
 #include "tscore/Diags.h"
 #include "LogFormat.h"
 #include "LogLimits.h"
diff --git a/proxy/logging/LogFile.cc b/proxy/logging/LogFile.cc
index 7327fac32..1f73033f9 100644
--- a/proxy/logging/LogFile.cc
+++ b/proxy/logging/LogFile.cc
@@ -93,27 +93,6 @@ LogFile::LogFile(const char *name, const char *header, LogFileFormat format, uin
   This (copy) constructor builds a LogFile object from another LogFile object.
   -------------------------------------------------------------------------*/
 
-LogFile::LogFile(const LogFile &copy)
-  : RefCountObj(copy),
-    m_file_format(copy.m_file_format),
-    m_name(ats_strdup(copy.m_name)),
-    m_header(ats_strdup(copy.m_header)),
-    m_signature(copy.m_signature),
-    m_ascii_buffer_size(copy.m_ascii_buffer_size),
-    m_max_line_size(copy.m_max_line_size),
-    m_pipe_buffer_size(copy.m_pipe_buffer_size),
-    m_fd(copy.m_fd)
-{
-  ink_release_assert(m_ascii_buffer_size >= m_max_line_size);
-
-  if (copy.m_log) {
-    m_log = new BaseLogFile(*(copy.m_log));
-  } else {
-    m_log = nullptr;
-  }
-
-  Debug("log-file", "exiting LogFile copy constructor, m_name=%s, this=%p", m_name, this);
-}
 /*-------------------------------------------------------------------------
   LogFile::~LogFile
   -------------------------------------------------------------------------*/
diff --git a/proxy/logging/LogFile.h b/proxy/logging/LogFile.h
index 2d603d5e1..f192da10a 100644
--- a/proxy/logging/LogFile.h
+++ b/proxy/logging/LogFile.h
@@ -44,7 +44,7 @@ class LogFile : public LogBufferSink, public RefCountObj
 public:
   LogFile(const char *name, const char *header, LogFileFormat format, uint64_t signature, size_t ascii_buffer_size = 4 * 9216,
           size_t max_line_size = 9216, int pipe_buffer_size = 0, LogEscapeType escape_type = LOG_ESCAPE_NONE);
-  LogFile(const LogFile &);
+  LogFile(const LogFile &) = delete;
   ~LogFile() override;
 
   enum {
diff --git a/proxy/logging/LogFormat.cc b/proxy/logging/LogFormat.cc
index c3e8f8142..4d6263053 100644
--- a/proxy/logging/LogFormat.cc
+++ b/proxy/logging/LogFormat.cc
@@ -206,7 +206,7 @@ LogFormat::LogFormat(const char *name, const char *format_str, unsigned interval
   -------------------------------------------------------------------------*/
 
 LogFormat::LogFormat(const LogFormat &rhs)
-  : RefCountObj(rhs),
+  : RefCountObj(),
     m_interval_sec(0),
     m_interval_next(0),
     m_agg_marshal_space(nullptr),