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

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


The following commit(s) were added to refs/heads/master by this push:
     new b4ae89ef8d Cleanup of Thread and EThread classes. (#10976)
b4ae89ef8d is described below

commit b4ae89ef8dadc7117ce300f17e527b69b1d4ba0e
Author: Walt Karas <wka...@yahooinc.com>
AuthorDate: Tue Jan 9 14:37:41 2024 -0500

    Cleanup of Thread and EThread classes. (#10976)
---
 include/iocore/eventsystem/EThread.h  |  3 +++
 include/iocore/eventsystem/Thread.h   |  2 +-
 src/iocore/eventsystem/Thread.cc      | 18 ++++--------------
 src/iocore/eventsystem/UnixEThread.cc | 20 ++++++++++++++++----
 4 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/include/iocore/eventsystem/EThread.h 
b/include/iocore/eventsystem/EThread.h
index ebcb520fc0..3a9dd2b9a3 100644
--- a/include/iocore/eventsystem/EThread.h
+++ b/include/iocore/eventsystem/EThread.h
@@ -549,6 +549,9 @@ public:
   };
 
   Metrics metrics;
+
+private:
+  void cons_common();
 };
 
 // --- Inline implementation
diff --git a/include/iocore/eventsystem/Thread.h 
b/include/iocore/eventsystem/Thread.h
index 31a446186b..372f6d6cb0 100644
--- a/include/iocore/eventsystem/Thread.h
+++ b/include/iocore/eventsystem/Thread.h
@@ -161,7 +161,7 @@ public:
 
   Thread(const Thread &)            = delete;
   Thread &operator=(const Thread &) = delete;
-  virtual ~Thread();
+  virtual ~Thread() {}
 
 protected:
   Thread();
diff --git a/src/iocore/eventsystem/Thread.cc b/src/iocore/eventsystem/Thread.cc
index 333d9cea71..959ec78c02 100644
--- a/src/iocore/eventsystem/Thread.cc
+++ b/src/iocore/eventsystem/Thread.cc
@@ -27,8 +27,11 @@
 
 **************************************************************************/
 
-#include "P_EventSystem.h"
+#include "iocore/eventsystem/Thread.h"
+#include "iocore/eventsystem/Lock.h"
 #include "tscore/ink_string.h"
+#include "tscore/ink_assert.h"
+#include "tscore/ink_memory.h"
 
 ///////////////////////////////////////////////
 // Common Interface impl                     //
@@ -39,19 +42,6 @@ thread_local Thread *Thread::this_thread_ptr;
 Thread::Thread()
 {
   mutex = new_ProxyMutex();
-  MUTEX_TAKE_LOCK(mutex, static_cast<EThread *>(this));
-  mutex->nthread_holding += THREAD_MUTEX_THREAD_HOLDING;
-}
-
-Thread::~Thread()
-{
-  ink_release_assert(mutex->thread_holding == static_cast<EThread *>(this));
-  if (this_thread_ptr == this) {
-    this_thread_ptr = nullptr;
-  }
-
-  mutex->nthread_holding -= THREAD_MUTEX_THREAD_HOLDING;
-  MUTEX_UNTAKE_LOCK(mutex, static_cast<EThread *>(this));
 }
 
 ///////////////////////////////////////////////
diff --git a/src/iocore/eventsystem/UnixEThread.cc 
b/src/iocore/eventsystem/UnixEThread.cc
index 97954b50b8..8b9b92ae47 100644
--- a/src/iocore/eventsystem/UnixEThread.cc
+++ b/src/iocore/eventsystem/UnixEThread.cc
@@ -71,14 +71,23 @@ EThread::set_specific()
   Thread::set_specific();
 }
 
-EThread::EThread()
+void
+EThread::cons_common()
 {
+  MUTEX_TAKE_LOCK(mutex, this);
+  mutex->nthread_holding += THREAD_MUTEX_THREAD_HOLDING;
+
   memset(thread_private, 0, PER_THREAD_DATA);
 }
 
+EThread::EThread()
+{
+  cons_common();
+}
+
 EThread::EThread(ThreadType att, int anid) : id(anid), tt(att)
 {
-  memset(thread_private, 0, PER_THREAD_DATA);
+  cons_common();
 #if HAVE_EVENTFD
   evfd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
   if (evfd < 0) {
@@ -103,17 +112,20 @@ EThread::EThread(ThreadType att, int anid) : id(anid), 
tt(att)
 EThread::EThread(ThreadType att, Event *e) : tt(att), start_event(e)
 {
   ink_assert(att == DEDICATED);
-  memset(thread_private, 0, PER_THREAD_DATA);
+  cons_common();
 }
 
 // Provide a destructor so that SDK functions which create and destroy
 // threads won't have to deal with EThread memory deallocation.
 EThread::~EThread()
 {
-  ink_release_assert(mutex->thread_holding == static_cast<EThread *>(this));
+  ink_release_assert(mutex->thread_holding == this);
   if (this_ethread_ptr == this) {
     this_ethread_ptr = nullptr;
   }
+
+  mutex->nthread_holding -= THREAD_MUTEX_THREAD_HOLDING;
+  MUTEX_UNTAKE_LOCK(mutex, this);
 }
 
 bool

Reply via email to