trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ok...@apache.org
Subject [trafficserver] branch master updated: Optimize: Add startCop & stopCop for InactivityCop
Date Fri, 15 Sep 2017 02:08:44 GMT
This is an automated email from the ASF dual-hosted git repository.

oknet 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 5b7aabc  Optimize: Add startCop & stopCop for InactivityCop
5b7aabc is described below

commit 5b7aabccaec0de5d603b9b12e68a9d37ae208baf
Author: Oknet Xu <xuchao@skyguard.com.cn>
AuthorDate: Tue Sep 12 15:37:33 2017 +0800

    Optimize: Add startCop & stopCop for InactivityCop
    
    startCop: put a netvc into open_list. All NetVCs in the open_list is
    checked for timeout by InactivityCop.
    
    stopCop: remove the netvc from open_list and cop_list. Also remove the
    netvc from keep_alive_queue and active_queue if its context is IN.
---
 iocore/net/P_UnixNet.h           | 46 ++++++++++++++++++++++++++++++++++++++--
 iocore/net/UnixNetVConnection.cc | 16 ++++++--------
 2 files changed, 50 insertions(+), 12 deletions(-)

diff --git a/iocore/net/P_UnixNet.h b/iocore/net/P_UnixNet.h
index a2200ea..ce76c45 100644
--- a/iocore/net/P_UnixNet.h
+++ b/iocore/net/P_UnixNet.h
@@ -212,18 +212,38 @@ public:
     Only be called when holding the mutex of this NetHandler.
 
     @param netvc UnixNetVConnection to be managed by this NetHandler.
-    @return 0 on success, -ERRNO on failure.
+    @return 0 on success, netvc->nh set to this NetHandler.
+            -ERRNO on failure.
    */
   int startIO(UnixNetVConnection *netvc);
   /**
     Stop to handle read & write event on a UnixNetVConnection.
     Remove the socket fd of netvc from polling system.
-    Only be called when holding the mutex of this NetHandler.
+    Only be called when holding the mutex of this NetHandler and must call stopCop(netvc)
first.
 
     @param netvc UnixNetVConnection to be released.
+    @return netvc->nh set to nullptr.
    */
   void stopIO(UnixNetVConnection *netvc);
 
+  /**
+    Start to handle active timeout and inactivity timeout on a UnixNetVConnection.
+    Put the netvc into open_list. All NetVCs in the open_list is checked for timeout by InactivityCop.
+    Only be called when holding the mutex of this NetHandler and must call startIO(netvc)
first.
+
+    @param netvc UnixNetVConnection to be managed by InactivityCop
+   */
+  void startCop(UnixNetVConnection *netvc);
+  /* *
+    Stop to handle active timeout and inactivity on a UnixNetVConnection.
+    Remove the netvc from open_list and cop_list.
+    Also remove the netvc from keep_alive_queue and active_queue if its context is IN.
+    Only be called when holding the mutex of this NetHandler.
+
+    @param netvc UnixNetVConnection to be released.
+   */
+  void stopCop(UnixNetVConnection *netvc);
+
   NetHandler();
 
 private:
@@ -701,4 +721,26 @@ NetHandler::stopIO(UnixNetVConnection *netvc)
 
   netvc->nh = nullptr;
 }
+
+TS_INLINE void
+NetHandler::startCop(UnixNetVConnection *netvc)
+{
+  ink_assert(this->mutex->thread_holding == this_ethread());
+  ink_release_assert(netvc->nh == this);
+  ink_assert(!open_list.in(netvc));
+
+  open_list.enqueue(netvc);
+}
+
+TS_INLINE void
+NetHandler::stopCop(UnixNetVConnection *netvc)
+{
+  ink_release_assert(netvc->nh == this);
+
+  open_list.remove(netvc);
+  cop_list.remove(netvc);
+  remove_from_keep_alive_queue(netvc);
+  remove_from_active_queue(netvc);
+}
+
 #endif
diff --git a/iocore/net/UnixNetVConnection.cc b/iocore/net/UnixNetVConnection.cc
index a47ee31..63d5ba0 100644
--- a/iocore/net/UnixNetVConnection.cc
+++ b/iocore/net/UnixNetVConnection.cc
@@ -95,10 +95,7 @@ close_UnixNetVConnection(UnixNetVConnection *vc, EThread *t)
 
   if (nh) {
     // 2. Release vc from InactivityCop.
-    nh->open_list.remove(vc);
-    nh->cop_list.remove(vc);
-    vc->remove_from_keep_alive_queue();
-    vc->remove_from_active_queue();
+    nh->stopCop(vc);
     // 3. Release vc from NetHandler.
     nh->stopIO(vc);
   }
@@ -1142,8 +1139,8 @@ UnixNetVConnection::acceptEvent(int event, Event *e)
   // Setup a timeout callback handler.
   SET_HANDLER((NetVConnHandler)&UnixNetVConnection::mainEvent);
 
-  // All NetVCs in the open_list is checked for timeout by InactivityCop.
-  nh->open_list.enqueue(this);
+  // Send this netvc to InactivityCop.
+  nh->startCop(this);
 
   if (inactivity_timeout_in) {
     UnixNetVConnection::set_inactivity_timeout(inactivity_timeout_in);
@@ -1253,8 +1250,7 @@ UnixNetVConnection::populate(Connection &con_in, Continuation *c,
void *arg)
 
   ink_assert(this->nh != nullptr);
   SET_HANDLER(&UnixNetVConnection::mainEvent);
-  ink_assert(!nh->open_list.in(this));
-  this->nh->open_list.enqueue(this);
+  this->nh->startCop(this);
   ink_assert(this->con.fd != NO_FD);
   return EVENT_DONE;
 }
@@ -1335,8 +1331,8 @@ UnixNetVConnection::connectUp(EThread *t, int fd)
 
   // Setup a timeout callback handler.
   SET_HANDLER(&UnixNetVConnection::mainEvent);
-  // All NetVCs in the open_list is checked for timeout by InactivityCop.
-  nh->open_list.enqueue(this);
+  // Send this netvc to InactivityCop.
+  nh->startCop(this);
 
   set_inactivity_timeout(0);
   ink_assert(!active_timeout_in);

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>'].

Mime
View raw message