You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2016/05/11 20:31:24 UTC

[trafficserver] branch master updated (a6e8332 -> 64b4092)

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

jpeach pushed a change to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git.

      from  a6e8332   TS-4433: Handle TSVConnFdCreate failure in the intercept example.
       new  090a068   TS-4425: Make the RefCountObj refcount private.
       new  c1b2b98   TS-4425: Bring RefCountObj methods inline for readability.
       new  0660bc5   TS-4425: Remove unused Ptr::to_ptr() method.
       new  464d5be   TS-4425: Rename Ptr::_ptr() to Ptr::get().
       new  369ab4c   TS-4425: Add Ptr::detach() to detach a RefCountObj from its holder.
       new  5389f26   TS-4425: Add unsafe Ptr::swizzle().
       new  2a47b9f   TS-4425: Add tests for Ptr<T>.
       new  8531f6a   TS-4425: Add Ptr<ProxyMutex> overloads for Mutex APIs.
       new  4e9d4e3   TS-4425: Add Ptr<ProxyMutex> Continuation constructor.
       new  f474472   TS-4425: Remove unused Mutex pointers from the threads system.
       new  e3ddc16   TS-4425: Switch Cache.cc over to Ptr::get().
       new  3001e09   TS-4425: Switch CacheDir.cc over to Ptr::get().
       new  708a284   TS-4445: Switch CacheRead.cc over to Ptr::get().
       new  a41002e   TS-4425: Switch CacheTest.cc over to Ptr::get().
       new  9085913   TS-4425: Switch P_CacheInternal.h over to Ptr::get().
       new  6fd403f   TS-4425: Stop using private Ptr::m_ptr in EThread.
       new  d700ba7   TS-4425: Switch P_UnixEthread.h over to Ptr::get().
       new  15ed828   TS-4425: Pass Ptr<ProxyMutex> down through the Continuation constructor.
       new  1a178af   TS-4425: Switch SSLNetVConnection over to Ptr::get().
       new  0e73f84   TS-4425: Use Ptr<ProxyMutex> in session acceptors.
       new  cf53450   TS-4425: Switch IOBuffers over to Ptr::get().
       new  5841b5c   TS-4425: Switch RamCacheCLFUS over to Ptr::get().
       new  5df323e   TS-4425: Switch CacheWrite.cc over to Ptr::get().
       new  d5b79b2   TS-4425: Switch iocore/net over to Ptr::get().
       new  6ee02bf   TS-4425: Switch DNS.cc over to Ptr::get().
       new  32f84f1   TS-4425: Switch iocore/cluster over to Ptr::get().
       new  23cb70f   TS-4425: Switch iocore/hostdb and iocore/utils to Ptr::get().
       new  8faceca   TS-4425: Switch proxy/logging over to Ptr::get().
       new  e61ea1b   TS-4425: Switch proxy/hdrs over to Ptr::get().
       new  a95fdf3   TS-4425: Switch the remainder of proxy/ over to Ptr::get().
       new  2f45c41   TS-4425: Switch InkIOCoreAPI.cc over to Ptr::get().
       new  523fede   TS-4425: Hide Ptr internals.
       new  64b4092   TS-4425: Use Ptr<ProxyMutex> for the Thread mutex.

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


Summary of changes:
 iocore/cache/Cache.cc                    |   8 +-
 iocore/cache/CacheDir.cc                 |   6 +-
 iocore/cache/CacheRead.cc                |  17 ++--
 iocore/cache/CacheTest.cc                |   6 +-
 iocore/cache/CacheVol.cc                 |   2 +-
 iocore/cache/CacheWrite.cc               |  24 +++---
 iocore/cache/P_CacheInternal.h           |  20 +++--
 iocore/cache/RamCacheCLFUS.cc            |   4 +-
 iocore/cluster/ClusterCache.cc           |  18 ++---
 iocore/cluster/ClusterConfig.cc          |   5 +-
 iocore/cluster/ClusterHandler.cc         |  36 ++++-----
 iocore/cluster/ClusterHandlerBase.cc     |  10 +--
 iocore/cluster/ClusterLib.cc             |  16 ++--
 iocore/cluster/ClusterLoadMonitor.cc     |   2 +-
 iocore/cluster/ClusterMachine.cc         |   6 +-
 iocore/cluster/ClusterProcessor.cc       |   7 +-
 iocore/cluster/ClusterRPC.cc             |  10 +--
 iocore/cluster/ClusterVConnection.cc     |   2 +-
 iocore/cluster/P_ClusterCache.h          |   6 +-
 iocore/cluster/P_ClusterCacheInternal.h  |   8 +-
 iocore/cluster/P_ClusterHandler.h        |  18 +++--
 iocore/cluster/P_ClusterInternal.h       |  20 +++++
 iocore/dns/DNS.cc                        |  14 ++--
 iocore/eventsystem/IOBuffer.cc           |  26 +++---
 iocore/eventsystem/I_Continuation.h      |  12 +++
 iocore/eventsystem/I_IOBuffer.h          |  20 +++--
 iocore/eventsystem/I_Lock.h              | 109 ++++++++++++++++++++++---
 iocore/eventsystem/I_Thread.h            |  16 ++--
 iocore/eventsystem/I_VConnection.h       |   1 +
 iocore/eventsystem/P_IOBuffer.h          | 112 +++++++++++++++++---------
 iocore/eventsystem/P_UnixEThread.h       |   4 +-
 iocore/eventsystem/P_VConnection.h       |   6 ++
 iocore/eventsystem/Thread.cc             |   2 -
 iocore/eventsystem/UnixEThread.cc        |   2 +-
 iocore/eventsystem/UnixEventProcessor.cc |   1 -
 iocore/hostdb/HostDB.cc                  |  37 ++++-----
 iocore/hostdb/MultiCache.cc              |   4 +-
 iocore/hostdb/P_MultiCache.h             |   3 +-
 iocore/net/I_UDPPacket.h                 |   2 +-
 iocore/net/P_CompletionUtil.h            |   2 +-
 iocore/net/P_Socks.h                     |   2 +-
 iocore/net/P_UDPConnection.h             |   2 +-
 iocore/net/P_UDPIOEvent.h                |  23 ++++--
 iocore/net/P_UDPPacket.h                 |  18 +++--
 iocore/net/P_UnixCompletionUtil.h        |   2 +-
 iocore/net/P_UnixNet.h                   |   4 +-
 iocore/net/P_UnixNetVConnection.h        |   2 +-
 iocore/net/SSLNetVConnection.cc          |  48 +++++------
 iocore/net/SSLNextProtocolAccept.cc      |   6 +-
 iocore/net/Socks.cc                      |   2 +-
 iocore/net/UnixNet.cc                    |   9 ++-
 iocore/net/UnixNetAccept.cc              |  19 +++--
 iocore/net/UnixNetProcessor.cc           |  12 +--
 iocore/net/UnixNetVConnection.cc         |  68 +++++++++-------
 iocore/net/UnixUDPNet.cc                 |   9 +--
 iocore/utils/OneWayMultiTunnel.cc        |   4 +-
 iocore/utils/OneWayTunnel.cc             |   8 +-
 lib/ts/Makefile.am                       |   7 +-
 lib/ts/Ptr.h                             | 133 +++++++++++++++++++------------
 lib/ts/test_Ptr.cc                       | 106 ++++++++++++++++++++++++
 mgmt/ProxyConfig.h                       |   4 +-
 proxy/CacheControl.cc                    |   2 +-
 proxy/CoreUtils.cc                       |   4 +-
 proxy/CoreUtils.h                        |   2 +
 proxy/FetchSM.cc                         |  16 ++--
 proxy/ICP.cc                             |  22 ++---
 proxy/ICP.h                              |  10 +--
 proxy/ICPConfig.cc                       |   6 +-
 proxy/InkAPI.cc                          |  16 ++--
 proxy/InkAPIInternal.h                   |   4 +-
 proxy/InkIOCoreAPI.cc                    |  16 ++--
 proxy/PluginVC.cc                        |   4 +-
 proxy/ProtocolProbeSessionAccept.cc      |   2 +-
 proxy/ReverseProxy.cc                    |   2 +-
 proxy/SocksProxy.cc                      |   2 +-
 proxy/Transform.cc                       |   2 +-
 proxy/congest/MT_hashtable.h             |   3 +-
 proxy/hdrs/HdrHeap.cc                    |  53 ++++++------
 proxy/hdrs/HdrHeap.h                     |  44 +++++-----
 proxy/hdrs/HdrTSOnly.cc                  |   2 +-
 proxy/hdrs/HdrTest.cc                    |   5 +-
 proxy/http/HttpCacheSM.h                 |   2 +-
 proxy/http/HttpProxyServerMain.cc        |   5 +-
 proxy/http/HttpSM.cc                     |   8 +-
 proxy/http/HttpSessionManager.cc         |   4 +-
 proxy/http/HttpTunnel.cc                 |   2 +-
 proxy/http/HttpTunnel.h                  |   2 +-
 proxy/http2/Http2ClientSession.h         |   2 +-
 proxy/logging/Log.cc                     |  41 +++++-----
 proxy/logging/LogField.cc                |   4 +-
 proxy/logging/LogFile.cc                 |   4 +-
 proxy/logging/LogFilter.cc               |   2 +-
 proxy/logging/LogHost.cc                 |   6 +-
 proxy/logging/LogHost.h                  |   3 +-
 proxy/logging/LogObject.cc               |   2 +-
 proxy/logging/LogObject.h                |   2 +-
 96 files changed, 881 insertions(+), 537 deletions(-)
 create mode 100644 lib/ts/test_Ptr.cc

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

[trafficserver] 16/33: TS-4425: Stop using private Ptr::m_ptr in EThread.

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 6fd403fceefcaab34502d618117791e3d5d681f4
Author: James Peach <jp...@apache.org>
AuthorDate: Thu May 5 21:18:23 2016 -0700

    TS-4425: Stop using private Ptr::m_ptr in EThread.
---
 iocore/eventsystem/UnixEThread.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/iocore/eventsystem/UnixEThread.cc b/iocore/eventsystem/UnixEThread.cc
index e395787..115d133 100644
--- a/iocore/eventsystem/UnixEThread.cc
+++ b/iocore/eventsystem/UnixEThread.cc
@@ -135,7 +135,7 @@ void
 EThread::process_event(Event *e, int calling_code)
 {
   ink_assert((!e->in_the_prot_queue && !e->in_the_priority_queue));
-  MUTEX_TRY_LOCK_FOR(lock, e->mutex.m_ptr, this, e->continuation);
+  MUTEX_TRY_LOCK_FOR(lock, e->mutex, this, e->continuation);
   if (!lock.is_locked()) {
     e->timeout_at = cur_time + DELAY_FOR_RETRY;
     EventQueueExternal.enqueue_local(e);

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

[trafficserver] 04/33: TS-4425: Rename Ptr::_ptr() to Ptr::get().

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 464d5be166162b3db99ff4e05521766c9640a42f
Author: James Peach <jp...@apache.org>
AuthorDate: Wed May 4 22:30:37 2016 -0700

    TS-4425: Rename Ptr::_ptr() to Ptr::get().
    
    Ptr::get() is the conventional name to extract a raw pointer from
    a smart pointer. Also introduce Ptr::object() which type-erases the
    pointer to a RefCountObject*.
---
 iocore/cache/Cache.cc      |  2 +-
 iocore/cache/CacheRead.cc  |  2 +-
 iocore/cache/CacheVol.cc   |  2 +-
 iocore/cache/CacheWrite.cc |  2 +-
 lib/ts/Ptr.h               | 41 +++++++++++++++++++++++++----------------
 proxy/hdrs/HdrHeap.cc      |  2 +-
 6 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc
index 8d13438..cf4b569 100644
--- a/iocore/cache/Cache.cc
+++ b/iocore/cache/Cache.cc
@@ -2203,7 +2203,7 @@ unmarshal_helper(Doc *doc, Ptr<IOBufferData> &buf, int &okay)
   char *tmp = doc->hdr();
   int len = doc->hlen;
   while (len > 0) {
-    int r = HTTPInfo::unmarshal(tmp, len, buf._ptr());
+    int r = HTTPInfo::unmarshal(tmp, len, buf.get());
     if (r < 0) {
       ink_assert(!"CacheVC::handleReadDone unmarshal failed");
       okay = 0;
diff --git a/iocore/cache/CacheRead.cc b/iocore/cache/CacheRead.cc
index 3e98ba9..685426a 100644
--- a/iocore/cache/CacheRead.cc
+++ b/iocore/cache/CacheRead.cc
@@ -410,7 +410,7 @@ CacheVC::openReadFromWriter(int event, Event *e)
       // Update case (b) : grab doc_len from the writer's alternate
       doc_len = alternate.object_size_get();
       if (write_vc->update_key == cod->single_doc_key && (cod->move_resident_alt || write_vc->f.rewrite_resident_alt) &&
-          write_vc->first_buf._ptr()) {
+          write_vc->first_buf.get()) {
         // the resident alternate is being updated and its a
         // header only update. The first_buf of the writer has the
         // document body.
diff --git a/iocore/cache/CacheVol.cc b/iocore/cache/CacheVol.cc
index b308bfe..09b7b8e 100644
--- a/iocore/cache/CacheVol.cc
+++ b/iocore/cache/CacheVol.cc
@@ -239,7 +239,7 @@ CacheVC::scanObject(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */)
       char *tmp = doc->hdr();
       int len = doc->hlen;
       while (len > 0) {
-        int r = HTTPInfo::unmarshal(tmp, len, buf._ptr());
+        int r = HTTPInfo::unmarshal(tmp, len, buf.get());
         if (r < 0) {
           ink_assert(!"CacheVC::scanObject unmarshal failed");
           goto Lskip;
diff --git a/iocore/cache/CacheWrite.cc b/iocore/cache/CacheWrite.cc
index dfb927c..cd56a5b 100644
--- a/iocore/cache/CacheWrite.cc
+++ b/iocore/cache/CacheWrite.cc
@@ -106,7 +106,7 @@ CacheVC::updateVector(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */)
       alternate_index = write_vector->insert(&alternate, alternate_index);
     }
 
-    if (od->move_resident_alt && first_buf._ptr() && !od->has_multiple_writers()) {
+    if (od->move_resident_alt && first_buf.get() && !od->has_multiple_writers()) {
       Doc *doc = (Doc *)first_buf->data();
       int small_doc = (int64_t)doc->data_len() < (int64_t)cache_config_alt_rewrite_max_size;
       int have_res_alt = doc->key == od->single_doc_key;
diff --git a/lib/ts/Ptr.h b/lib/ts/Ptr.h
index dd87657..56fc4cb 100644
--- a/lib/ts/Ptr.h
+++ b/lib/ts/Ptr.h
@@ -136,10 +136,19 @@ public:
     return (m_ptr != p.m_ptr);
   }
 
+  // Return the raw pointer.
+  T *
+  get() const
+  {
+    return m_ptr;
+  }
+
+  // Return the raw pointer as a RefCount object. Typically
+  // this is for keeping a collection of heterogenous objects.
   RefCountObj *
-  _ptr()
+  object() const
   {
-    return (RefCountObj *)m_ptr;
+    return static_cast<RefCountObj *>(m_ptr);
   }
 
   T *m_ptr;
@@ -159,24 +168,23 @@ make_ptr(T *p)
 ////////////////////////////////////////////////////////////////////////
 template <class T> inline Ptr<T>::Ptr(T *ptr /* = 0 */) : m_ptr(ptr)
 {
-  if (m_ptr)
-    _ptr()->refcount_inc();
-  return;
+  if (m_ptr) {
+    m_ptr->refcount_inc();
+  }
 }
 
 template <class T> inline Ptr<T>::Ptr(const Ptr<T> &src) : m_ptr(src.m_ptr)
 {
-  if (m_ptr)
-    _ptr()->refcount_inc();
-  return;
+  if (m_ptr) {
+    m_ptr->refcount_inc();
+  }
 }
 
 template <class T> inline Ptr<T>::~Ptr()
 {
-  if ((m_ptr) && _ptr()->refcount_dec() == 0) {
-    _ptr()->free();
+  if (m_ptr && m_ptr->refcount_dec() == 0) {
+    m_ptr->free();
   }
-  return;
 }
 
 template <class T>
@@ -185,17 +193,18 @@ Ptr<T>::operator=(T *p)
 {
   T *temp_ptr = m_ptr;
 
-  if (m_ptr == p)
+  if (m_ptr == p) {
     return (*this);
+  }
 
   m_ptr = p;
 
-  if (m_ptr != 0) {
-    _ptr()->refcount_inc();
+  if (m_ptr) {
+    m_ptr->refcount_inc();
   }
 
-  if ((temp_ptr) && ((RefCountObj *)temp_ptr)->refcount_dec() == 0) {
-    ((RefCountObj *)temp_ptr)->free();
+  if (temp_ptr && temp_ptr->refcount_dec() == 0) {
+    temp_ptr->free();
   }
 
   return (*this);
diff --git a/proxy/hdrs/HdrHeap.cc b/proxy/hdrs/HdrHeap.cc
index 28dd399..9f01e19 100644
--- a/proxy/hdrs/HdrHeap.cc
+++ b/proxy/hdrs/HdrHeap.cc
@@ -972,7 +972,7 @@ HdrHeap::attach_str_heap(char *h_start, int h_len, RefCountObj *h_ref_obj, int *
   // Loop over existing entries to see if this one is already present
   for (int z = 0; z < *index; z++) {
     if (m_ronly_heap[z].m_heap_start == h_start) {
-      ink_assert(m_ronly_heap[z].m_ref_count_ptr._ptr() == h_ref_obj);
+      ink_assert(m_ronly_heap[z].m_ref_count_ptr.object() == h_ref_obj);
 
       // The lengths could be different because our copy could be
       //   read-only and the copy we are attaching from could be

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

[trafficserver] 20/33: TS-4425: Use Ptr in session acceptors.

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 0e73f84340a65a8610f33c9f060d4a38effe173a
Author: James Peach <jp...@apache.org>
AuthorDate: Thu May 5 22:18:18 2016 -0700

    TS-4425: Use Ptr<ProxyMutex> in session acceptors.
---
 iocore/net/SSLNextProtocolAccept.cc | 6 ++----
 proxy/ProtocolProbeSessionAccept.cc | 2 +-
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/iocore/net/SSLNextProtocolAccept.cc b/iocore/net/SSLNextProtocolAccept.cc
index 2d1e213..91f22ef 100644
--- a/iocore/net/SSLNextProtocolAccept.cc
+++ b/iocore/net/SSLNextProtocolAccept.cc
@@ -27,10 +27,8 @@ static void
 send_plugin_event(Continuation *plugin, int event, void *edata)
 {
   if (plugin->mutex) {
-    EThread *thread(this_ethread());
-    MUTEX_TAKE_LOCK(plugin->mutex, thread);
+    SCOPED_MUTEX_LOCK(lock, plugin->mutex, this_ethread());
     plugin->handleEvent(event, edata);
-    MUTEX_UNTAKE_LOCK(plugin->mutex, thread);
   } else {
     plugin->handleEvent(event, edata);
   }
@@ -64,7 +62,7 @@ ssl_netvc_cast(int event, void *edata)
 // lock across the handshake, so we make a trampoline to bounce the event from the SSL acceptor to the ultimate session
 // acceptor.
 struct SSLNextProtocolTrampoline : public Continuation {
-  explicit SSLNextProtocolTrampoline(const SSLNextProtocolAccept *npn, ProxyMutex *mutex) : Continuation(mutex), npnParent(npn)
+  SSLNextProtocolTrampoline(const SSLNextProtocolAccept *npn, Ptr<ProxyMutex> &mutex) : Continuation(mutex), npnParent(npn)
   {
     SET_HANDLER(&SSLNextProtocolTrampoline::ioCompletionEvent);
   }
diff --git a/proxy/ProtocolProbeSessionAccept.cc b/proxy/ProtocolProbeSessionAccept.cc
index f73a051..8f64467 100644
--- a/proxy/ProtocolProbeSessionAccept.cc
+++ b/proxy/ProtocolProbeSessionAccept.cc
@@ -59,7 +59,7 @@ struct ProtocolProbeTrampoline : public Continuation, public ProtocolProbeSessio
   static const unsigned buffer_size_index = CLIENT_CONNECTION_FIRST_READ_BUFFER_SIZE_INDEX;
   IOBufferReader *reader;
 
-  explicit ProtocolProbeTrampoline(const ProtocolProbeSessionAccept *probe, ProxyMutex *mutex, MIOBuffer *buffer,
+  explicit ProtocolProbeTrampoline(const ProtocolProbeSessionAccept *probe, Ptr<ProxyMutex> &mutex, MIOBuffer *buffer,
                                    IOBufferReader *reader)
     : Continuation(mutex), probeParent(probe)
   {

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

[trafficserver] 08/33: TS-4425: Add Ptr overloads for Mutex APIs.

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 8531f6a277024ac5a65cd507d93c1a88e29299d8
Author: James Peach <jp...@apache.org>
AuthorDate: Thu May 5 19:48:33 2016 -0700

    TS-4425: Add Ptr<ProxyMutex> overloads for Mutex APIs.
    
    Add Ptr<ProxyMutex> overloads for various Mutex APIs so that the
    callers will not have to call Ptr::get() everywhere.
---
 iocore/eventsystem/I_Lock.h | 109 ++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 100 insertions(+), 9 deletions(-)

diff --git a/iocore/eventsystem/I_Lock.h b/iocore/eventsystem/I_Lock.h
index 5f4cfc5..618f12c 100644
--- a/iocore/eventsystem/I_Lock.h
+++ b/iocore/eventsystem/I_Lock.h
@@ -322,6 +322,20 @@ Mutex_trylock(
 }
 
 inline bool
+Mutex_trylock(
+#ifdef DEBUG
+  const SourceLocation &location, const char *ahandler,
+#endif
+  Ptr<ProxyMutex> &m, EThread *t)
+{
+  return Mutex_trylock(
+#ifdef DEBUG
+    location, ahandler,
+#endif
+    m.get(), t);
+}
+
+inline bool
 Mutex_trylock_spin(
 #ifdef DEBUG
   const SourceLocation &location, const char *ahandler,
@@ -370,6 +384,20 @@ Mutex_trylock_spin(
   return true;
 }
 
+inline bool
+Mutex_trylock_spin(
+#ifdef DEBUG
+  const SourceLocation &location, const char *ahandler,
+#endif
+  Ptr<ProxyMutex> &m, EThread *t, int spincnt = 1)
+{
+  return Mutex_trylock_spin(
+#ifdef DEBUG
+    location, ahandler,
+#endif
+    m.get(), t, spincnt);
+}
+
 inline int
 Mutex_lock(
 #ifdef DEBUG
@@ -402,6 +430,20 @@ Mutex_lock(
   return true;
 }
 
+inline int
+Mutex_lock(
+#ifdef DEBUG
+  const SourceLocation &location, const char *ahandler,
+#endif
+  Ptr<ProxyMutex> &m, EThread *t)
+{
+  return Mutex_lock(
+#ifdef DEBUG
+    location, ahandler,
+#endif
+    m.get(), t);
+}
+
 inline void
 Mutex_unlock(ProxyMutex *m, EThread *t)
 {
@@ -426,6 +468,12 @@ Mutex_unlock(ProxyMutex *m, EThread *t)
   }
 }
 
+inline void
+Mutex_unlock(Ptr<ProxyMutex> &m, EThread *t)
+{
+  Mutex_unlock(m.get(), t);
+}
+
 /** Scoped lock class for ProxyMutex
  */
 class MutexLock
@@ -445,10 +493,24 @@ public:
 #ifdef DEBUG
       location, ahandler,
 #endif // DEBUG
-      m, t);
+      m.get(), t);
   }
 
-  ~MutexLock() { Mutex_unlock(m, m->thread_holding); }
+  MutexLock(
+#ifdef DEBUG
+    const SourceLocation &location, const char *ahandler,
+#endif // DEBUG
+    Ptr<ProxyMutex> &am, EThread *t)
+    : m(am)
+  {
+    Mutex_lock(
+#ifdef DEBUG
+      location, ahandler,
+#endif // DEBUG
+      m.get(), t);
+  }
+
+  ~MutexLock() { Mutex_unlock(m.get(), m->thread_holding); }
 };
 
 /** Scoped try lock class for ProxyMutex
@@ -471,7 +533,21 @@ public:
 #ifdef DEBUG
       location, ahandler,
 #endif // DEBUG
-      m, t);
+      m.get(), t);
+  }
+
+  MutexTryLock(
+#ifdef DEBUG
+    const SourceLocation &location, const char *ahandler,
+#endif // DEBUG
+    Ptr<ProxyMutex> &am, EThread *t)
+    : m(am)
+  {
+    lock_acquired = Mutex_trylock(
+#ifdef DEBUG
+      location, ahandler,
+#endif // DEBUG
+      m.get(), t);
   }
 
   MutexTryLock(
@@ -485,13 +561,27 @@ public:
 #ifdef DEBUG
       location, ahandler,
 #endif // DEBUG
-      m, t, sp);
+      m.get(), t, sp);
+  }
+
+  MutexTryLock(
+#ifdef DEBUG
+    const SourceLocation &location, const char *ahandler,
+#endif // DEBUG
+    Ptr<ProxyMutex> &am, EThread *t, int sp)
+    : m(am)
+  {
+    lock_acquired = Mutex_trylock_spin(
+#ifdef DEBUG
+      location, ahandler,
+#endif // DEBUG
+      m.get(), t, sp);
   }
 
   ~MutexTryLock()
   {
     if (lock_acquired)
-      Mutex_unlock(m.m_ptr, m.m_ptr->thread_holding);
+      Mutex_unlock(m.get(), m->thread_holding);
   }
 
   /** Spin till lock is acquired
@@ -499,7 +589,7 @@ public:
   void
   acquire(EThread *t)
   {
-    MUTEX_TAKE_LOCK(m.m_ptr, t);
+    MUTEX_TAKE_LOCK(m.get(), t);
     lock_acquired = true;
   }
 
@@ -508,7 +598,7 @@ public:
   {
     ink_assert(lock_acquired); // generate a warning because it shouldn't be done.
     if (lock_acquired) {
-      Mutex_unlock(m.m_ptr, m.m_ptr->thread_holding);
+      Mutex_unlock(m.get(), m->thread_holding);
     }
     lock_acquired = false;
   }
@@ -518,10 +608,11 @@ public:
   {
     return lock_acquired;
   }
+
   const ProxyMutex *
-  get_mutex()
+  get_mutex() const
   {
-    return m.m_ptr;
+    return m.get();
   }
 };
 

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

[trafficserver] 21/33: TS-4425: Switch IOBuffers over to Ptr::get().

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit cf53450b74c54a7c1661d95043de91286382ec1f
Author: James Peach <jp...@apache.org>
AuthorDate: Thu May 5 22:27:14 2016 -0700

    TS-4425: Switch IOBuffers over to Ptr::get().
---
 iocore/eventsystem/IOBuffer.cc  |  26 +++++-----
 iocore/eventsystem/I_IOBuffer.h |  21 +++++---
 iocore/eventsystem/P_IOBuffer.h | 112 ++++++++++++++++++++++++++--------------
 3 files changed, 102 insertions(+), 57 deletions(-)

diff --git a/iocore/eventsystem/IOBuffer.cc b/iocore/eventsystem/IOBuffer.cc
index b73d81e..b2aa507 100644
--- a/iocore/eventsystem/IOBuffer.cc
+++ b/iocore/eventsystem/IOBuffer.cc
@@ -79,7 +79,7 @@ MIOBuffer::remove_append(IOBufferReader *r)
     }
     r->start_offset = 0;
     l += b->read_avail();
-    append_block(b);
+    append_block(b.get());
   }
   r->mbuf->_writer = NULL;
   return l;
@@ -140,7 +140,7 @@ int64_t
 MIOBuffer::write(IOBufferReader *r, int64_t alen, int64_t offset)
 {
   int64_t len = alen;
-  IOBufferBlock *b = r->block;
+  IOBufferBlock *b = r->block.get();
   offset += r->start_offset;
 
   while (b && len > 0) {
@@ -148,22 +148,24 @@ MIOBuffer::write(IOBufferReader *r, int64_t alen, int64_t offset)
     max_bytes -= offset;
     if (max_bytes <= 0) {
       offset = -max_bytes;
-      b = b->next;
+      b = b->next.get();
       continue;
     }
     int64_t bytes;
-    if (len < 0 || len >= max_bytes)
+    if (len < 0 || len >= max_bytes) {
       bytes = max_bytes;
-    else
+    } else {
       bytes = len;
+    }
     IOBufferBlock *bb = b->clone();
     bb->_start += offset;
     bb->_buf_end = bb->_end = bb->_start + bytes;
     append_block(bb);
     offset = 0;
     len -= bytes;
-    b = b->next;
+    b = b->next.get();
   }
+
   return alen - len;
 }
 
@@ -212,7 +214,7 @@ IOBufferReader::read(void *ab, int64_t len)
 int64_t
 IOBufferReader::memchr(char c, int64_t len, int64_t offset)
 {
-  IOBufferBlock *b = block;
+  IOBufferBlock *b = block.get();
   offset += start_offset;
   int64_t o = offset;
 
@@ -221,7 +223,7 @@ IOBufferReader::memchr(char c, int64_t len, int64_t offset)
     max_bytes -= offset;
     if (max_bytes <= 0) {
       offset = -max_bytes;
-      b = b->next;
+      b = b->next.get();
       continue;
     }
     int64_t bytes;
@@ -235,7 +237,7 @@ IOBufferReader::memchr(char c, int64_t len, int64_t offset)
       return (int64_t)(o - start_offset + p - s);
     o += bytes;
     len -= bytes;
-    b = b->next;
+    b = b->next.get();
     offset = 0;
   }
 
@@ -246,7 +248,7 @@ char *
 IOBufferReader::memcpy(const void *ap, int64_t len, int64_t offset)
 {
   char *p = (char *)ap;
-  IOBufferBlock *b = block;
+  IOBufferBlock *b = block.get();
   offset += start_offset;
 
   while (b && len) {
@@ -254,7 +256,7 @@ IOBufferReader::memcpy(const void *ap, int64_t len, int64_t offset)
     max_bytes -= offset;
     if (max_bytes <= 0) {
       offset = -max_bytes;
-      b = b->next;
+      b = b->next.get();
       continue;
     }
     int64_t bytes;
@@ -265,7 +267,7 @@ IOBufferReader::memcpy(const void *ap, int64_t len, int64_t offset)
     ::memcpy(p, b->start() + offset, bytes);
     p += bytes;
     len -= bytes;
-    b = b->next;
+    b = b->next.get();
     offset = 0;
   }
 
diff --git a/iocore/eventsystem/I_IOBuffer.h b/iocore/eventsystem/I_IOBuffer.h
index 5931f90..b50dfb2 100644
--- a/iocore/eventsystem/I_IOBuffer.h
+++ b/iocore/eventsystem/I_IOBuffer.h
@@ -917,18 +917,19 @@ public:
     Returns a pointer to the first writable block on the block chain.
     Returns NULL if there are not currently any writable blocks on the
     block list.
-
   */
   IOBufferBlock *
   first_write_block()
   {
     if (_writer) {
-      if (_writer->next && !_writer->write_avail())
-        return _writer->next;
+      if (_writer->next && !_writer->write_avail()) {
+        return _writer->next.get();
+      }
       ink_assert(!_writer->next || !_writer->next->read_avail());
-      return _writer;
-    } else
-      return NULL;
+      return _writer.get();
+    }
+
+    return NULL;
   }
 
   char *
@@ -937,16 +938,19 @@ public:
     IOBufferBlock *b = first_write_block();
     return b ? b->buf() : 0;
   }
+
   char *
   buf_end()
   {
     return first_write_block()->buf_end();
   }
+
   char *
   start()
   {
     return first_write_block()->start();
   }
+
   char *
   end()
   {
@@ -1318,6 +1322,11 @@ public:
   {
     return new_IOBufferBlock_internal(loc, d, len, offset);
   }
+  IOBufferBlock *
+  operator()(Ptr<IOBufferData> &d, int64_t len = 0, int64_t offset = 0)
+  {
+    return new_IOBufferBlock_internal(loc, d.get(), len, offset);
+  }
 };
 #endif
 
diff --git a/iocore/eventsystem/P_IOBuffer.h b/iocore/eventsystem/P_IOBuffer.h
index 1298b89..2046ca6 100644
--- a/iocore/eventsystem/P_IOBuffer.h
+++ b/iocore/eventsystem/P_IOBuffer.h
@@ -69,27 +69,32 @@ index_to_buffer_size(int64_t idx)
 }
 
 TS_INLINE IOBufferBlock *
-iobufferblock_clone(IOBufferBlock *b, int64_t offset, int64_t len)
+iobufferblock_clone(IOBufferBlock *src, int64_t offset, int64_t len)
 {
   IOBufferBlock *start_buf = NULL;
   IOBufferBlock *current_buf = NULL;
 
-  while (b && len >= 0) {
-    char *start = b->_start;
-    char *end = b->_end;
+  while (src && len >= 0) {
+    char *start = src->_start;
+    char *end = src->_end;
     int64_t max_bytes = end - start;
+
     max_bytes -= offset;
     if (max_bytes <= 0) {
       offset = -max_bytes;
-      b = b->next;
+      src = src->next.get();
       continue;
     }
+
     int64_t bytes = len;
-    if (bytes >= max_bytes)
+    if (bytes >= max_bytes) {
       bytes = max_bytes;
-    IOBufferBlock *new_buf = b->clone();
+    }
+
+    IOBufferBlock *new_buf = src->clone();
     new_buf->_start += offset;
     new_buf->_buf_end = new_buf->_end = new_buf->_start + bytes;
+
     if (!start_buf) {
       start_buf = new_buf;
       current_buf = start_buf;
@@ -97,10 +102,12 @@ iobufferblock_clone(IOBufferBlock *b, int64_t offset, int64_t len)
       current_buf->next = new_buf;
       current_buf = new_buf;
     }
+
     len -= bytes;
-    b = b->next;
+    src = src->next.get();
     offset = 0;
   }
+
   return start_buf;
 }
 
@@ -109,16 +116,21 @@ iobufferblock_skip(IOBufferBlock *b, int64_t *poffset, int64_t *plen, int64_t wr
 {
   int64_t offset = *poffset;
   int64_t len = write;
+
   while (b && len >= 0) {
     int64_t max_bytes = b->read_avail();
+
+    // If this block ends before the start offset, skip it
+    // and adjust the offset to consume its length.
     max_bytes -= offset;
     if (max_bytes <= 0) {
       offset = -max_bytes;
-      b = b->next;
+      b = b->next.get();
       continue;
     }
+
     if (len >= max_bytes) {
-      b = b->next;
+      b = b->next.get();
       len -= max_bytes;
       offset = 0;
     } else {
@@ -126,14 +138,13 @@ iobufferblock_skip(IOBufferBlock *b, int64_t *poffset, int64_t *plen, int64_t wr
       break;
     }
   }
+
   *poffset = offset;
   *plen -= write;
   return b;
 }
 
 #ifdef TRACK_BUFFER_USER
-extern Resource *res_lookup(const char *path);
-
 TS_INLINE void
 iobuffer_mem_inc(const char *_loc, int64_t _size_index)
 {
@@ -406,19 +417,25 @@ TS_INLINE void
 IOBufferBlock::clear()
 {
   data = NULL;
-  IOBufferBlock *p = next;
+
+  IOBufferBlock *p = next.get();
   while (p) {
-    int r = p->refcount_dec();
-    if (r)
-      break;
-    else {
-      IOBufferBlock *n = p->next.m_ptr;
-      p->next.m_ptr = NULL;
+    // If our block pointer refcount dropped to zero,
+    // recursively free the list.
+    if (p->refcount_dec() == 0) {
+      IOBufferBlock *n = p->next.detach();
       p->free();
       p = n;
+    } else {
+      // We don't hold the last refcount, so we are done.
+      break;
     }
   }
-  next.m_ptr = NULL;
+
+  // Nuke the next pointer without dropping the refcount
+  // because we already manually did that.
+  next.detach();
+
   _buf_end = _end = _start = NULL;
 }
 
@@ -555,14 +572,16 @@ IOBufferReader::current_low_water()
 TS_INLINE IOBufferBlock *
 IOBufferReader::get_current_block()
 {
-  return block;
+  return block.get();
 }
 
 TS_INLINE char *
 IOBufferReader::start()
 {
-  if (block == 0)
+  if (!block) {
     return 0;
+  }
+
   skip_empty_blocks();
   return block->start() + start_offset;
 }
@@ -570,8 +589,10 @@ IOBufferReader::start()
 TS_INLINE char *
 IOBufferReader::end()
 {
-  if (block == 0)
+  if (!block) {
     return 0;
+  }
+
   skip_empty_blocks();
   return block->end();
 }
@@ -579,8 +600,10 @@ IOBufferReader::end()
 TS_INLINE int64_t
 IOBufferReader::block_read_avail()
 {
-  if (block == 0)
+  if (!block) {
     return 0;
+  }
+
   skip_empty_blocks();
   return (int64_t)(block->end() - (block->start() + start_offset));
 }
@@ -589,12 +612,13 @@ TS_INLINE int
 IOBufferReader::block_count()
 {
   int count = 0;
-  IOBufferBlock *b = block;
+  IOBufferBlock *b = block.get();
 
   while (b) {
     count++;
-    b = b->next;
+    b = b->next.get();
   }
+
   return count;
 }
 
@@ -602,15 +626,18 @@ TS_INLINE int64_t
 IOBufferReader::read_avail()
 {
   int64_t t = 0;
-  IOBufferBlock *b = block;
+  IOBufferBlock *b = block.get();
 
   while (b) {
     t += b->read_avail();
-    b = b->next;
+    b = b->next.get();
   }
+
   t -= start_offset;
-  if (size_limit != INT64_MAX && t > size_limit)
+  if (size_limit != INT64_MAX && t > size_limit) {
     t = size_limit;
+  }
+
   return t;
 }
 
@@ -618,13 +645,14 @@ inline bool
 IOBufferReader::is_read_avail_more_than(int64_t size)
 {
   int64_t t = -start_offset;
-  IOBufferBlock *b = block;
+  IOBufferBlock *b = block.get();
+
   while (b) {
     t += b->read_avail();
     if (t > size) {
       return true;
     }
-    b = b->next;
+    b = b->next.get();
   }
   return false;
 }
@@ -633,11 +661,15 @@ TS_INLINE void
 IOBufferReader::consume(int64_t n)
 {
   start_offset += n;
-  if (size_limit != INT64_MAX)
+  if (size_limit != INT64_MAX) {
     size_limit -= n;
+  }
+
   ink_assert(size_limit >= 0);
-  if (block == 0)
+  if (!block) {
     return;
+  }
+
   int64_t r = block->read_avail();
   int64_t s = start_offset;
   while (r <= s && block->next && block->next->read_avail()) {
@@ -646,26 +678,28 @@ IOBufferReader::consume(int64_t n)
     block = block->next;
     r = block->read_avail();
   }
+
   ink_assert(read_avail() >= 0);
 }
 
 TS_INLINE char &IOBufferReader::operator[](int64_t i)
 {
   static char _error = '\0';
+  IOBufferBlock *b = block.get();
 
-  IOBufferBlock *b = block;
   i += start_offset;
   while (b) {
     int64_t bytes = b->read_avail();
     if (bytes > i)
       return b->start()[i];
     i -= bytes;
-    b = b->next;
+    b = b->next.get();
   }
 
   ink_assert(!"out of range");
-  if (unlikely(b))
+  if (unlikely(b)) {
     return *b->start();
+  }
 
   return _error;
 }
@@ -893,7 +927,7 @@ MIOBuffer::append_block_internal(IOBufferBlock *b)
     _writer->next = b;
     while (b->read_avail()) {
       _writer = b;
-      b = b->next;
+      b = b->next.get();
       if (!b)
         break;
     }
@@ -964,10 +998,10 @@ TS_INLINE int64_t
 MIOBuffer::current_write_avail()
 {
   int64_t t = 0;
-  IOBufferBlock *b = _writer;
+  IOBufferBlock *b = _writer.get();
   while (b) {
     t += b->write_avail();
-    b = b->next;
+    b = b->next.get();
   }
   return t;
 }

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

[trafficserver] 13/33: TS-4445: Switch CacheRead.cc over to Ptr::get().

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 708a284e0272bca7eab2819be5c65b31c11d82ba
Author: James Peach <jp...@apache.org>
AuthorDate: Thu May 5 20:59:09 2016 -0700

    TS-4445: Switch CacheRead.cc over to Ptr::get().
---
 iocore/cache/CacheRead.cc | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/iocore/cache/CacheRead.cc b/iocore/cache/CacheRead.cc
index 685426a..b71d375 100644
--- a/iocore/cache/CacheRead.cc
+++ b/iocore/cache/CacheRead.cc
@@ -41,7 +41,7 @@ Cache::open_read(Continuation *cont, const CacheKey *key, CacheFragType type, co
 
   Vol *vol = key_to_vol(key, hostname, host_len);
   Dir result, *last_collision = NULL;
-  ProxyMutex *mutex = cont->mutex;
+  ProxyMutex *mutex = cont->mutex.get();
   OpenDirEntry *od = NULL;
   CacheVC *c = NULL;
   {
@@ -104,7 +104,7 @@ Cache::open_read(Continuation *cont, const CacheKey *key, CacheHTTPHdr *request,
 
   Vol *vol = key_to_vol(key, hostname, host_len);
   Dir result, *last_collision = NULL;
-  ProxyMutex *mutex = cont->mutex;
+  ProxyMutex *mutex = cont->mutex.get();
   OpenDirEntry *od = NULL;
   CacheVC *c = NULL;
 
@@ -495,7 +495,7 @@ CacheVC::openReadFromWriterMain(int /* event ATS_UNUSED */, Event * /* e ATS_UNU
      openWriteWriteDone was called. */
   if (length > ((int64_t)doc_len) - vio.ndone) {
     int64_t skip_bytes = length - (doc_len - vio.ndone);
-    iobufferblock_skip(writer_buf, &writer_offset, &length, skip_bytes);
+    iobufferblock_skip(writer_buf.get(), &writer_offset, &length, skip_bytes);
   }
   int64_t bytes = length;
   if (bytes > vio.ntodo())
@@ -505,8 +505,8 @@ CacheVC::openReadFromWriterMain(int /* event ATS_UNUSED */, Event * /* e ATS_UNU
     // reached the end of the document and the user still wants more
     return calluser(VC_EVENT_EOS);
   }
-  b = iobufferblock_clone(writer_buf, writer_offset, bytes);
-  writer_buf = iobufferblock_skip(writer_buf, &writer_offset, &length, bytes);
+  b = iobufferblock_clone(writer_buf.get(), writer_offset, bytes);
+  writer_buf = iobufferblock_skip(writer_buf.get(), &writer_offset, &length, bytes);
   vio.buffer.writer()->append_block(b);
   vio.ndone += bytes;
   if (vio.ntodo() <= 0)
@@ -938,7 +938,7 @@ CacheVC::openReadVecWrite(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */
     if (io.ok()) {
       ink_assert(f.evac_vector);
       ink_assert(frag_type == CACHE_FRAG_TYPE_HTTP);
-      ink_assert(!buf.m_ptr);
+      ink_assert(!buf);
       f.evac_vector = false;
       last_collision = NULL;
       f.update = 0;
@@ -957,8 +957,9 @@ CacheVC::openReadVecWrite(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */
         // case is rare.
         goto Lrestart;
       }
-    } else
+    } else {
       vol->close_write(this);
+    }
   }
 
   CACHE_INCREMENT_DYN_STAT(cache_read_failure_stat);

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

[trafficserver] 10/33: TS-4425: Remove unused Mutex pointers from the threads system.

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit f474472f468b2ee5400af4662ab5034abeb4be5b
Author: James Peach <jp...@apache.org>
AuthorDate: Thu May 5 20:46:07 2016 -0700

    TS-4425: Remove unused Mutex pointers from the threads system.
---
 iocore/eventsystem/I_Thread.h            | 14 ++++----------
 iocore/eventsystem/Thread.cc             |  2 --
 iocore/eventsystem/UnixEventProcessor.cc |  1 -
 3 files changed, 4 insertions(+), 13 deletions(-)

diff --git a/iocore/eventsystem/I_Thread.h b/iocore/eventsystem/I_Thread.h
index 2d4fcb7..f24bb99 100644
--- a/iocore/eventsystem/I_Thread.h
+++ b/iocore/eventsystem/I_Thread.h
@@ -61,20 +61,15 @@
 
 #if !defined(_I_EventSystem_h) && !defined(_P_EventSystem_h)
 #error "include I_EventSystem.h or P_EventSystem.h"
--- - include I_Event.h or
-  P_Event.h
 #endif
+
 #include "ts/ink_platform.h"
 #include "ts/ink_thread.h"
 #include "I_ProxyAllocator.h"
-  class Thread;
-class ProxyMutex;
 
-#define THREADAPI
-#define THREADAPI_RETURN_TYPE void *
-typedef THREADAPI_RETURN_TYPE(THREADAPI *ThreadFunction)(void *arg);
-
-extern ProxyMutex *global_mutex;
+class Thread;
+class ProxyMutex;
+typedef void *(*ThreadFunction)(void *arg);
 
 static const int MAX_THREAD_NAME_LENGTH = 16;
 static const int DEFAULT_STACKSIZE = 1048576; // 1MB
@@ -124,7 +119,6 @@ public:
 
   static ink_hrtime cur_time;
   inkcoreapi static ink_thread_key thread_data_key;
-  Ptr<ProxyMutex> mutex_ptr;
 
   // For THREAD_ALLOC
   ProxyAllocator eventAllocator;
diff --git a/iocore/eventsystem/Thread.cc b/iocore/eventsystem/Thread.cc
index 03af6db..86c74ea 100644
--- a/iocore/eventsystem/Thread.cc
+++ b/iocore/eventsystem/Thread.cc
@@ -37,14 +37,12 @@
 
 static ink_thread_key init_thread_key();
 
-ProxyMutex *global_mutex = NULL;
 ink_hrtime Thread::cur_time = 0;
 inkcoreapi ink_thread_key Thread::thread_data_key = init_thread_key();
 
 Thread::Thread()
 {
   mutex = new_ProxyMutex();
-  mutex_ptr = mutex;
   MUTEX_TAKE_LOCK(mutex, (EThread *)this);
   mutex->nthread_holding = THREAD_MUTEX_THREAD_HOLDING;
 }
diff --git a/iocore/eventsystem/UnixEventProcessor.cc b/iocore/eventsystem/UnixEventProcessor.cc
index 0c4e410..549c6f2 100644
--- a/iocore/eventsystem/UnixEventProcessor.cc
+++ b/iocore/eventsystem/UnixEventProcessor.cc
@@ -85,7 +85,6 @@ EventProcessor::start(int n_event_threads, size_t stacksize)
     EThread *t = new EThread(REGULAR, i);
     if (i == 0) {
       ink_thread_setspecific(Thread::thread_data_key, t);
-      global_mutex = t->mutex;
       Thread::get_hrtime_updated();
     }
     all_ethreads[i] = t;

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

[trafficserver] 29/33: TS-4425: Switch proxy/hdrs over to Ptr::get().

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit e61ea1b55470304a467f5ac7cf7d9b425470e56e
Author: James Peach <jp...@apache.org>
AuthorDate: Sat May 7 13:59:01 2016 -0700

    TS-4425: Switch proxy/hdrs over to Ptr::get().
---
 proxy/hdrs/HdrHeap.cc   | 44 +++++++++++++++++++++-----------------------
 proxy/hdrs/HdrHeap.h    | 44 ++++++++++++++++++++++----------------------
 proxy/hdrs/HdrTSOnly.cc |  2 +-
 3 files changed, 44 insertions(+), 46 deletions(-)

diff --git a/proxy/hdrs/HdrHeap.cc b/proxy/hdrs/HdrHeap.cc
index 9f01e19..cc0721c 100644
--- a/proxy/hdrs/HdrHeap.cc
+++ b/proxy/hdrs/HdrHeap.cc
@@ -43,7 +43,6 @@ Allocator hdrHeapAllocator("hdrHeap", HDR_HEAP_DEFAULT_SIZE);
 static HdrHeap proto_heap;
 
 Allocator strHeapAllocator("hdrStrHeap", HDR_STR_HEAP_DEFAULT_SIZE);
-static HdrStrHeap str_proto_heap;
 
 /*-------------------------------------------------------------------------
   -------------------------------------------------------------------------*/
@@ -99,11 +98,11 @@ HdrHeap::init()
   // We need to clear m_ptr directly since it's garbage and
   //  using the operator functions will to free() what ever
   //  garbage it is pointing to
-  m_read_write_heap.m_ptr = NULL;
+  m_read_write_heap.detach();
 
   for (int i = 0; i < HDR_BUF_RONLY_HEAPS; i++) {
     m_ronly_heap[i].m_heap_start = NULL;
-    m_ronly_heap[i].m_ref_count_ptr.m_ptr = NULL;
+    m_ronly_heap[i].m_ref_count_ptr.detach();
     m_ronly_heap[i].m_locked = false;
     m_ronly_heap[i].m_heap_len = 0;
   }
@@ -332,8 +331,8 @@ HdrHeap::demote_rw_str_heap()
   for (int i = 0; i < HDR_BUF_RONLY_HEAPS; i++) {
     if (m_ronly_heap[i].m_heap_start == NULL) {
       // We've found a slot
-      m_ronly_heap[i].m_ref_count_ptr = m_read_write_heap;
-      m_ronly_heap[i].m_heap_start = (char *)m_read_write_heap.m_ptr;
+      m_ronly_heap[i].m_ref_count_ptr = m_read_write_heap.object();
+      m_ronly_heap[i].m_heap_start = (char *)m_read_write_heap.get();
       m_ronly_heap[i].m_heap_len = m_read_write_heap->m_heap_size - m_read_write_heap->m_free_size;
 
       //          Debug("hdrs", "Demoted rw heap of %d size", m_read_write_heap->m_heap_size);
@@ -479,7 +478,7 @@ HdrHeap::sanity_check_strs()
 
   // Build up a string check table
   if (m_read_write_heap) {
-    heaps[num_heaps].start = ((char *)m_read_write_heap.m_ptr) + sizeof(HdrStrHeap);
+    heaps[num_heaps].start = ((char *)m_read_write_heap.get()) + sizeof(HdrStrHeap);
 
     int heap_size = m_read_write_heap->m_heap_size - (sizeof(HdrStrHeap) + m_read_write_heap->m_free_size);
 
@@ -669,12 +668,12 @@ HdrHeap::marshal(char *buf, int len)
   marshal_hdr->m_size = ptr_heap_size + HDR_HEAP_HDR_SIZE;
   marshal_hdr->m_next = NULL;
   marshal_hdr->m_free_size = 0;
-  marshal_hdr->m_read_write_heap.m_ptr = NULL;
+  marshal_hdr->m_read_write_heap.detach();
   marshal_hdr->m_lost_string_space = this->m_lost_string_space;
 
   // We'have one read-only string heap after marshalling
   marshal_hdr->m_ronly_heap[0].m_heap_start = (char *)(intptr_t)marshal_hdr->m_size; // offset
-  marshal_hdr->m_ronly_heap[0].m_ref_count_ptr.m_ptr = NULL;
+  marshal_hdr->m_ronly_heap[0].m_ref_count_ptr.detach();
 
   for (int i = 1; i < HDR_BUF_RONLY_HEAPS; i++)
     marshal_hdr->m_ronly_heap[i].m_heap_start = NULL;
@@ -691,7 +690,7 @@ HdrHeap::marshal(char *buf, int len)
   MarshalXlate str_xlation[HDR_BUF_RONLY_HEAPS + 1];
 
   if (m_read_write_heap) {
-    char *copy_start = ((char *)m_read_write_heap.m_ptr) + sizeof(HdrStrHeap);
+    char *copy_start = ((char *)m_read_write_heap.get()) + sizeof(HdrStrHeap);
     int nto_copy = m_read_write_heap->m_heap_size - (sizeof(HdrStrHeap) + m_read_write_heap->m_free_size);
 
     if (nto_copy > len) {
@@ -904,7 +903,7 @@ HdrHeap::unmarshal(int buf_length, int obj_type, HdrHeapObjImpl **found_obj, Ref
   m_free_start = ((char *)this) + m_size;
   m_ronly_heap[0].m_heap_start = ((char *)this) + (intptr_t)m_ronly_heap[0].m_heap_start;
 
-  // Crazy Invarient - If we are sitting in a ref counted block,
+  // Crazy Invariant - If we are sitting in a ref counted block,
   //   the HdrHeap lifetime is externally determined.  Whoever
   //   unmarshalls us should keep the block around as long as
   //   they want to use the header.  However, the strings can
@@ -915,8 +914,9 @@ HdrHeap::unmarshal(int buf_length, int obj_type, HdrHeapObjImpl **found_obj, Ref
   //   the lifetime is explicit but copies will increase
   //   the refcount
   if (block_ref) {
-    m_ronly_heap[0].m_ref_count_ptr.m_ptr = block_ref;
+    m_ronly_heap[0].m_ref_count_ptr.swizzle(block_ref);
   }
+
   // Loop over objects and swizzle there pointer to
   //  live offsets
   char *obj_data = m_data_start;
@@ -962,11 +962,11 @@ HdrHeap::unmarshal(int buf_length, int obj_type, HdrHeapObjImpl **found_obj, Ref
   return unmarshal_size;
 }
 
-inline int
+inline bool
 HdrHeap::attach_str_heap(char *h_start, int h_len, RefCountObj *h_ref_obj, int *index)
 {
   if (*index >= HDR_BUF_RONLY_HEAPS) {
-    return 0;
+    return false;
   }
 
   // Loop over existing entries to see if this one is already present
@@ -980,7 +980,7 @@ HdrHeap::attach_str_heap(char *h_start, int h_len, RefCountObj *h_ref_obj, int *
       //   to was attached
       if (h_len > m_ronly_heap[z].m_heap_len)
         m_ronly_heap[z].m_heap_len = h_len;
-      return 1;
+      return true;
     }
   }
 
@@ -990,7 +990,7 @@ HdrHeap::attach_str_heap(char *h_start, int h_len, RefCountObj *h_ref_obj, int *
   m_ronly_heap[*index].m_locked = false;
   *index = *index + 1;
 
-  return 1;
+  return true;
 }
 
 // void HdrHeap::inhertit_string_heaps(const HdrHeap* inherit_from)
@@ -1005,7 +1005,7 @@ HdrHeap::inherit_string_heaps(const HdrHeap *inherit_from)
   if (inherit_from == (const HdrHeap *)this)
     return;
 
-  int index, result;
+  int index;
   int first_free = HDR_BUF_RONLY_HEAPS; // default is out of array bounds
   int free_slots = 0;
   int inherit_str_size = 0;
@@ -1055,16 +1055,14 @@ HdrHeap::inherit_string_heaps(const HdrHeap *inherit_from)
     if (inherit_from->m_read_write_heap) {
       int str_size =
         inherit_from->m_read_write_heap->m_heap_size - STR_HEAP_HDR_SIZE - inherit_from->m_read_write_heap->m_free_size;
-      result = attach_str_heap(((char *)inherit_from->m_read_write_heap.m_ptr) + STR_HEAP_HDR_SIZE, str_size,
-                               inherit_from->m_read_write_heap, &first_free);
-      ink_release_assert(result != 0);
+      ink_release_assert(attach_str_heap(((char *)inherit_from->m_read_write_heap.get()) + STR_HEAP_HDR_SIZE, str_size,
+                                         inherit_from->m_read_write_heap.get(), &first_free));
     }
     // Copy over read only string heaps
     for (int i = 0; i < HDR_BUF_RONLY_HEAPS; i++) {
       if (inherit_from->m_ronly_heap[i].m_heap_start) {
-        result = attach_str_heap(inherit_from->m_ronly_heap[i].m_heap_start, inherit_from->m_ronly_heap[i].m_heap_len,
-                                 inherit_from->m_ronly_heap[i].m_ref_count_ptr.m_ptr, &first_free);
-        ink_release_assert(result != 0);
+        ink_release_assert(attach_str_heap(inherit_from->m_ronly_heap[i].m_heap_start, inherit_from->m_ronly_heap[i].m_heap_len,
+                                           inherit_from->m_ronly_heap[i].m_ref_count_ptr.get(), &first_free));
       }
     }
 
@@ -1201,7 +1199,7 @@ REGRESSION_TEST(HdrHeap_Coalesce)(RegressionTest *t, int /* atype ATS_UNUSED */,
   HdrHeap *heap = new_HdrHeap();
   URLImpl *url = url_create(heap);
 
-  tb.check(heap->m_read_write_heap.m_ptr == NULL, "Checking that we have no rw heap.");
+  tb.check(heap->m_read_write_heap.get() == NULL, "Checking that we have no rw heap.");
   url_path_set(heap, url, buf, next_required_overflow_size, true);
   tb.check(heap->m_read_write_heap->m_free_size == 0, "Checking that we've completely consumed the rw heap");
   for (int i = 0; i < HDR_BUF_RONLY_HEAPS; ++i) {
diff --git a/proxy/hdrs/HdrHeap.h b/proxy/hdrs/HdrHeap.h
index cf206cd..afe25c5 100644
--- a/proxy/hdrs/HdrHeap.h
+++ b/proxy/hdrs/HdrHeap.h
@@ -60,6 +60,9 @@
 #define HDR_HEAP_HDR_SIZE ROUND(sizeof(HdrHeap), HDR_PTR_SIZE)
 #define STR_HEAP_HDR_SIZE sizeof(HdrStrHeap)
 
+class CoreUtils;
+class IOBufferBlock;
+
 enum {
   HDR_HEAP_OBJ_EMPTY = 0,
   HDR_HEAP_OBJ_RAW = 1,
@@ -135,22 +138,6 @@ enum {
   HDR_BUF_MAGIC_CORRUPT = 0xbadbadcc
 };
 
-struct StrHeapDesc {
-  StrHeapDesc();
-  Ptr<RefCountObj> m_ref_count_ptr;
-  char *m_heap_start;
-  int32_t m_heap_len;
-  bool m_locked;
-
-  bool
-  contains(const char *str) const
-  {
-    return (str >= m_heap_start && str < (m_heap_start + m_heap_len));
-  }
-};
-
-class IOBufferBlock;
-
 class HdrStrHeap : public RefCountObj
 {
 public:
@@ -171,7 +158,19 @@ public:
   }
 };
 
-class CoreUtils;
+struct StrHeapDesc {
+  StrHeapDesc();
+  Ptr<RefCountObj> m_ref_count_ptr;
+  char *m_heap_start;
+  int32_t m_heap_len;
+  bool m_locked;
+
+  bool
+  contains(const char *str) const
+  {
+    return (str >= m_heap_start && str < (m_heap_start + m_heap_len));
+  }
+};
 
 class HdrHeap
 {
@@ -211,7 +210,8 @@ public:
   lock_ronly_str_heap(int i)
   {
     m_ronly_heap[i].m_locked = true;
-  };
+  }
+
   void
   unlock_ronly_str_heap(int i)
   {
@@ -233,7 +233,7 @@ public:
         m_ronly_heap[i].m_locked = false;
       }
     }
-  };
+  }
 
   // Sanity Check Functions
   void sanity_check_strs();
@@ -265,7 +265,7 @@ public:
   void coalesce_str_heaps(int incoming_size = 0);
   void evacuate_from_str_heaps(HdrStrHeap *new_heap);
   size_t required_space_for_evacuation();
-  int attach_str_heap(char *h_start, int h_len, RefCountObj *h_ref_obj, int *index);
+  bool attach_str_heap(char *h_start, int h_len, RefCountObj *h_ref_obj, int *index);
 
   /** Struct to prevent garbage collection on heaps.
       This bumps the reference count to the heap containing the pointer
@@ -278,7 +278,7 @@ public:
     HeapGuard(HdrHeap *heap, const char *str)
     {
       if (heap->m_read_write_heap && heap->m_read_write_heap->contains(str)) {
-        m_ptr = heap->m_read_write_heap;
+        m_ptr = heap->m_read_write_heap.get();
       } else {
         for (int i = 0; i < HDR_BUF_RONLY_HEAPS; ++i) {
           if (heap->m_ronly_heap[i].contains(str)) {
@@ -290,7 +290,7 @@ public:
     }
 
     // There's no need to have a destructor here, the default dtor will take care of
-    // releaseing the (potentially) locked heap.
+    // releasing the (potentially) locked heap.
 
     /// The heap we protect (if any)
     Ptr<RefCountObj> m_ptr;
diff --git a/proxy/hdrs/HdrTSOnly.cc b/proxy/hdrs/HdrTSOnly.cc
index 6a59f7c..28e0dc4 100644
--- a/proxy/hdrs/HdrTSOnly.cc
+++ b/proxy/hdrs/HdrTSOnly.cc
@@ -171,7 +171,7 @@ RETRY:
       // Add block to heap in this slot
       m_ronly_heap[i].m_heap_start = (char *)use_start;
       m_ronly_heap[i].m_heap_len = (int)(b->end() - b->start());
-      m_ronly_heap[i].m_ref_count_ptr = b->data;
+      m_ronly_heap[i].m_ref_count_ptr = b->data.object();
       //          printf("Attaching block at %X for %d in slot %d\n",
       //                 m_ronly_heap[i].m_heap_start,
       //                 m_ronly_heap[i].m_heap_len,

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

[trafficserver] 26/33: TS-4425: Switch iocore/cluster over to Ptr::get().

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 32f84f1834c9b7e32c18b84b2b67c7f0181501f5
Author: James Peach <jp...@apache.org>
AuthorDate: Sat May 7 13:21:16 2016 -0700

    TS-4425: Switch iocore/cluster over to Ptr::get().
---
 iocore/cluster/ClusterCache.cc          |  8 ++++----
 iocore/cluster/ClusterHandler.cc        | 36 ++++++++++++++++-----------------
 iocore/cluster/ClusterHandlerBase.cc    | 10 ++++-----
 iocore/cluster/ClusterLib.cc            | 16 ++++++++-------
 iocore/cluster/ClusterLoadMonitor.cc    |  2 +-
 iocore/cluster/ClusterProcessor.cc      |  3 +--
 iocore/cluster/ClusterVConnection.cc    |  2 +-
 iocore/cluster/P_ClusterCache.h         |  6 +++---
 iocore/cluster/P_ClusterCacheInternal.h |  8 ++++----
 iocore/cluster/P_ClusterHandler.h       | 18 +++++++++--------
 iocore/cluster/P_ClusterInternal.h      | 20 ++++++++++++++++++
 11 files changed, 76 insertions(+), 53 deletions(-)

diff --git a/iocore/cluster/ClusterCache.cc b/iocore/cluster/ClusterCache.cc
index bf3b659..04213c9 100644
--- a/iocore/cluster/ClusterCache.cc
+++ b/iocore/cluster/ClusterCache.cc
@@ -1616,7 +1616,7 @@ CacheContinuation::replyOpEvent(int event, VConnection *cvc)
       msg->token = token; // Tell sender conn established
 
       OneWayTunnel *pOWT = OneWayTunnel::OneWayTunnel_alloc();
-      pOWT->init(read_cluster_vc, cache_vc, NULL, nbytes ? nbytes : DEFAULT_MAX_BUFFER_SIZE, this->mutex);
+      pOWT->init(read_cluster_vc, cache_vc, NULL, nbytes ? nbytes : DEFAULT_MAX_BUFFER_SIZE, this->mutex.get());
       read_cluster_vc->allow_remote_close();
       results_expected--;
     }
@@ -1688,7 +1688,7 @@ CacheContinuation::replyOpEvent(int event, VConnection *cvc)
       // Transmit reply message and object data in same cluster message
       Debug("cache_proto", "Sending reply/data seqno=%d buflen=%" PRId64, seq_number,
             readahead_data ? bytes_IOBufferBlockList(readahead_data, 1) : 0);
-      clusterProcessor.invoke_remote_data(ch, CACHE_OP_RESULT_CLUSTER_FUNCTION, (void *)msg, (flen + len), readahead_data,
+      clusterProcessor.invoke_remote_data(ch, CACHE_OP_RESULT_CLUSTER_FUNCTION, (void *)msg, (flen + len), readahead_data.get(),
                                           cluster_vc_channel, &token, &CacheContinuation::disposeOfDataBuffer, (void *)this,
                                           CLUSTER_OPT_STEAL);
     } else {
@@ -1975,7 +1975,7 @@ cache_op_result_ClusterFunction(ClusterHandler *ch, void *d, int l)
     c->freeMsgBuffer();
     if (ci.valid()) {
       // Unmarshaled CacheHTTPInfo contained in reply message, copy it.
-      c->setMsgBufferLen(len, iob);
+      c->setMsgBufferLen(len, iob.get());
       c->ic_new_info = ci;
     }
     msg->seq_number = len; // HACK ALERT: reusing variable
@@ -1996,7 +1996,7 @@ cache_op_result_ClusterFunction(ClusterHandler *ch, void *d, int l)
       c->token = msg->token;
     if (ci.valid()) {
       // Unmarshaled CacheHTTPInfo contained in reply message, copy it.
-      c->setMsgBufferLen(len, iob);
+      c->setMsgBufferLen(len, iob.get());
       c->ic_new_info = ci;
     }
     c->result_error = op_result_error;
diff --git a/iocore/cluster/ClusterHandler.cc b/iocore/cluster/ClusterHandler.cc
index da07b4d..57e9ab1 100644
--- a/iocore/cluster/ClusterHandler.cc
+++ b/iocore/cluster/ClusterHandler.cc
@@ -369,11 +369,11 @@ ClusterHandler::close_free_lock(ClusterVConnection *vc, ClusterVConnState *s)
 {
   Ptr<ProxyMutex> m(s->vio.mutex);
   if (s == &vc->read) {
-    if ((ProxyMutex *)vc->read_locked)
+    if (vc->read_locked)
       MUTEX_UNTAKE_LOCK(vc->read_locked, thread);
     vc->read_locked = NULL;
   } else {
-    if ((ProxyMutex *)vc->write_locked)
+    if (vc->write_locked)
       MUTEX_UNTAKE_LOCK(vc->write_locked, thread);
     vc->write_locked = NULL;
   }
@@ -569,7 +569,7 @@ ClusterHandler::build_initial_vector(bool read_flag)
             /////////////////////////////////////
             // Try to get the read VIO mutex
             /////////////////////////////////////
-            ink_release_assert(!(ProxyMutex *)vc->read_locked);
+            ink_release_assert(!vc->read_locked);
 #ifdef CLUSTER_TOMCAT
             if (!vc->read.vio.mutex ||
                 !MUTEX_TAKE_TRY_LOCK_FOR_SPIN(vc->read.vio.mutex, thread, vc->read.vio._cont, READ_LOCK_SPIN_COUNT))
@@ -617,7 +617,7 @@ ClusterHandler::build_initial_vector(bool read_flag)
             bool remote_write_fill = (vc->pending_remote_fill && vc->remote_write_block);
             // Sanity check, assert we have the lock
             if (!remote_write_fill) {
-              ink_assert((ProxyMutex *)vc->write_locked);
+              ink_assert(vc->write_locked);
             }
             if (vc_ok_write(vc) || remote_write_fill) {
               if (remote_write_fill) {
@@ -633,9 +633,10 @@ ClusterHandler::build_initial_vector(bool read_flag)
                 vc->write_list_bytes -= (int)s.msg.descriptor[i].length;
                 vc->write_bytes_in_transit += (int)s.msg.descriptor[i].length;
 
-                vc->write_list_tail = vc->write_list;
-                while (vc->write_list_tail && vc->write_list_tail->next)
-                  vc->write_list_tail = vc->write_list_tail->next;
+                vc->write_list_tail = vc->write_list.get();
+                while (vc->write_list_tail && vc->write_list_tail->next) {
+                  vc->write_list_tail = vc->write_list_tail->next.get();
+                }
               }
             } else {
               Debug(CL_NOTE, "faking cluster write data");
@@ -761,7 +762,7 @@ ClusterHandler::get_read_locks()
         continue;
       }
 
-      ink_assert(!(ProxyMutex *)vc->read_locked);
+      ink_assert(!vc->read_locked);
       vc->read_locked = vc->read.vio.mutex;
       if (vc->byte_bank_q.head ||
           !MUTEX_TAKE_TRY_LOCK_FOR_SPIN(vc->read.vio.mutex, thread, vc->read.vio._cont, READ_LOCK_SPIN_COUNT)) {
@@ -815,7 +816,7 @@ ClusterHandler::get_write_locks()
         //  already have a reference to the buffer
         continue;
       }
-      ink_assert(!(ProxyMutex *)vc->write_locked);
+      ink_assert(!vc->write_locked);
       vc->write_locked = vc->write.vio.mutex;
 #ifdef CLUSTER_TOMCAT
       if (vc->write_locked &&
@@ -1110,7 +1111,7 @@ ClusterHandler::update_channels_read()
           continue;
         }
 
-        if (!vc->pending_remote_fill && vc_ok_read(vc) && (!((ProxyMutex *)vc->read_locked) || vc->byte_bank_q.head)) {
+        if (!vc->pending_remote_fill && vc_ok_read(vc) && (!vc->read_locked || vc->byte_bank_q.head)) {
           //
           // Byte bank active or unable to acquire lock on VC.
           // Move data into the byte bank and attempt delivery
@@ -1120,7 +1121,7 @@ ClusterHandler::update_channels_read()
           add_to_byte_bank(vc);
 
         } else {
-          if (vc->pending_remote_fill || ((ProxyMutex *)vc->read_locked && vc_ok_read(vc))) {
+          if (vc->pending_remote_fill || (vc->read_locked && vc_ok_read(vc))) {
             vc->read_block->fill(len); // note bytes received
             if (!vc->pending_remote_fill) {
               vc->read.vio.buffer.writer()->append_block(vc->read_block->clone());
@@ -1146,9 +1147,8 @@ ClusterHandler::update_channels_read()
 // for message processing which cannot be done with a ET_CLUSTER thread.
 //
 int
-ClusterHandler::process_incoming_callouts(ProxyMutex *m)
+ClusterHandler::process_incoming_callouts(ProxyMutex *mutex)
 {
-  ProxyMutex *mutex = m;
   ink_hrtime now;
   //
   // Atomically dequeue all active requests from the external queue and
@@ -1308,7 +1308,7 @@ ClusterHandler::update_channels_partial_read()
             vc->read_block->fill(len); // note bytes received
 
             if (!vc->pending_remote_fill) {
-              if ((ProxyMutex *)vc->read_locked) {
+              if (vc->read_locked) {
                 Debug("cluster_vc_xfer", "Partial read, credit ch %d %p %d bytes", vc->channel, vc, len);
                 s->vio.buffer.writer()->append_block(vc->read_block->clone());
                 if (complete_channel_read(len, vc)) {
@@ -1358,7 +1358,7 @@ ClusterHandler::complete_channel_read(int len, ClusterVConnection *vc)
   if (vc->closed)
     return false; // No action if already closed
 
-  ink_assert((ProxyMutex *)s->vio.mutex == (ProxyMutex *)s->vio._cont->mutex);
+  ink_assert(s->vio.mutex == s->vio._cont->mutex);
 
   Debug("cluster_vc_xfer", "Complete read, credit ch %d %p %d bytes", vc->channel, vc, len);
   s->vio.ndone += len;
@@ -2316,12 +2316,12 @@ ClusterHandler::free_locks(bool read_flag, int i)
       ClusterVConnection *vc = channels[s.msg.descriptor[j].channel];
       if (VALID_CHANNEL(vc)) {
         if (read_flag) {
-          if ((ProxyMutex *)vc->read_locked) {
+          if (vc->read_locked) {
             MUTEX_UNTAKE_LOCK(vc->read.vio.mutex, thread);
             vc->read_locked = NULL;
           }
         } else {
-          if ((ProxyMutex *)vc->write_locked) {
+          if (vc->write_locked) {
             MUTEX_UNTAKE_LOCK(vc->write_locked, thread);
             vc->write_locked = NULL;
           }
@@ -2331,7 +2331,7 @@ ClusterHandler::free_locks(bool read_flag, int i)
                s.msg.descriptor[j].channel != CLUSTER_CONTROL_CHANNEL) {
       ClusterVConnection *vc = channels[s.msg.descriptor[j].channel];
       if (VALID_CHANNEL(vc)) {
-        if ((ProxyMutex *)vc->read_locked) {
+        if (vc->read_locked) {
           MUTEX_UNTAKE_LOCK(vc->read_locked, thread);
           vc->read_locked = NULL;
         }
diff --git a/iocore/cluster/ClusterHandlerBase.cc b/iocore/cluster/ClusterHandlerBase.cc
index a396f7c..cb7064c 100644
--- a/iocore/cluster/ClusterHandlerBase.cc
+++ b/iocore/cluster/ClusterHandlerBase.cc
@@ -53,7 +53,7 @@ ClusterCalloutContinuation::~ClusterCalloutContinuation()
 int
 ClusterCalloutContinuation::CalloutHandler(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */)
 {
-  return _ch->process_incoming_callouts(this->mutex);
+  return _ch->process_incoming_callouts(this->mutex.get());
 }
 
 /*************************************************************************/
@@ -67,8 +67,7 @@ ClusterControl::ClusterControl()
 void
 ClusterControl::real_alloc_data(int read_access, bool align_int32_on_non_int64_boundary)
 {
-  EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = this_ethread()->mutex;
 
   ink_assert(!data);
   if ((len + DATA_HDR + sizeof(int32_t)) <= DEFAULT_MAX_BUFFER_SIZE) {
@@ -316,11 +315,12 @@ ClusterState::build_do_io_vector()
     if (last_block) {
       last_block->next = block[n];
     }
-    last_block = block[n];
+    last_block = block[n].get();
     while (last_block->next) {
-      last_block = last_block->next;
+      last_block = last_block->next.get();
     }
   }
+
   mbuf->_writer = block[0];
   ink_release_assert(bytes_to_xfer == to_do);
   ink_assert(bytes_to_xfer == bytes_IOBufferBlockList(mbuf->_writer, !read_channel));
diff --git a/iocore/cluster/ClusterLib.cc b/iocore/cluster/ClusterLib.cc
index cd24208..e46e56f 100644
--- a/iocore/cluster/ClusterLib.cc
+++ b/iocore/cluster/ClusterLib.cc
@@ -104,13 +104,13 @@ clone_IOBufferBlockList(IOBufferBlock *b, int start_off, int n, IOBufferBlock **
   while (bsrc && nbytes) {
     // Skip zero length blocks
     if (!bsrc->read_avail()) {
-      bsrc = bsrc->next;
+      bsrc = bsrc->next.get();
       continue;
     }
 
     if (bclone_head) {
       bclone->next = bsrc->clone();
-      bclone = bclone->next;
+      bclone = bclone->next.get();
     } else {
       // Skip bytes already processed
       if (bytes_to_skip) {
@@ -125,7 +125,7 @@ clone_IOBufferBlockList(IOBufferBlock *b, int start_off, int n, IOBufferBlock **
 
         } else {
           // Skip entire block
-          bsrc = bsrc->next;
+          bsrc = bsrc->next.get();
           continue;
         }
       } else {
@@ -140,7 +140,7 @@ clone_IOBufferBlockList(IOBufferBlock *b, int start_off, int n, IOBufferBlock **
       bclone->fill(nbytes);
       nbytes = 0;
     }
-    bsrc = bsrc->next;
+    bsrc = bsrc->next.get();
   }
   ink_release_assert(!nbytes);
   *b_tail = bclone;
@@ -167,14 +167,15 @@ consume_IOBufferBlockList(IOBufferBlock *b, int64_t n)
 
       } else {
         // Consumed entire block
-        b_remainder = b->next;
+        b_remainder = b->next.get();
       }
       break;
 
     } else {
-      b = b->next;
+      b = b->next.get();
     }
   }
+
   ink_release_assert(nbytes == 0);
   return b_remainder; // return remaining blocks
 }
@@ -191,8 +192,9 @@ bytes_IOBufferBlockList(IOBufferBlock *b, int64_t read_avail_bytes)
     } else {
       n += b->write_avail();
     }
-    b = b->next;
+    b = b->next.get();
   }
+
   return n;
 }
 
diff --git a/iocore/cluster/ClusterLoadMonitor.cc b/iocore/cluster/ClusterLoadMonitor.cc
index 42af4cf..de3157d 100644
--- a/iocore/cluster/ClusterLoadMonitor.cc
+++ b/iocore/cluster/ClusterLoadMonitor.cc
@@ -218,7 +218,7 @@ void
 ClusterLoadMonitor::note_ping_response_time(ink_hrtime response_time, int sequence_number)
 {
 #ifdef CLUSTER_TOMCAT
-  ProxyMutex *mutex = this->ch->mutex; // hack for stats
+  ProxyMutex *mutex = this->ch->mutex.get(); // hack for stats
 #endif
 
   CLUSTER_SUM_DYN_STAT(CLUSTER_PING_TIME_STAT, response_time);
diff --git a/iocore/cluster/ClusterProcessor.cc b/iocore/cluster/ClusterProcessor.cc
index e8655b6..699d09c 100644
--- a/iocore/cluster/ClusterProcessor.cc
+++ b/iocore/cluster/ClusterProcessor.cc
@@ -53,8 +53,7 @@ ClusterProcessor::~ClusterProcessor()
 int
 ClusterProcessor::internal_invoke_remote(ClusterHandler *ch, int cluster_fn, void *data, int len, int options, void *cmsg)
 {
-  EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = this_ethread()->mutex;
   //
   // RPC facility for intercluster communication available to other
   //  subsystems.
diff --git a/iocore/cluster/ClusterVConnection.cc b/iocore/cluster/ClusterVConnection.cc
index 1fa0f64..f6e97d0 100644
--- a/iocore/cluster/ClusterVConnection.cc
+++ b/iocore/cluster/ClusterVConnection.cc
@@ -31,7 +31,7 @@ ClassAllocator<ClusterVConnection> clusterVCAllocator("clusterVCAllocator");
 ClassAllocator<ByteBankDescriptor> byteBankAllocator("byteBankAllocator");
 
 ByteBankDescriptor *
-ByteBankDescriptor::ByteBankDescriptor_alloc(IOBufferBlock *iob)
+ByteBankDescriptor::ByteBankDescriptor_alloc(Ptr<IOBufferBlock> &iob)
 {
   ByteBankDescriptor *b = byteBankAllocator.alloc();
   b->block = iob;
diff --git a/iocore/cluster/P_ClusterCache.h b/iocore/cluster/P_ClusterCache.h
index 06b6afa..f774bb5 100644
--- a/iocore/cluster/P_ClusterCache.h
+++ b/iocore/cluster/P_ClusterCache.h
@@ -454,12 +454,12 @@ class ByteBankDescriptor
 public:
   ByteBankDescriptor() {}
   IOBufferBlock *
-  get_block()
+  get_block() const
   {
-    return block;
+    return block.get();
   }
 
-  static ByteBankDescriptor *ByteBankDescriptor_alloc(IOBufferBlock *);
+  static ByteBankDescriptor *ByteBankDescriptor_alloc(Ptr<IOBufferBlock> &);
   static void ByteBankDescriptor_free(ByteBankDescriptor *);
 
 public:
diff --git a/iocore/cluster/P_ClusterCacheInternal.h b/iocore/cluster/P_ClusterCacheInternal.h
index b0b4d15..4437972 100644
--- a/iocore/cluster/P_ClusterCacheInternal.h
+++ b/iocore/cluster/P_ClusterCacheInternal.h
@@ -195,7 +195,7 @@ struct CacheContinuation : public Continuation {
   inline void
   setMsgBufferLen(int l, IOBufferData *b = 0)
   {
-    ink_assert(rw_buf_msg == 0);
+    ink_assert(!rw_buf_msg);
     ink_assert(rw_buf_msg_len == 0);
 
     rw_buf_msg = b;
@@ -211,7 +211,7 @@ struct CacheContinuation : public Continuation {
   inline void
   allocMsgBuffer()
   {
-    ink_assert(rw_buf_msg == 0);
+    ink_assert(!rw_buf_msg);
     ink_assert(rw_buf_msg_len);
     if (rw_buf_msg_len <= DEFAULT_MAX_BUFFER_SIZE) {
       rw_buf_msg = new_IOBufferData(buffer_size_to_index(rw_buf_msg_len, MAX_BUFFER_SIZE_INDEX));
@@ -228,9 +228,9 @@ struct CacheContinuation : public Continuation {
   }
 
   inline IOBufferData *
-  getMsgBufferIOBData()
+  getMsgBufferIOBData() const
   {
-    return rw_buf_msg;
+    return rw_buf_msg.get();
   }
 
   inline void
diff --git a/iocore/cluster/P_ClusterHandler.h b/iocore/cluster/P_ClusterHandler.h
index edf2d49..5dc169a 100644
--- a/iocore/cluster/P_ClusterHandler.h
+++ b/iocore/cluster/P_ClusterHandler.h
@@ -52,17 +52,19 @@ struct ClusterControl : public Continuation {
   Ptr<IOBufferBlock> iob_block;
 
   IOBufferBlock *
-  get_block()
+  get_block() const
   {
-    return iob_block;
+    return iob_block.get();
   }
+
   bool
-  fast_data()
+  fast_data() const
   {
     return (len <= MAX_FAST_CONTROL_MESSAGE);
   }
+
   bool
-  valid_alloc_data()
+  valid_alloc_data() const
   {
     return iob_block && real_data && data;
   }
@@ -240,9 +242,9 @@ struct ClusterMsg {
   }
 
   IOBufferBlock *
-  get_block()
+  get_block() const
   {
-    return iob_descriptor_block;
+    return iob_descriptor_block.get();
   }
 
   IOBufferBlock *
@@ -255,7 +257,7 @@ struct ClusterMsg {
     iob_descriptor_block->next = 0;
     iob_descriptor_block->fill(start_offset);
     iob_descriptor_block->consume(start_offset);
-    return iob_descriptor_block;
+    return iob_descriptor_block.get();
   }
 
   IOBufferBlock *
@@ -268,7 +270,7 @@ struct ClusterMsg {
     iob_descriptor_block->next = 0;
     iob_descriptor_block->fill(start_offset);
     iob_descriptor_block->consume(start_offset);
-    return iob_descriptor_block;
+    return iob_descriptor_block.get();
   }
 
   void
diff --git a/iocore/cluster/P_ClusterInternal.h b/iocore/cluster/P_ClusterInternal.h
index 844934f..1011eb0 100644
--- a/iocore/cluster/P_ClusterInternal.h
+++ b/iocore/cluster/P_ClusterInternal.h
@@ -493,9 +493,29 @@ extern void cluster_update_priority(ClusterHandler *, ClusterVConnection *, Clus
 extern void cluster_bump(ClusterHandler *, ClusterVConnectionBase *, ClusterVConnState *, int);
 
 extern IOBufferBlock *clone_IOBufferBlockList(IOBufferBlock *, int, int, IOBufferBlock **);
+
+static inline IOBufferBlock *
+clone_IOBufferBlockList(Ptr<IOBufferBlock> &src, int start_off, int b, IOBufferBlock **b_tail)
+{
+  return clone_IOBufferBlockList(src.get(), start_off, b, b_tail);
+}
+
 extern IOBufferBlock *consume_IOBufferBlockList(IOBufferBlock *, int64_t);
+
+static inline IOBufferBlock *
+consume_IOBufferBlockList(Ptr<IOBufferBlock> &b, int64_t n)
+{
+  return consume_IOBufferBlockList(b.get(), n);
+}
+
 extern int64_t bytes_IOBufferBlockList(IOBufferBlock *, int64_t);
 
+static inline int64_t
+bytes_IOBufferBlockList(Ptr<IOBufferBlock> &b, int64_t read_avail_bytes)
+{
+  return bytes_IOBufferBlockList(b.get(), read_avail_bytes);
+}
+
 // ClusterVConnection declarations
 extern void clusterVCAllocator_free(ClusterVConnection *vc);
 extern ClassAllocator<ClusterVConnection> clusterVCAllocator;

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

[trafficserver] 32/33: TS-4425: Hide Ptr internals.

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 523feded25bc46486f70e11203fe3b6c3a391103
Author: James Peach <jp...@apache.org>
AuthorDate: Sat May 7 14:13:22 2016 -0700

    TS-4425: Hide Ptr internals.
    
    Make the raw pointer member in Ptr<T> private and remove the implicit
    raw pointer conversion. This improves type safety and forces callers
    to declare when they circumvent the refcounting.
---
 lib/ts/Ptr.h       | 12 +++++++++++-
 lib/ts/test_Ptr.cc | 13 +++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/lib/ts/Ptr.h b/lib/ts/Ptr.h
index 3391608..8645fbf 100644
--- a/lib/ts/Ptr.h
+++ b/lib/ts/Ptr.h
@@ -100,6 +100,13 @@ private:
 ////////////////////////////////////////////////////////////////////////
 template <class T> class Ptr
 {
+  // https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Safe_bool.
+  typedef void (Ptr::*bool_type)() const;
+  void
+  this_type_does_not_support_comparisons() const
+  {
+  }
+
 public:
   explicit Ptr(T *p = 0);
   Ptr(const Ptr<T> &);
@@ -109,9 +116,9 @@ public:
   Ptr<T> &operator=(const Ptr<T> &);
   Ptr<T> &operator=(T *);
 
-  operator T *() const { return (m_ptr); }
   T *operator->() const { return (m_ptr); }
   T &operator*() const { return (*m_ptr); }
+  operator bool_type() const { return m_ptr ? &Ptr::this_type_does_not_support_comparisons : 0; }
   int
   operator==(const T *p)
   {
@@ -170,7 +177,10 @@ public:
     m_ptr = ptr;
   }
 
+private:
   T *m_ptr;
+
+  friend class CoreUtils;
 };
 
 template <typename T>
diff --git a/lib/ts/test_Ptr.cc b/lib/ts/test_Ptr.cc
index 3f7f826..9029416 100644
--- a/lib/ts/test_Ptr.cc
+++ b/lib/ts/test_Ptr.cc
@@ -85,6 +85,19 @@ REGRESSION_TEST(Ptr_refcount)(RegressionTest *t, int /* atype ATS_UNUSED */, int
   box.check(alive == 0, "refcounts dropped");
 }
 
+REGRESSION_TEST(Ptr_bool)(RegressionTest *t, int /* atype ATS_UNUSED */, int *pstatus)
+{
+  TestBox box(t, pstatus);
+  box = REGRESSION_TEST_PASSED;
+  unsigned alive = 0;
+
+  Ptr<PtrObject> none;
+  Ptr<PtrObject> some = make_ptr(new PtrObject(&alive));
+
+  box.check(!none, "Empty Ptr<T> is false");
+  box.check(some, "Non-empty Ptr<T> is true");
+}
+
 int
 main(int /* argc ATS_UNUSED */, char ** /* argv ATS_UNUSED */)
 {

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

[trafficserver] 18/33: TS-4425: Pass Ptr down through the Continuation constructor.

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 15ed8284d275688be60e56686aa3023e2163ed37
Author: James Peach <jp...@apache.org>
AuthorDate: Thu May 5 21:37:57 2016 -0700

    TS-4425: Pass Ptr<ProxyMutex> down through the Continuation constructor.
---
 iocore/eventsystem/I_VConnection.h | 1 +
 iocore/eventsystem/P_VConnection.h | 6 ++++++
 iocore/net/P_UnixNetVConnection.h  | 2 +-
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/iocore/eventsystem/I_VConnection.h b/iocore/eventsystem/I_VConnection.h
index effdc5a..e7fb12a 100644
--- a/iocore/eventsystem/I_VConnection.h
+++ b/iocore/eventsystem/I_VConnection.h
@@ -311,6 +311,7 @@ public:
   virtual void do_io_shutdown(ShutdownHowTo_t howto) = 0;
 
   VConnection(ProxyMutex *aMutex);
+  VConnection(Ptr<ProxyMutex> &aMutex);
 
   /** @deprecated */
   VIO *do_io(int op, Continuation *c = NULL, int64_t nbytes = INT64_MAX, MIOBuffer *buf = 0, int data = 0);
diff --git a/iocore/eventsystem/P_VConnection.h b/iocore/eventsystem/P_VConnection.h
index 4c75c42..f390a2a 100644
--- a/iocore/eventsystem/P_VConnection.h
+++ b/iocore/eventsystem/P_VConnection.h
@@ -61,6 +61,12 @@ VConnection::VConnection(ProxyMutex *aMutex) : Continuation(aMutex), lerrno(0)
 }
 
 TS_INLINE
+VConnection::VConnection(Ptr<ProxyMutex> &aMutex) : Continuation(aMutex), lerrno(0)
+{
+  SET_HANDLER(0);
+}
+
+TS_INLINE
 VConnection::~VConnection()
 {
 }
diff --git a/iocore/net/P_UnixNetVConnection.h b/iocore/net/P_UnixNetVConnection.h
index 9b10cbf..2443d7b 100644
--- a/iocore/net/P_UnixNetVConnection.h
+++ b/iocore/net/P_UnixNetVConnection.h
@@ -88,7 +88,7 @@ struct OOB_callback : public Continuation {
   Continuation *server_cont;
   int retry_OOB_send(int, Event *);
 
-  OOB_callback(ProxyMutex *m, NetVConnection *vc, Continuation *cont, char *buf, int len)
+  OOB_callback(Ptr<ProxyMutex> &m, NetVConnection *vc, Continuation *cont, char *buf, int len)
     : Continuation(m), data(buf), length(len), trigger(0)
   {
     server_vc = (UnixNetVConnection *)vc;

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

[trafficserver] 07/33: TS-4425: Add tests for Ptr.

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 2a47b9fa42823d3fa01b147297da850602dc5d2a
Author: James Peach <jp...@apache.org>
AuthorDate: Sat May 7 14:24:12 2016 -0700

    TS-4425: Add tests for Ptr<T>.
---
 lib/ts/Makefile.am |  7 +++-
 lib/ts/test_Ptr.cc | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 99 insertions(+), 1 deletion(-)

diff --git a/lib/ts/Makefile.am b/lib/ts/Makefile.am
index cb0e076..da6d149 100644
--- a/lib/ts/Makefile.am
+++ b/lib/ts/Makefile.am
@@ -21,7 +21,8 @@ library_includedir=$(includedir)/ts
 library_include_HEADERS = apidefs.h
 
 noinst_PROGRAMS = mkdfa CompileParseRules
-check_PROGRAMS = test_arena test_atomic test_freelist test_geometry test_List test_Map test_Regex test_PriorityQueue test_Vec test_X509HostnameValidator
+check_PROGRAMS = test_arena test_atomic test_freelist test_geometry test_List test_Map test_Regex test_PriorityQueue test_Vec test_X509HostnameValidator test_Ptr
+
 TESTS = $(check_PROGRAMS)
 
 AM_CPPFLAGS = -I$(top_srcdir)/lib
@@ -235,6 +236,10 @@ test_X509HostnameValidator_SOURCES = test_X509HostnameValidator.cc
 test_X509HostnameValidator_LDADD = libtsutil.la @LIBTCL@ @LIBPCRE@ @OPENSSL_LIBS@
 test_X509HostnameValidator_LDFLAGS = @EXTRA_CXX_LDFLAGS@ @LIBTOOL_LINK_FLAGS@
 
+test_Ptr_SOURCES = test_Ptr.cc
+test_Ptr_LDADD = libtsutil.la @LIBTCL@ @LIBPCRE@
+test_Ptr_LDFLAGS = @EXTRA_CXX_LDFLAGS@ @LIBTOOL_LINK_FLAGS@
+
 CompileParseRules_SOURCES = CompileParseRules.cc
 
 test:: $(TESTS)
diff --git a/lib/ts/test_Ptr.cc b/lib/ts/test_Ptr.cc
new file mode 100644
index 0000000..3f7f826
--- /dev/null
+++ b/lib/ts/test_Ptr.cc
@@ -0,0 +1,93 @@
+/*
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+*/
+
+#include "ts/Ptr.h"
+#include "ts/TestBox.h"
+
+struct PtrObject : RefCountObj {
+  PtrObject(unsigned *_c) : count(_c) { ++(*count); }
+  ~PtrObject() { --(*count); }
+  unsigned *count;
+};
+
+REGRESSION_TEST(Ptr_detach)(RegressionTest *t, int /* atype ATS_UNUSED */, int *pstatus)
+{
+  TestBox box(t, pstatus);
+  box = REGRESSION_TEST_PASSED;
+  unsigned alive = 0;
+
+  Ptr<PtrObject> p1 = make_ptr(new PtrObject(&alive));
+  PtrObject *p2 = p1.detach();
+
+  box.check(p1.get() == NULL, "Ptr<T>::detach NULLs the stored pointer");
+  box.check(p2->refcount() == 1, "Ptr<T>::detach preserves the refcount");
+
+  // Note that there's no symmetric reattach.
+  p1 = p2;
+  box.check(p2->refcount() == 2, "reattaching increments the refcount again");
+  p1->refcount_dec();
+}
+
+REGRESSION_TEST(Ptr_clear)(RegressionTest *t, int /* atype ATS_UNUSED */, int *pstatus)
+{
+  TestBox box(t, pstatus);
+  box = REGRESSION_TEST_PASSED;
+  unsigned alive = 0;
+
+  Ptr<PtrObject> p1 = make_ptr(new PtrObject(&alive));
+  box.check(alive == 1, "we have a live object");
+  p1.clear();
+  box.check(p1.get() == NULL, "Ptr<T>::clear NULLs the pointer");
+  box.check(alive == 0, "Ptr<T>::clear drops the refcount");
+
+  p1 = make_ptr(new PtrObject(&alive));
+  box.check(alive == 1, "we have a live object");
+  p1 = 0;
+  box.check(alive == 0, "assigning NULL drops the refcount");
+}
+
+REGRESSION_TEST(Ptr_refcount)(RegressionTest *t, int /* atype ATS_UNUSED */, int *pstatus)
+{
+  TestBox box(t, pstatus);
+  box = REGRESSION_TEST_PASSED;
+  unsigned alive = 0;
+
+  {
+    Ptr<PtrObject> p1 = make_ptr(new PtrObject(&alive));
+
+    box.check(p1->refcount() == 1, "initial refcount is 1");
+
+    Ptr<PtrObject> p2(p1);
+    box.check(p1->refcount() == 2, "initial refcount is 1");
+
+    Ptr<PtrObject> p3 = p1;
+  }
+
+  // Everything goes out of scope, so the refcounts should drop to zero.
+  box.check(alive == 0, "refcounts dropped");
+}
+
+int
+main(int /* argc ATS_UNUSED */, char ** /* argv ATS_UNUSED */)
+{
+  RegressionTest::run();
+  return RegressionTest::final_status == REGRESSION_TEST_PASSED ? 0 : 1;
+}

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

[trafficserver] 19/33: TS-4425: Switch SSLNetVConnection over to Ptr::get().

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 1a178afcab7538192e65ab3c0313619b40575f4d
Author: James Peach <jp...@apache.org>
AuthorDate: Thu May 5 22:16:10 2016 -0700

    TS-4425: Switch SSLNetVConnection over to Ptr::get().
---
 iocore/net/SSLNetVConnection.cc | 48 +++++++++++++++++------------------------
 1 file changed, 20 insertions(+), 28 deletions(-)

diff --git a/iocore/net/SSLNetVConnection.cc b/iocore/net/SSLNetVConnection.cc
index 5a96db4..5aa577a 100644
--- a/iocore/net/SSLNetVConnection.cc
+++ b/iocore/net/SSLNetVConnection.cc
@@ -76,13 +76,10 @@ public:
       This takes the secondary @a mutex and the @a target continuation
       to invoke, along with the arguments for that invocation.
   */
-  ContWrapper(ProxyMutex *mutex ///< Mutex for this continuation (primary lock).
-              ,
-              Continuation *target ///< "Real" continuation we want to call.
-              ,
-              int eventId = EVENT_IMMEDIATE ///< Event ID for invocation of @a target.
-              ,
-              void *edata = 0 ///< Data for invocation of @a target.
+  ContWrapper(ProxyMutex *mutex,             ///< Mutex for this continuation (primary lock).
+              Continuation *target,          ///< "Real" continuation we want to call.
+              int eventId = EVENT_IMMEDIATE, ///< Event ID for invocation of @a target.
+              void *edata = 0                ///< Data for invocation of @a target.
               )
     : Continuation(mutex), _target(target), _eventId(eventId), _edata(edata)
   {
@@ -116,13 +113,10 @@ public:
       instance but simply calls the @a target.
   */
   static void
-  wrap(ProxyMutex *mutex ///< Mutex for this continuation (primary lock).
-       ,
-       Continuation *target ///< "Real" continuation we want to call.
-       ,
-       int eventId = EVENT_IMMEDIATE ///< Event ID for invocation of @a target.
-       ,
-       void *edata = 0 ///< Data for invocation of @a target.
+  wrap(ProxyMutex *mutex,             ///< Mutex for this continuation (primary lock).
+       Continuation *target,          ///< "Real" continuation we want to call.
+       int eventId = EVENT_IMMEDIATE, ///< Event ID for invocation of @a target.
+       void *edata = 0                ///< Data for invocation of @a target.
        )
   {
     EThread *eth = this_ethread();
@@ -209,7 +203,7 @@ ssl_read_from_net(SSLNetVConnection *sslvc, EThread *lthread, int64_t &ret)
   bool trace = sslvc->getSSLTrace();
   Debug("ssl", "trace=%s", trace ? "TRUE" : "FALSE");
 
-  for (bytes_read = 0; (b != 0) && (sslErr == SSL_ERROR_NONE); b = b->next) {
+  for (bytes_read = 0; (b != 0) && (sslErr == SSL_ERROR_NONE); b = b->next.get()) {
     block_write_avail = b->write_avail();
 
     Debug("ssl", "[SSL_NetVConnection::ssl_read_from_net] b->write_avail()=%" PRId64, block_write_avail);
@@ -341,7 +335,7 @@ SSLNetVConnection::read_raw_data()
 
   // read data
   int64_t rattempted = 0, total_read = 0;
-  int niov = 0;
+  unsigned niov = 0;
   IOVec tiovec[NET_MAX_IOV];
   if (toread) {
     IOBufferBlock *b = this->handShakeBuffer->first_write_block();
@@ -361,14 +355,13 @@ SSLNetVConnection::read_raw_data()
           if (a >= togo)
             break;
         }
-        b = b->next;
+        b = b->next.get();
       }
 
-      if (niov == 1) {
-        r = socketManager.read(this->con.fd, tiovec[0].iov_base, tiovec[0].iov_len);
-      } else {
-        r = socketManager.readv(this->con.fd, &tiovec[0], niov);
-      }
+      ink_assert(niov > 0);
+      ink_assert(niov < countof(tiovec));
+      r = socketManager.readv(this->con.fd, &tiovec[0], niov);
+
       NET_INCREMENT_DYN_STAT(net_calls_to_read_stat);
       total_read += rattempted;
     } while (rattempted && r == rattempted && total_read < toread);
@@ -607,7 +600,7 @@ SSLNetVConnection::net_read_io(NetHandler *nh, EThread *lthread)
     break;
   case SSL_WRITE_WOULD_BLOCK:
   case SSL_READ_WOULD_BLOCK:
-    if (lock.get_mutex() != s->vio.mutex.m_ptr) {
+    if (lock.get_mutex() != s->vio.mutex.get()) {
       Debug("ssl", "ssl_read_from_net, mutex switched");
       if (ret == SSL_READ_WOULD_BLOCK)
         readReschedule(nh);
@@ -658,7 +651,6 @@ int64_t
 SSLNetVConnection::load_buffer_and_write(int64_t towrite, int64_t &wattempted, int64_t &total_written, MIOBufferAccessor &buf,
                                          int &needs)
 {
-  ProxyMutex *mutex = this_ethread()->mutex;
   int64_t r = 0;
   int64_t l = 0;
   uint32_t dynamic_tls_record_size = 0;
@@ -666,7 +658,7 @@ SSLNetVConnection::load_buffer_and_write(int64_t towrite, int64_t &wattempted, i
 
   // XXX Rather than dealing with the block directly, we should use the IOBufferReader API.
   int64_t offset = buf.reader()->start_offset;
-  IOBufferBlock *b = buf.reader()->block;
+  IOBufferBlock *b = buf.reader()->block.get();
 
   // Dynamic TLS record sizing
   ink_hrtime now = 0;
@@ -695,7 +687,7 @@ SSLNetVConnection::load_buffer_and_write(int64_t towrite, int64_t &wattempted, i
     l -= offset;
     if (l <= 0) {
       offset = -l;
-      b = b->next;
+      b = b->next.get();
       continue;
     }
     // check if to amount to write exceeds that in this buffer
@@ -750,7 +742,7 @@ SSLNetVConnection::load_buffer_and_write(int64_t towrite, int64_t &wattempted, i
     if (l == orig_l) {
       // on to the next block
       offset = 0;
-      b = b->next;
+      b = b->next.get();
     } else {
       offset += l;
     }
@@ -1043,7 +1035,7 @@ SSLNetVConnection::sslServerHandShakeEvent(int &err)
         sslPreAcceptHookState = SSL_HOOKS_DONE;
       } else {
         sslPreAcceptHookState = SSL_HOOKS_ACTIVE;
-        ContWrapper::wrap(mutex, curHook->m_cont, TS_EVENT_VCONN_PRE_ACCEPT, this);
+        ContWrapper::wrap(mutex.get(), curHook->m_cont, TS_EVENT_VCONN_PRE_ACCEPT, this);
         return SSL_WAIT_FOR_HOOK;
       }
     } else { // waiting for hook to complete

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

[trafficserver] 05/33: TS-4425: Add Ptr::detach() to detach a RefCountObj from its holder.

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 369ab4ce6eb974e12bbc8fdd8ae05115e7cadc59
Author: James Peach <jp...@apache.org>
AuthorDate: Sat May 7 09:12:09 2016 -0700

    TS-4425: Add Ptr::detach() to detach a RefCountObj from its holder.
---
 lib/ts/Ptr.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lib/ts/Ptr.h b/lib/ts/Ptr.h
index 56fc4cb..d1288fa 100644
--- a/lib/ts/Ptr.h
+++ b/lib/ts/Ptr.h
@@ -151,6 +151,16 @@ public:
     return static_cast<RefCountObj *>(m_ptr);
   }
 
+  // Return the stored pointer, storing NULL instead. Do not increment
+  // the refcount; the caller is now responsible for owning the RefCountObj.
+  T *
+  detach()
+  {
+    T *tmp = m_ptr;
+    m_ptr = NULL;
+    return tmp;
+  }
+
   T *m_ptr;
 };
 

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

[trafficserver] 22/33: TS-4425: Switch RamCacheCLFUS over to Ptr::get().

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 5841b5c20532f9608c2ad0689affbb2971599856
Author: James Peach <jp...@apache.org>
AuthorDate: Thu May 5 22:34:20 2016 -0700

    TS-4425: Switch RamCacheCLFUS over to Ptr::get().
---
 iocore/cache/RamCacheCLFUS.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/iocore/cache/RamCacheCLFUS.cc b/iocore/cache/RamCacheCLFUS.cc
index c186214..7aa3375 100644
--- a/iocore/cache/RamCacheCLFUS.cc
+++ b/iocore/cache/RamCacheCLFUS.cc
@@ -302,10 +302,10 @@ RamCacheCLFUS::get(INK_MD5 *key, Ptr<IOBufferData> *ret_data, uint32_t auxkey1,
           }
           (*ret_data) = data;
         } else {
-          IOBufferData *data = e->data;
+          IOBufferData *data = e->data.get();
           if (e->flag_bits.copy) {
             data = new_IOBufferData(iobuffer_size_to_index(e->len, MAX_BUFFER_SIZE_INDEX), MEMALIGNED);
-            memcpy(data->data(), e->data->data(), e->len);
+            ::memcpy(data->data(), e->data->data(), e->len);
           }
           (*ret_data) = data;
         }

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

[trafficserver] 27/33: TS-4425: Switch iocore/hostdb and iocore/utils to Ptr::get().

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 23cb70f2db31026541705d635df243545212dfb7
Author: James Peach <jp...@apache.org>
AuthorDate: Sat May 7 13:32:30 2016 -0700

    TS-4425: Switch iocore/hostdb and iocore/utils to Ptr::get().
---
 iocore/hostdb/HostDB.cc           | 25 ++++++++++---------------
 iocore/hostdb/MultiCache.cc       |  4 ++--
 iocore/hostdb/P_MultiCache.h      |  3 ++-
 iocore/utils/OneWayMultiTunnel.cc |  4 ++--
 iocore/utils/OneWayTunnel.cc      |  8 ++++----
 5 files changed, 20 insertions(+), 24 deletions(-)

diff --git a/iocore/hostdb/HostDB.cc b/iocore/hostdb/HostDB.cc
index b83ddff..2eabe2a 100644
--- a/iocore/hostdb/HostDB.cc
+++ b/iocore/hostdb/HostDB.cc
@@ -565,8 +565,9 @@ HostDBContinuation::refresh_MD5()
   md5.refresh();
   // Update the mutex if it's from the bucket.
   // Some call sites modify this after calling @c init so need to check.
-  if (old_bucket_mutex == mutex)
+  if (mutex.get() == old_bucket_mutex) {
     mutex = hostDB.lock_for_bucket((int)(fold_md5(md5.hash) % hostDB.buckets));
+  }
 }
 
 static bool
@@ -1141,7 +1142,7 @@ HostDBProcessor::setby_srv(const char *hostname, int len, const char *target, Ho
 int
 HostDBContinuation::setbyEvent(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */)
 {
-  HostDBInfo *r = probe(mutex, md5, false);
+  HostDBInfo *r = probe(mutex.get(), md5, false);
 
   if (r)
     do_setby(r, &app, md5.host_name, md5.ip, is_srv());
@@ -1232,7 +1233,7 @@ HostDBContinuation::removeEvent(int /* event ATS_UNUSED */, Event *e)
 {
   Continuation *cont = action.continuation;
 
-  MUTEX_TRY_LOCK(lock, cont ? (ProxyMutex *)cont->mutex : (ProxyMutex *)NULL, e->ethread);
+  MUTEX_TRY_LOCK(lock, cont ? cont->mutex.get() : (ProxyMutex *)NULL, e->ethread);
   if (!lock.is_locked()) {
     e->schedule_in(HOST_DB_RETRY_PERIOD);
     return EVENT_CONT;
@@ -1242,7 +1243,7 @@ HostDBContinuation::removeEvent(int /* event ATS_UNUSED */, Event *e)
       if (cont)
         cont->handleEvent(EVENT_HOST_DB_IP_REMOVED, (void *)NULL);
     } else {
-      HostDBInfo *r = probe(mutex, md5, false);
+      HostDBInfo *r = probe(mutex.get(), md5, false);
       bool res = (remove_round_robin(r, md5.host_name, md5.ip) ? true : false);
       if (cont)
         cont->handleEvent(EVENT_HOST_DB_IP_REMOVED, res ? static_cast<void *>(&md5.ip) : static_cast<void *>(NULL));
@@ -1455,7 +1456,7 @@ HostDBContinuation::dnsEvent(int event, HostEnt *e)
     ttl = failed ? 0 : e->ttl / 60;
     int ttl_seconds = failed ? 0 : e->ttl; // ebalsa: moving to second accuracy
 
-    HostDBInfo *old_r = probe(mutex, md5, true);
+    HostDBInfo *old_r = probe(mutex.get(), md5, true);
     HostDBInfo old_info;
     if (old_r)
       old_info = *old_r;
@@ -1912,7 +1913,7 @@ HostDBContinuation::probeEvent(int /* event ATS_UNUSED */, Event *e)
   if (!force_dns) {
     // Do the probe
     //
-    HostDBInfo *r = probe(mutex, md5, false);
+    HostDBInfo *r = probe(mutex.get(), md5, false);
 
     if (r)
       HOSTDB_INCREMENT_DYN_STAT(hostdb_total_hits_stat);
@@ -2794,18 +2795,12 @@ HostDBFileContinuation::destroy()
 // globals.
 int HostDBFileUpdateActive = 0;
 
-// Actual ordering doesn't matter as long as it's consistent.
-bool
-CmpMD5(INK_MD5 const &lhs, INK_MD5 const &rhs)
-{
-  return lhs[0] < rhs[0] || (lhs[0] == rhs[0] && lhs[1] < rhs[1]);
-}
-
-void
-ParseHostLine(RefCountedHostsFileMap *map, char *l)
+static void
+ParseHostLine(Ptr<RefCountedHostsFileMap> &map, char *l)
 {
   Tokenizer elts(" \t");
   int n_elts = elts.Initialize(l, SHARE_TOKS);
+
   // Elements should be the address then a list of host names.
   // Don't use RecHttpLoadIp because the address *must* be literal.
   IpAddr ip;
diff --git a/iocore/hostdb/MultiCache.cc b/iocore/hostdb/MultiCache.cc
index 2e6951a..a3201a1 100644
--- a/iocore/hostdb/MultiCache.cc
+++ b/iocore/hostdb/MultiCache.cc
@@ -1046,7 +1046,7 @@ struct MultiCacheSync : public Continuation {
   }
 
   MultiCacheSync(Continuation *acont, MultiCacheBase *amc)
-    : Continuation(amc->locks[0]), partition(0), mc(amc), cont(acont), before_used(0)
+    : Continuation(amc->locks[0].get()), partition(0), mc(amc), cont(acont), before_used(0)
   {
     mutex = mc->locks[partition];
     SET_HANDLER((MCacheSyncHandler)&MultiCacheSync::heapEvent);
@@ -1159,7 +1159,7 @@ struct MultiCacheHeapGC : public Continuation {
   }
 
   MultiCacheHeapGC(Continuation *acont, MultiCacheBase *amc)
-    : Continuation(amc->locks[0]), cont(acont), mc(amc), partition(0), n_offsets(0)
+    : Continuation(amc->locks[0].get()), cont(acont), mc(amc), partition(0), n_offsets(0)
   {
     SET_HANDLER((MCacheHeapGCHandler)&MultiCacheHeapGC::startEvent);
     offset_table = (OffsetTable *)ats_malloc(sizeof(OffsetTable) *
diff --git a/iocore/hostdb/P_MultiCache.h b/iocore/hostdb/P_MultiCache.h
index adc1ad3..b79f7f2 100644
--- a/iocore/hostdb/P_MultiCache.h
+++ b/iocore/hostdb/P_MultiCache.h
@@ -321,8 +321,9 @@ struct MultiCacheBase : public MultiCacheHeader {
   ProxyMutex *
   lock_for_bucket(int bucket)
   {
-    return locks[partition_of_bucket(bucket)];
+    return locks[partition_of_bucket(bucket)].get();
   }
+
   uint64_t
   make_tag(uint64_t folded_md5)
   {
diff --git a/iocore/utils/OneWayMultiTunnel.cc b/iocore/utils/OneWayMultiTunnel.cc
index fc28305..868a712 100644
--- a/iocore/utils/OneWayMultiTunnel.cc
+++ b/iocore/utils/OneWayMultiTunnel.cc
@@ -63,7 +63,7 @@ OneWayMultiTunnel::init(VConnection *vcSource, VConnection **vcTargets, int n_vc
                         bool aclose_targets,                 /* = false */
                         Transform_fn aManipulate_fn, int water_mark)
 {
-  mutex = aCont ? (ProxyMutex *)aCont->mutex : new_ProxyMutex();
+  mutex = aCont ? aCont->mutex : make_ptr(new_ProxyMutex());
   cont = aCont;
   manipulate_fn = aManipulate_fn;
   close_source = aclose_source;
@@ -108,7 +108,7 @@ void
 OneWayMultiTunnel::init(Continuation *aCont, VIO *SourceVio, VIO **TargetVios, int n_TargetVios, bool aclose_source,
                         bool aclose_targets)
 {
-  mutex = aCont ? (ProxyMutex *)aCont->mutex : new_ProxyMutex();
+  mutex = aCont ? aCont->mutex : make_ptr(new_ProxyMutex());
   cont = aCont;
   single_buffer = true;
   manipulate_fn = 0;
diff --git a/iocore/utils/OneWayTunnel.cc b/iocore/utils/OneWayTunnel.cc
index d286a57..4e42eb6 100644
--- a/iocore/utils/OneWayTunnel.cc
+++ b/iocore/utils/OneWayTunnel.cc
@@ -107,7 +107,7 @@ OneWayTunnel::~OneWayTunnel()
 }
 
 OneWayTunnel::OneWayTunnel(Continuation *aCont, Transform_fn aManipulate_fn, bool aclose_source, bool aclose_target)
-  : Continuation(aCont ? (ProxyMutex *)aCont->mutex : new_ProxyMutex()),
+  : Continuation(aCont ? aCont->mutex.get() : new_ProxyMutex()),
     cont(aCont),
     manipulate_fn(aManipulate_fn),
     n_connections(2),
@@ -126,7 +126,7 @@ OneWayTunnel::init(VConnection *vcSource, VConnection *vcTarget, Continuation *a
                    int64_t nbytes, bool asingle_buffer, bool aclose_source, bool aclose_target, Transform_fn aManipulate_fn,
                    int water_mark)
 {
-  mutex = aCont ? (ProxyMutex *)aCont->mutex : (aMutex ? aMutex : new_ProxyMutex());
+  mutex = aCont ? aCont->mutex.get() : (aMutex ? aMutex : new_ProxyMutex());
   cont = aMutex ? NULL : aCont;
   single_buffer = asingle_buffer;
   manipulate_fn = aManipulate_fn;
@@ -170,7 +170,7 @@ OneWayTunnel::init(VConnection *vcSource, VConnection *vcTarget, Continuation *a
                    bool aclose_source, bool aclose_target)
 {
   (void)vcSource;
-  mutex = aCont ? (ProxyMutex *)aCont->mutex : new_ProxyMutex();
+  mutex = aCont ? aCont->mutex : make_ptr(new_ProxyMutex());
   cont = aCont;
   single_buffer = true;
   manipulate_fn = 0;
@@ -196,7 +196,7 @@ OneWayTunnel::init(VConnection *vcSource, VConnection *vcTarget, Continuation *a
 void
 OneWayTunnel::init(Continuation *aCont, VIO *SourceVio, VIO *TargetVio, bool aclose_source, bool aclose_target)
 {
-  mutex = aCont ? (ProxyMutex *)aCont->mutex : new_ProxyMutex();
+  mutex = aCont ? aCont->mutex : make_ptr(new_ProxyMutex());
   cont = aCont;
   single_buffer = true;
   manipulate_fn = 0;

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

[trafficserver] 17/33: TS-4425: Switch P_UnixEthread.h over to Ptr::get().

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit d700ba766e00f5f33bb13865e8f356d2e78d4456
Author: James Peach <jp...@apache.org>
AuthorDate: Thu May 5 21:25:53 2016 -0700

    TS-4425: Switch P_UnixEthread.h over to Ptr::get().
---
 iocore/eventsystem/P_UnixEThread.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/iocore/eventsystem/P_UnixEThread.h b/iocore/eventsystem/P_UnixEThread.h
index f884f4b..e2356a1 100644
--- a/iocore/eventsystem/P_UnixEThread.h
+++ b/iocore/eventsystem/P_UnixEThread.h
@@ -97,7 +97,7 @@ EThread::schedule(Event *e, bool fast_signal)
     e->mutex = e->continuation->mutex;
   else
     e->mutex = e->continuation->mutex = e->ethread->mutex;
-  ink_assert(e->mutex.m_ptr);
+  ink_assert(e->mutex.get());
   EventQueueExternal.enqueue(e, fast_signal);
   return e;
 }
@@ -145,7 +145,7 @@ EThread::schedule_local(Event *e)
     ink_assert(tt == DEDICATED);
     return eventProcessor.schedule(e, ET_CALL);
   }
-  if (!e->mutex.m_ptr) {
+  if (!e->mutex) {
     e->ethread = this;
     e->mutex = e->continuation->mutex;
   } else {

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

[trafficserver] 03/33: TS-4425: Remove unused Ptr::to_ptr() method.

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 0660bc53daef5c80484042c2192cdf2876acd5ec
Author: James Peach <jp...@apache.org>
AuthorDate: Wed May 4 22:02:35 2016 -0700

    TS-4425: Remove unused Ptr::to_ptr() method.
---
 lib/ts/Ptr.h | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/lib/ts/Ptr.h b/lib/ts/Ptr.h
index b7b86be..dd87657 100644
--- a/lib/ts/Ptr.h
+++ b/lib/ts/Ptr.h
@@ -109,17 +109,6 @@ public:
   Ptr<T> &operator=(const Ptr<T> &);
   Ptr<T> &operator=(T *);
 
-  T *
-  to_ptr()
-  {
-    if (m_ptr && m_ptr->m_refcount == 1) {
-      T *ptr = m_ptr;
-      m_ptr = 0;
-      ptr->m_refcount = 0;
-      return ptr;
-    }
-    return 0;
-  }
   operator T *() const { return (m_ptr); }
   T *operator->() const { return (m_ptr); }
   T &operator*() const { return (*m_ptr); }
@@ -128,16 +117,19 @@ public:
   {
     return (m_ptr == p);
   }
+
   int
   operator==(const Ptr<T> &p)
   {
     return (m_ptr == p.m_ptr);
   }
+
   int
   operator!=(const T *p)
   {
     return (m_ptr != p);
   }
+
   int
   operator!=(const Ptr<T> &p)
   {
@@ -208,6 +200,7 @@ Ptr<T>::operator=(T *p)
 
   return (*this);
 }
+
 template <class T>
 inline void
 Ptr<T>::clear()
@@ -218,6 +211,7 @@ Ptr<T>::clear()
     m_ptr = NULL;
   }
 }
+
 template <class T>
 inline Ptr<T> &
 Ptr<T>::operator=(const Ptr<T> &src)

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

[trafficserver] 28/33: TS-4425: Switch proxy/logging over to Ptr::get().

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 8faceca2c67b45977df2e42c257b3b5e41a95746
Author: James Peach <jp...@apache.org>
AuthorDate: Sat May 7 13:41:18 2016 -0700

    TS-4425: Switch proxy/logging over to Ptr::get().
---
 proxy/logging/Log.cc       | 33 +++++++++++++++++++--------------
 proxy/logging/LogField.cc  |  4 ++--
 proxy/logging/LogFilter.cc |  2 +-
 proxy/logging/LogHost.cc   |  6 ++++--
 proxy/logging/LogHost.h    |  3 ++-
 proxy/logging/LogObject.h  |  2 +-
 6 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/proxy/logging/Log.cc b/proxy/logging/Log.cc
index 6e481ca..636610a 100644
--- a/proxy/logging/Log.cc
+++ b/proxy/logging/Log.cc
@@ -99,6 +99,13 @@ RecRawStatBlock *log_rsb;
 LogConfig *Log::config = NULL;
 static unsigned log_configid = 0;
 
+// Downcast from a Ptr<LogFieldAliasTable> to a Ptr<LogFieldAliasMap>.
+static Ptr<LogFieldAliasMap>
+make_alias_map(Ptr<LogFieldAliasTable> &table)
+{
+  return make_ptr(static_cast<LogFieldAliasMap *>(table.get()));
+}
+
 void
 Log::change_configuration()
 {
@@ -502,7 +509,7 @@ Log::init_fields()
   finish_status_map->init(N_LOG_FINISH_CODE_TYPES, LOG_FINISH_FIN, "FIN", LOG_FINISH_INTR, "INTR", LOG_FINISH_TIMEOUT, "TIMEOUT");
 
   field = new LogField("client_finish_status_code", "cfsc", LogField::sINT, &LogAccess::marshal_client_finish_status_code,
-                       &LogAccess::unmarshal_finish_status, (Ptr<LogFieldAliasMap>)finish_status_map);
+                       &LogAccess::unmarshal_finish_status, make_alias_map(finish_status_map));
   global_field_list.add(field, false);
   ink_hash_table_insert(field_symbol_hash, "cfsc", field);
 
@@ -538,7 +545,7 @@ Log::init_fields()
   ink_hash_table_insert(field_symbol_hash, "pshl", field);
 
   field = new LogField("proxy_finish_status_code", "pfsc", LogField::sINT, &LogAccess::marshal_proxy_finish_status_code,
-                       &LogAccess::unmarshal_finish_status, (Ptr<LogFieldAliasMap>)finish_status_map);
+                       &LogAccess::unmarshal_finish_status, make_alias_map(finish_status_map));
   global_field_list.add(field, false);
   ink_hash_table_insert(field_symbol_hash, "pfsc", field);
 
@@ -579,12 +586,12 @@ Log::init_fields()
                            SQUID_MISS_CACHE_BYPASS, "MISS_CACHE_BYPASS", SQUID_HIT_MISS_INVALID_ASSIGNED_CODE, "INVALID_CODE");
 
   field = new LogField("cache_result_code", "crc", LogField::sINT, &LogAccess::marshal_cache_result_code,
-                       &LogAccess::unmarshal_cache_code, (Ptr<LogFieldAliasMap>)cache_code_map);
+                       &LogAccess::unmarshal_cache_code, make_alias_map(cache_code_map));
   global_field_list.add(field, false);
   ink_hash_table_insert(field_symbol_hash, "crc", field);
 
   field = new LogField("cache_hit_miss", "chm", LogField::sINT, &LogAccess::marshal_cache_hit_miss,
-                       &LogAccess::unmarshal_cache_hit_miss, (Ptr<LogFieldAliasMap>)cache_hit_miss_map);
+                       &LogAccess::unmarshal_cache_hit_miss, make_alias_map(cache_hit_miss_map));
   global_field_list.add(field, false);
   ink_hash_table_insert(field_symbol_hash, "chm", field);
 
@@ -635,7 +642,7 @@ Log::init_fields()
     "INVALID_ASSIGNED_CODE");
 
   field = new LogField("proxy_hierarchy_route", "phr", LogField::sINT, &LogAccess::marshal_proxy_hierarchy_route,
-                       &LogAccess::unmarshal_hierarchy, (Ptr<LogFieldAliasMap>)hierarchy_map);
+                       &LogAccess::unmarshal_hierarchy, make_alias_map(hierarchy_map));
   global_field_list.add(field, false);
   ink_hash_table_insert(field_symbol_hash, "phr", field);
 
@@ -750,12 +757,12 @@ Log::init_fields()
   cache_write_code_map->init(N_LOG_CACHE_WRITE_TYPES, LOG_CACHE_WRITE_NONE, "-", LOG_CACHE_WRITE_LOCK_MISSED, "WL_MISS",
                              LOG_CACHE_WRITE_LOCK_ABORTED, "INTR", LOG_CACHE_WRITE_ERROR, "ERR", LOG_CACHE_WRITE_COMPLETE, "FIN");
   field = new LogField("cache_write_result", "cwr", LogField::sINT, &LogAccess::marshal_cache_write_code,
-                       &LogAccess::unmarshal_cache_write_code, (Ptr<LogFieldAliasMap>)cache_write_code_map);
+                       &LogAccess::unmarshal_cache_write_code, make_alias_map(cache_write_code_map));
   global_field_list.add(field, false);
   ink_hash_table_insert(field_symbol_hash, "cwr", field);
 
   field = new LogField("cache_write_transform_result", "cwtr", LogField::sINT, &LogAccess::marshal_cache_write_transform_code,
-                       &LogAccess::unmarshal_cache_write_code, (Ptr<LogFieldAliasMap>)cache_write_code_map);
+                       &LogAccess::unmarshal_cache_write_code, make_alias_map(cache_write_code_map));
   global_field_list.add(field, false);
   ink_hash_table_insert(field_symbol_hash, "cwtr", field);
 
@@ -788,7 +795,7 @@ Log::init_fields()
   Ptr<LogFieldAliasTable> entry_type_map = make_ptr(new LogFieldAliasTable);
   entry_type_map->init(N_LOG_ENTRY_TYPES, LOG_ENTRY_HTTP, "LOG_ENTRY_HTTP", LOG_ENTRY_ICP, "LOG_ENTRY_ICP");
   field = new LogField("log_entry_type", "etype", LogField::sINT, &LogAccess::marshal_entry_type, &LogAccess::unmarshal_entry_type,
-                       (Ptr<LogFieldAliasMap>)entry_type_map);
+                       make_alias_map(entry_type_map));
   global_field_list.add(field, false);
   ink_hash_table_insert(field_symbol_hash, "etype", field);
 
@@ -1184,12 +1191,10 @@ Log::preproc_thread_main(void *args)
 void *
 Log::flush_thread_main(void * /* args ATS_UNUSED */)
 {
-  char *buf;
-  LogFile *logfile;
   LogBuffer *logbuffer;
   LogFlushData *fdata;
   ink_hrtime now, last_time = 0;
-  int len, bytes_written, total_bytes;
+  int len, total_bytes;
   SLL<LogFlushData, LogFlushData::Link_link> link, invert_link;
   ProxyMutex *mutex = this_thread()->mutex;
 
@@ -1210,9 +1215,9 @@ Log::flush_thread_main(void * /* args ATS_UNUSED */)
     // process each flush data
     //
     while ((fdata = invert_link.pop())) {
-      buf = NULL;
-      bytes_written = 0;
-      logfile = fdata->m_logfile;
+      char *buf = NULL;
+      int bytes_written = 0;
+      LogFile *logfile = fdata->m_logfile.get();
 
       if (logfile->m_file_format == LOG_FILE_BINARY) {
         logbuffer = (LogBuffer *)fdata->m_data;
diff --git a/proxy/logging/LogField.cc b/proxy/logging/LogField.cc
index 3ae1a0b..8413add 100644
--- a/proxy/logging/LogField.cc
+++ b/proxy/logging/LogField.cc
@@ -223,7 +223,7 @@ LogField::LogField(const char *name, const char *symbol, Type type, MarshalFunc
   ink_assert(m_symbol != NULL);
   ink_assert(m_type >= 0 && m_type < N_TYPES);
   ink_assert(m_marshal_func != (MarshalFunc)NULL);
-  ink_assert(m_alias_map != NULL);
+  ink_assert(m_alias_map);
 
   m_time_field = (strcmp(m_symbol, "cqts") == 0 || strcmp(m_symbol, "cqth") == 0 || strcmp(m_symbol, "cqtq") == 0 ||
                   strcmp(m_symbol, "cqtn") == 0 || strcmp(m_symbol, "cqtd") == 0 || strcmp(m_symbol, "cqtt") == 0);
@@ -521,7 +521,7 @@ LogField::marshal_agg(char *buf)
 unsigned
 LogField::unmarshal(char **buf, char *dest, int len)
 {
-  if (m_alias_map == NULL) {
+  if (!m_alias_map) {
     if (m_unmarshal_func == (UnmarshalFunc)LogAccess::unmarshal_str ||
         m_unmarshal_func == (UnmarshalFunc)LogAccess::unmarshal_http_text) {
       UnmarshalFuncWithSlice func = (UnmarshalFuncWithSlice)m_unmarshal_func;
diff --git a/proxy/logging/LogFilter.cc b/proxy/logging/LogFilter.cc
index 592df6a..62fb923 100644
--- a/proxy/logging/LogFilter.cc
+++ b/proxy/logging/LogFilter.cc
@@ -435,7 +435,7 @@ LogFilterInt::LogFilterInt(const char *name, LogField *field, LogFilter::Action
     char *t;
     while (t = tok.getNext(), t != NULL) {
       int64_t ival;
-      if (!_convertStringToInt(t, &ival, field->map())) {
+      if (!_convertStringToInt(t, &ival, field->map().get())) {
         // conversion was successful, add entry to array
         //
         val_array[i++] = ival;
diff --git a/proxy/logging/LogHost.cc b/proxy/logging/LogHost.cc
index b4efa96..2cd87ba 100644
--- a/proxy/logging/LogHost.cc
+++ b/proxy/logging/LogHost.cc
@@ -228,7 +228,10 @@ LogHost::disconnect()
 void
 LogHost::create_orphan_LogFile_object()
 {
-  delete m_orphan_file;
+  // We expect that no-one else is holding any refcounts on the
+  // orphan file so that is will be releases when we replace it
+  // below.
+  ink_assert(m_orphan_file->refcount() == 1);
 
   const char *orphan_ext = "orphan";
   unsigned name_len = (unsigned)(strlen(m_object_filename) + strlen(name()) + strlen(orphan_ext) + 16);
@@ -241,7 +244,6 @@ LogHost::create_orphan_LogFile_object()
   // should check for conflicts with orphan filename
   //
   m_orphan_file = new LogFile(name_buf, NULL, LOG_FILE_ASCII, m_object_signature);
-  ink_assert(m_orphan_file != NULL);
   ats_free(name_buf);
 }
 
diff --git a/proxy/logging/LogHost.h b/proxy/logging/LogHost.h
index 7425d7c..03a977e 100644
--- a/proxy/logging/LogHost.h
+++ b/proxy/logging/LogHost.h
@@ -87,8 +87,9 @@ public:
   LogFile *
   get_orphan_logfile() const
   {
-    return m_orphan_file;
+    return m_orphan_file.get();
   }
+
   // check if we will be able to write orphan file
   int
   do_filesystem_checks()
diff --git a/proxy/logging/LogObject.h b/proxy/logging/LogObject.h
index abfef3a..3b866b4 100644
--- a/proxy/logging/LogObject.h
+++ b/proxy/logging/LogObject.h
@@ -143,7 +143,7 @@ public:
       idx = m_buffer_manager_idx++ % m_flush_threads;
 
     if (m_logFile) {
-      nfb = m_buffer_manager[idx].preproc_buffers(m_logFile);
+      nfb = m_buffer_manager[idx].preproc_buffers(m_logFile.get());
     } else {
       nfb = m_buffer_manager[idx].preproc_buffers(&m_host_list);
     }

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

[trafficserver] 02/33: TS-4425: Bring RefCountObj methods inline for readability.

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit c1b2b98e7a3dea930a19f47a5d357f64eda047aa
Author: James Peach <jp...@apache.org>
AuthorDate: Wed May 4 21:49:09 2016 -0700

    TS-4425: Bring RefCountObj methods inline for readability.
---
 lib/ts/Ptr.h | 44 ++++++++++++++++++++------------------------
 1 file changed, 20 insertions(+), 24 deletions(-)

diff --git a/lib/ts/Ptr.h b/lib/ts/Ptr.h
index edefcf2..b7b86be 100644
--- a/lib/ts/Ptr.h
+++ b/lib/ts/Ptr.h
@@ -51,6 +51,7 @@ public:
     (void)s;
     return;
   }
+
   virtual ~RefCountObj() {}
   RefCountObj &
   operator=(const RefCountObj &s)
@@ -59,9 +60,25 @@ public:
     return (*this);
   }
 
-  int refcount_inc();
-  int refcount_dec();
-  int refcount() const;
+  // Increment the reference count, returning the new count.
+  int
+  refcount_inc()
+  {
+    return ink_atomic_increment((int *)&m_refcount, 1) + 1;
+  }
+
+  // Decrement the reference count, returning the new count.
+  int
+  refcount_dec()
+  {
+    return ink_atomic_increment((int *)&m_refcount, -1) - 1;
+  }
+
+  int
+  refcount() const
+  {
+    return m_refcount;
+  }
 
   virtual void
   free()
@@ -73,30 +90,9 @@ private:
   volatile int m_refcount;
 };
 
-// Increment the reference count, returning the new count.
-inline int
-RefCountObj::refcount_inc()
-{
-  return ink_atomic_increment((int *)&m_refcount, 1) + 1;
-}
-
 #define REF_COUNT_OBJ_REFCOUNT_INC(_x) (_x)->refcount_inc()
-
-// Decrement the reference count, returning the new count.
-inline int
-RefCountObj::refcount_dec()
-{
-  return ink_atomic_increment((int *)&m_refcount, -1) - 1;
-}
-
 #define REF_COUNT_OBJ_REFCOUNT_DEC(_x) (_x)->refcount_dec()
 
-inline int
-RefCountObj::refcount() const
-{
-  return m_refcount;
-}
-
 ////////////////////////////////////////////////////////////////////////
 //
 // class Ptr

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

[trafficserver] 25/33: TS-4425: Switch DNS.cc over to Ptr::get().

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 6ee02bff49e076f52beaba225dba5bf4fc8485c2
Author: James Peach <jp...@apache.org>
AuthorDate: Sat May 7 13:10:18 2016 -0700

    TS-4425: Switch DNS.cc over to Ptr::get().
---
 iocore/dns/DNS.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/iocore/dns/DNS.cc b/iocore/dns/DNS.cc
index fbd0416..02e65d4 100644
--- a/iocore/dns/DNS.cc
+++ b/iocore/dns/DNS.cc
@@ -1070,7 +1070,7 @@ DNSEntry::mainEvent(int event, Event *e)
     Debug("dns", "timeout for query %s", qname);
     if (dnsH->txn_lookup_timeout) {
       timeout = NULL;
-      dns_result(dnsH, this, result_ent, false); // do not retry -- we are over TXN timeout on DNS alone!
+      dns_result(dnsH, this, result_ent.get(), false); // do not retry -- we are over TXN timeout on DNS alone!
       return EVENT_DONE;
     }
     if (written_flag) {
@@ -1080,7 +1080,7 @@ DNSEntry::mainEvent(int event, Event *e)
       DNS_DECREMENT_DYN_STAT(dns_in_flight_stat);
     }
     timeout = NULL;
-    dns_result(dnsH, this, result_ent, true);
+    dns_result(dnsH, this, result_ent.get(), true);
     return EVENT_DONE;
   }
 }
@@ -1266,7 +1266,7 @@ DNSEntry::postEvent(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */)
 {
   if (!action.cancelled) {
     Debug("dns", "called back continuation for %s", qname);
-    action.continuation->handleEvent(DNS_EVENT_LOOKUP, result_ent);
+    action.continuation->handleEvent(DNS_EVENT_LOOKUP, result_ent.get());
   }
   result_ent = NULL;
   action.mutex = NULL;

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

[trafficserver] 31/33: TS-4425: Switch InkIOCoreAPI.cc over to Ptr::get().

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 2f45c4154a59a0ab58cadfbea09ce5631c18aa99
Author: James Peach <jp...@apache.org>
AuthorDate: Sat May 7 15:01:57 2016 -0700

    TS-4425: Switch InkIOCoreAPI.cc over to Ptr::get().
---
 proxy/InkIOCoreAPI.cc | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/proxy/InkIOCoreAPI.cc b/proxy/InkIOCoreAPI.cc
index d8bbc36..cdd274f 100644
--- a/proxy/InkIOCoreAPI.cc
+++ b/proxy/InkIOCoreAPI.cc
@@ -588,7 +588,7 @@ TSIOBufferBlockNext(TSIOBufferBlock blockp)
   sdk_assert(sdk_sanity_check_iocore_structure(blockp) == TS_SUCCESS);
 
   IOBufferBlock *blk = (IOBufferBlock *)blockp;
-  return (TSIOBufferBlock)((IOBufferBlock *)blk->next);
+  return (TSIOBufferBlock)(blk->next.get());
 }
 
 // dev API, not exposed
@@ -615,7 +615,7 @@ TSIOBufferBlockReadStart(TSIOBufferBlock blockp, TSIOBufferReader readerp, int64
   if (avail)
     *avail = blk->read_avail();
 
-  if (blk == reader->block) {
+  if (reader->block.get() == blk) {
     p += reader->start_offset;
     if (avail) {
       *avail -= reader->start_offset;
@@ -640,7 +640,7 @@ TSIOBufferBlockReadAvail(TSIOBufferBlock blockp, TSIOBufferReader readerp)
 
   avail = blk->read_avail();
 
-  if (blk == reader->block) {
+  if (reader->block.get() == blk) {
     avail -= reader->start_offset;
     if (avail < 0) {
       avail = 0;
@@ -728,8 +728,10 @@ TSIOBufferReaderStart(TSIOBufferReader readerp)
 
   IOBufferReader *r = (IOBufferReader *)readerp;
 
-  if (r->block != NULL)
+  if (r->block) {
     r->skip_empty_blocks();
+  }
+
   return reinterpret_cast<TSIOBufferBlock>(r->get_current_block());
 }
 

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

[trafficserver] 11/33: TS-4425: Switch Cache.cc over to Ptr::get().

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit e3ddc16de99bc3e5d869088e1bab82fc81668322
Author: James Peach <jp...@apache.org>
AuthorDate: Thu May 5 20:01:10 2016 -0700

    TS-4425: Switch Cache.cc over to Ptr::get().
---
 iocore/cache/Cache.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc
index cf4b569..d916d63 100644
--- a/iocore/cache/Cache.cc
+++ b/iocore/cache/Cache.cc
@@ -2415,7 +2415,7 @@ CacheVC::handleReadDone(int event, Event *e)
                         (doc_len && (int64_t)doc_len < cache_config_ram_cache_cutoff) || !cache_config_ram_cache_cutoff);
         if (cutoff_check && !f.doc_from_ram_cache) {
           uint64_t o = dir_offset(&dir);
-          vol->ram_cache->put(read_key, buf, doc->len, http_copy_hdr, (uint32_t)(o >> 32), (uint32_t)o);
+          vol->ram_cache->put(read_key, buf.get(), doc->len, http_copy_hdr, (uint32_t)(o >> 32), (uint32_t)o);
         }
         if (!doc_len) {
           // keep a pointer to it. In case the state machine decides to
@@ -2510,7 +2510,7 @@ Cache::lookup(Continuation *cont, const CacheKey *key, CacheFragType type, char
   }
 
   Vol *vol = key_to_vol(key, hostname, host_len);
-  ProxyMutex *mutex = cont->mutex;
+  ProxyMutex *mutex = cont->mutex.get();
   CacheVC *c = new_CacheVC(cont);
   SET_CONTINUATION_HANDLER(c, &CacheVC::openReadStartHead);
   c->vio.op = VIO::READ;

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

[trafficserver] 33/33: TS-4425: Use Ptr for the Thread mutex.

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 64b4092e01982e6daf8c006a57350f0f65030686
Author: James Peach <jp...@apache.org>
AuthorDate: Sat May 7 15:03:05 2016 -0700

    TS-4425: Use Ptr<ProxyMutex> for the Thread mutex.
    
    Each Thread owns its own mutex, so declare this as a Ptr<ProxyMutex>
    to ensure that refcounting semantics are correctly preserved.
---
 iocore/cache/Cache.cc                |  2 +-
 iocore/cache/CacheWrite.cc           | 10 +++++-----
 iocore/cache/P_CacheInternal.h       |  2 +-
 iocore/cluster/ClusterCache.cc       | 10 +++++-----
 iocore/cluster/ClusterConfig.cc      |  5 ++---
 iocore/cluster/ClusterHandlerBase.cc |  2 +-
 iocore/cluster/ClusterMachine.cc     |  6 ++----
 iocore/cluster/ClusterProcessor.cc   |  6 +++---
 iocore/cluster/ClusterRPC.cc         | 10 +++++-----
 iocore/dns/DNS.cc                    |  8 ++++----
 iocore/eventsystem/I_IOBuffer.h      |  5 -----
 iocore/eventsystem/I_Thread.h        |  2 +-
 iocore/hostdb/HostDB.cc              | 12 ++++++------
 iocore/net/P_UnixNet.h               |  4 ++--
 iocore/net/UnixNet.cc                |  9 +++++----
 iocore/net/UnixNetProcessor.cc       |  2 +-
 iocore/net/UnixNetVConnection.cc     |  8 ++++----
 mgmt/ProxyConfig.h                   |  4 ++--
 proxy/ICP.cc                         |  2 +-
 proxy/ICPConfig.cc                   |  2 +-
 proxy/InkAPIInternal.h               |  2 +-
 proxy/InkIOCoreAPI.cc                |  2 +-
 proxy/logging/Log.cc                 |  6 +++---
 proxy/logging/LogFile.cc             |  4 ++--
 proxy/logging/LogObject.cc           |  2 +-
 25 files changed, 60 insertions(+), 67 deletions(-)

diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc
index d916d63..e074fc1 100644
--- a/iocore/cache/Cache.cc
+++ b/iocore/cache/Cache.cc
@@ -888,7 +888,7 @@ CacheProcessor::cacheInitialized()
   uint64_t vol_used_direntries = 0;
   Vol *vol;
 
-  ProxyMutex *mutex = this_ethread()->mutex;
+  ProxyMutex *mutex = this_ethread()->mutex.get();
 
   if (theCache) {
     total_size += theCache->cache_size;
diff --git a/iocore/cache/CacheWrite.cc b/iocore/cache/CacheWrite.cc
index af69c07..67391ed 100644
--- a/iocore/cache/CacheWrite.cc
+++ b/iocore/cache/CacheWrite.cc
@@ -364,7 +364,7 @@ CacheVC *
 new_DocEvacuator(int nbytes, Vol *vol)
 {
   CacheVC *c = new_CacheVC(vol);
-  ProxyMutex *mutex = vol->mutex;
+  ProxyMutex *mutex = vol->mutex.get();
   c->base_stat = cache_evacuate_active_stat;
   CACHE_INCREMENT_DYN_STAT(c->base_stat + CACHE_STAT_ACTIVE);
   c->buf = new_IOBufferData(iobuffer_size_to_index(nbytes, MAX_BUFFER_SIZE_INDEX), MEMALIGNED);
@@ -802,7 +802,7 @@ agg_copy(char *p, CacheVC *vc)
     // move data
     if (vc->write_len) {
       {
-        ProxyMutex *mutex ATS_UNUSED = vc->vol->mutex;
+        ProxyMutex *mutex ATS_UNUSED = vc->vol->mutex.get();
         ink_assert(mutex->thread_holding == this_ethread());
         CACHE_DEBUG_SUM_DYN_STAT(cache_write_bytes_stat, vc->write_len);
       }
@@ -841,7 +841,7 @@ agg_copy(char *p, CacheVC *vc)
     Doc *doc = (Doc *)vc->buf->data();
     int l = vc->vol->round_to_approx_size(doc->len);
     {
-      ProxyMutex *mutex ATS_UNUSED = vc->vol->mutex;
+      ProxyMutex *mutex ATS_UNUSED = vc->vol->mutex.get();
       ink_assert(mutex->thread_holding == this_ethread());
       CACHE_DEBUG_INCREMENT_DYN_STAT(cache_gc_frags_evacuated_stat);
       CACHE_DEBUG_SUM_DYN_STAT(cache_gc_bytes_evacuated_stat, l);
@@ -1583,7 +1583,7 @@ Cache::open_write(Continuation *cont, const CacheKey *key, CacheFragType frag_ty
 
   intptr_t res = 0;
   CacheVC *c = new_CacheVC(cont);
-  ProxyMutex *mutex = cont->mutex;
+  ProxyMutex *mutex = cont->mutex.get();
   SCOPED_MUTEX_LOCK(lock, c->mutex, this_ethread());
   c->vio.op = VIO::WRITE;
   c->base_stat = cache_write_active_stat;
@@ -1651,7 +1651,7 @@ Cache::open_write(Continuation *cont, const CacheKey *key, CacheHTTPInfo *info,
   intptr_t err = 0;
   int if_writers = (uintptr_t)info == CACHE_ALLOW_MULTIPLE_WRITES;
   CacheVC *c = new_CacheVC(cont);
-  ProxyMutex *mutex = cont->mutex;
+  ProxyMutex *mutex = cont->mutex.get();
   c->vio.op = VIO::WRITE;
   c->first_key = *key;
   /*
diff --git a/iocore/cache/P_CacheInternal.h b/iocore/cache/P_CacheInternal.h
index 7fd3162..4150ae6 100644
--- a/iocore/cache/P_CacheInternal.h
+++ b/iocore/cache/P_CacheInternal.h
@@ -879,7 +879,7 @@ dir_overwrite_lock(CacheKey *key, Vol *d, Dir *to_part, ProxyMutex *m, Dir *over
 }
 
 void TS_INLINE
-rand_CacheKey(CacheKey *next_key, ProxyMutex *mutex)
+rand_CacheKey(CacheKey *next_key, Ptr<ProxyMutex> &mutex)
 {
   next_key->b[0] = mutex->thread_holding->generator.random();
   next_key->b[1] = mutex->thread_holding->generator.random();
diff --git a/iocore/cluster/ClusterCache.cc b/iocore/cluster/ClusterCache.cc
index 04213c9..2102a0d 100644
--- a/iocore/cluster/ClusterCache.cc
+++ b/iocore/cluster/ClusterCache.cc
@@ -243,7 +243,7 @@ ClusterVConnectionCache::insert(INK_MD5 *key, ClusterVConnection *vc)
   int index = MD5ToIndex(key);
   Entry *e;
   EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
 
   MUTEX_TRY_LOCK(lock, hash_lock[index], thread);
   if (!lock.is_locked()) {
@@ -269,7 +269,7 @@ ClusterVConnectionCache::lookup(INK_MD5 *key)
   Entry *e;
   ClusterVConnection *vc = 0;
   EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
 
   MUTEX_TRY_LOCK(lock, hash_lock[index], thread);
   if (!lock.is_locked()) {
@@ -1023,7 +1023,7 @@ void
 cache_op_ClusterFunction(ClusterHandler *ch, void *data, int len)
 {
   EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
   ////////////////////////////////////////////////////////
   // Note: we are running on the ET_CLUSTER thread
   ////////////////////////////////////////////////////////
@@ -1939,7 +1939,7 @@ cache_op_result_ClusterFunction(ClusterHandler *ch, void *d, int l)
 
   unsigned int hash = FOLDHASH(ch->machine->ip, msg->seq_number);
   EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
   if (MUTEX_TAKE_TRY_LOCK(remoteCacheContQueueMutex[hash], thread)) {
     // Find it in pending list
 
@@ -2504,7 +2504,7 @@ cache_lookup_ClusterFunction(ClusterHandler *ch, void *data, int len)
 {
   (void)len;
   EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
   ////////////////////////////////////////////////////////
   // Note: we are running on the ET_CLUSTER thread
   ////////////////////////////////////////////////////////
diff --git a/iocore/cluster/ClusterConfig.cc b/iocore/cluster/ClusterConfig.cc
index 499550b..39e6f75 100644
--- a/iocore/cluster/ClusterConfig.cc
+++ b/iocore/cluster/ClusterConfig.cc
@@ -285,7 +285,7 @@ configuration_add_machine(ClusterConfiguration *c, ClusterMachine *m)
   // Machines are stored in ip sorted order.
   //
   EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
   int i = 0;
   ClusterConfiguration *cc = new ClusterConfiguration(*c);
 
@@ -321,8 +321,7 @@ configuration_add_machine(ClusterConfiguration *c, ClusterMachine *m)
 ClusterConfiguration *
 configuration_remove_machine(ClusterConfiguration *c, ClusterMachine *m)
 {
-  EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = this_thread()->mutex.get();
 
   //
   // Build a new cluster configuration without a machine
diff --git a/iocore/cluster/ClusterHandlerBase.cc b/iocore/cluster/ClusterHandlerBase.cc
index cb7064c..41e3ab8 100644
--- a/iocore/cluster/ClusterHandlerBase.cc
+++ b/iocore/cluster/ClusterHandlerBase.cc
@@ -67,7 +67,7 @@ ClusterControl::ClusterControl()
 void
 ClusterControl::real_alloc_data(int read_access, bool align_int32_on_non_int64_boundary)
 {
-  ProxyMutex *mutex = this_ethread()->mutex;
+  ProxyMutex *mutex = this_ethread()->mutex.get();
 
   ink_assert(!data);
   if ((len + DATA_HDR + sizeof(int32_t)) <= DEFAULT_MAX_BUFFER_SIZE) {
diff --git a/iocore/cluster/ClusterMachine.cc b/iocore/cluster/ClusterMachine.cc
index 3dd80e8..4663f06 100644
--- a/iocore/cluster/ClusterMachine.cc
+++ b/iocore/cluster/ClusterMachine.cc
@@ -78,8 +78,7 @@ ClusterMachine::ClusterMachine(char *ahostname, unsigned int aip, int aport)
     msg_proto_minor(0),
     clusterHandlers(0)
 {
-  EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = this_ethread()->mutex.get();
   CLUSTER_INCREMENT_DYN_STAT(CLUSTER_MACHINES_ALLOCATED_STAT);
   if (!aip) {
     char localhost[1024];
@@ -191,8 +190,7 @@ struct MachineTimeoutContinuation : public Continuation {
 void
 free_ClusterMachine(ClusterMachine *m)
 {
-  EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = this_ethread()->mutex.get();
   // delay before the final free
   CLUSTER_INCREMENT_DYN_STAT(CLUSTER_MACHINES_FREED_STAT);
   m->dead = true;
diff --git a/iocore/cluster/ClusterProcessor.cc b/iocore/cluster/ClusterProcessor.cc
index 699d09c..89f4cf2 100644
--- a/iocore/cluster/ClusterProcessor.cc
+++ b/iocore/cluster/ClusterProcessor.cc
@@ -53,7 +53,7 @@ ClusterProcessor::~ClusterProcessor()
 int
 ClusterProcessor::internal_invoke_remote(ClusterHandler *ch, int cluster_fn, void *data, int len, int options, void *cmsg)
 {
-  ProxyMutex *mutex = this_ethread()->mutex;
+  ProxyMutex *mutex = this_ethread()->mutex.get();
   //
   // RPC facility for intercluster communication available to other
   //  subsystems.
@@ -238,7 +238,7 @@ ClusterProcessor::open_local(Continuation *cont, ClusterMachine * /* m ATS_UNUSE
     return NULL;
 
   EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
   ClusterVConnection *vc = clusterVCAllocator.alloc();
   vc->new_connect_read = (options & CLUSTER_OPT_CONN_READ ? 1 : 0);
   vc->start_time = Thread::get_hrtime();
@@ -308,7 +308,7 @@ ClusterProcessor::connect_local(Continuation *cont, ClusterVCToken *token, int c
     return NULL;
 
   EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
   ClusterVConnection *vc = clusterVCAllocator.alloc();
   vc->new_connect_read = (options & CLUSTER_OPT_CONN_READ ? 1 : 0);
   vc->start_time = Thread::get_hrtime();
diff --git a/iocore/cluster/ClusterRPC.cc b/iocore/cluster/ClusterRPC.cc
index 8ae28c8..52c6724 100644
--- a/iocore/cluster/ClusterRPC.cc
+++ b/iocore/cluster/ClusterRPC.cc
@@ -132,7 +132,7 @@ CacheVC *
 ChannelToCacheWriteVC(ClusterHandler *ch, int channel, uint32_t channel_seqno, ClusterVConnection **cluster_vc)
 {
   EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
 
   ClusterVConnection *cvc = ch->channels[channel];
   if (!VALID_CHANNEL(cvc) || (channel_seqno != cvc->token.sequence_number) || (cvc->read.vio.op != VIO::READ)) {
@@ -160,7 +160,7 @@ void
 set_channel_data_ClusterFunction(ClusterHandler *ch, void *tdata, int tlen)
 {
   EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
   // We are called on the ET_CLUSTER thread.
 
   char *data;
@@ -229,7 +229,7 @@ void
 post_setchan_send_ClusterFunction(ClusterHandler *ch, void *data, int /* len ATS_UNUSED */)
 {
   EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
   // We are called on the ET_CLUSTER thread.
   // set_data() control message has been queued into cluster transfer message.
   // This allows us to assume that it has been sent.
@@ -289,7 +289,7 @@ void
 post_setchan_pin_ClusterFunction(ClusterHandler *ch, void *data, int /* len ATS_UNUSED */)
 {
   EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
   // We are called on the ET_CLUSTER thread.
   // Control message has been queued into cluster transfer message.
   // This allows us to assume that it has been sent.
@@ -349,7 +349,7 @@ void
 post_setchan_priority_ClusterFunction(ClusterHandler *ch, void *data, int /* len ATS_UNUSED */)
 {
   EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
 
   // We are called on the ET_CLUSTER thread.
   // Control message has been queued into cluster transfer message.
diff --git a/iocore/dns/DNS.cc b/iocore/dns/DNS.cc
index 02e65d4..63341f6 100644
--- a/iocore/dns/DNS.cc
+++ b/iocore/dns/DNS.cc
@@ -874,7 +874,7 @@ get_entry(DNSHandler *h, char *qname, int qtype)
 static void
 write_dns(DNSHandler *h)
 {
-  ProxyMutex *mutex = h->mutex;
+  ProxyMutex *mutex = h->mutex.get();
   DNS_INCREMENT_DYN_STAT(dns_total_lookups_stat);
   int max_nscount = h->m_res->nscount;
   if (max_nscount > MAX_NAMED)
@@ -955,7 +955,7 @@ DNSHandler::get_query_id()
 static bool
 write_dns_event(DNSHandler *h, DNSEntry *e)
 {
-  ProxyMutex *mutex = h->mutex;
+  ProxyMutex *mutex = h->mutex.get();
   union {
     HEADER _h;
     char _b[MAX_DNS_PACKET_LEN];
@@ -1110,7 +1110,7 @@ DNSProcessor::getby(const char *x, int len, int type, Continuation *cont, Option
 static void
 dns_result(DNSHandler *h, DNSEntry *e, HostEnt *ent, bool retry)
 {
-  ProxyMutex *mutex = h->mutex;
+  ProxyMutex *mutex = h->mutex.get();
   bool cancelled = (e->action.cancelled ? true : false);
 
   if (!ent && !cancelled) {
@@ -1279,7 +1279,7 @@ DNSEntry::postEvent(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */)
 static bool
 dns_process(DNSHandler *handler, HostEnt *buf, int len)
 {
-  ProxyMutex *mutex = handler->mutex;
+  ProxyMutex *mutex = handler->mutex.get();
   HEADER *h = (HEADER *)(buf->buf);
   DNSEntry *e = get_dns(handler, (uint16_t)ntohs(h->id));
   bool retry = false;
diff --git a/iocore/eventsystem/I_IOBuffer.h b/iocore/eventsystem/I_IOBuffer.h
index b50dfb2..17c61ad 100644
--- a/iocore/eventsystem/I_IOBuffer.h
+++ b/iocore/eventsystem/I_IOBuffer.h
@@ -1318,11 +1318,6 @@ public:
     return new_IOBufferBlock_internal(loc);
   }
   IOBufferBlock *
-  operator()(IOBufferData *d, int64_t len = 0, int64_t offset = 0)
-  {
-    return new_IOBufferBlock_internal(loc, d, len, offset);
-  }
-  IOBufferBlock *
   operator()(Ptr<IOBufferData> &d, int64_t len = 0, int64_t offset = 0)
   {
     return new_IOBufferBlock_internal(loc, d.get(), len, offset);
diff --git a/iocore/eventsystem/I_Thread.h b/iocore/eventsystem/I_Thread.h
index f24bb99..eb4bc81 100644
--- a/iocore/eventsystem/I_Thread.h
+++ b/iocore/eventsystem/I_Thread.h
@@ -110,7 +110,7 @@ public:
     regions. Do not modify this member directly.
 
   */
-  ProxyMutex *mutex;
+  Ptr<ProxyMutex> mutex;
 
   // PRIVATE
   void set_specific();
diff --git a/iocore/hostdb/HostDB.cc b/iocore/hostdb/HostDB.cc
index 2eabe2a..78de0bb 100644
--- a/iocore/hostdb/HostDB.cc
+++ b/iocore/hostdb/HostDB.cc
@@ -754,7 +754,7 @@ HostDBProcessor::getby(Continuation *cont, const char *hostname, int len, sockad
 {
   HostDBMD5 md5;
   EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
   ip_text_buffer ipb;
 
   HOSTDB_INCREMENT_DYN_STAT(hostdb_total_lookups_stat);
@@ -840,7 +840,7 @@ HostDBProcessor::getbyname_re(Continuation *cont, const char *ahostname, int len
 {
   bool force_dns = false;
   EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
 
   if (opt.flags & HOSTDB_FORCE_DNS_ALWAYS)
     force_dns = true;
@@ -857,7 +857,7 @@ HostDBProcessor::getbynameport_re(Continuation *cont, const char *ahostname, int
 {
   bool force_dns = false;
   EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
 
   if (opt.flags & HOSTDB_FORCE_DNS_ALWAYS)
     force_dns = true;
@@ -879,7 +879,7 @@ HostDBProcessor::getSRVbyname_imm(Continuation *cont, process_srv_info_pfn proce
   ink_assert(cont->mutex->thread_holding == this_ethread());
   bool force_dns = false;
   EThread *thread = cont->mutex->thread_holding;
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
 
   if (opt.flags & HOSTDB_FORCE_DNS_ALWAYS)
     force_dns = true;
@@ -952,7 +952,7 @@ HostDBProcessor::getbyname_imm(Continuation *cont, process_hostdb_info_pfn proce
   ink_assert(cont->mutex->thread_holding == this_ethread());
   bool force_dns = false;
   EThread *thread = cont->mutex->thread_holding;
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
   HostDBMD5 md5;
 
   if (opt.flags & HOSTDB_FORCE_DNS_ALWAYS)
@@ -1022,7 +1022,7 @@ HostDBProcessor::iterate(Continuation *cont)
 {
   ink_assert(cont->mutex->thread_holding == this_ethread());
   EThread *thread = cont->mutex->thread_holding;
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
 
   HOSTDB_INCREMENT_DYN_STAT(hostdb_total_lookups_stat);
 
diff --git a/iocore/net/P_UnixNet.h b/iocore/net/P_UnixNet.h
index 637577c..d7ae246 100644
--- a/iocore/net/P_UnixNet.h
+++ b/iocore/net/P_UnixNet.h
@@ -160,8 +160,8 @@ struct PollCont : public Continuation {
   PollDescriptor *nextPollDescriptor;
   int poll_timeout;
 
-  PollCont(ProxyMutex *m, int pt = net_config_poll_timeout);
-  PollCont(ProxyMutex *m, NetHandler *nh, int pt = net_config_poll_timeout);
+  PollCont(Ptr<ProxyMutex> &m, int pt = net_config_poll_timeout);
+  PollCont(Ptr<ProxyMutex> &m, NetHandler *nh, int pt = net_config_poll_timeout);
   ~PollCont();
   int pollEvent(int event, Event *e);
 };
diff --git a/iocore/net/UnixNet.cc b/iocore/net/UnixNet.cc
index 5066b47..738b962 100644
--- a/iocore/net/UnixNet.cc
+++ b/iocore/net/UnixNet.cc
@@ -42,7 +42,7 @@ int update_cop_config(const char *name, RecDataT data_type, RecData data, void *
 class InactivityCop : public Continuation
 {
 public:
-  InactivityCop(ProxyMutex *m) : Continuation(m), default_inactivity_timeout(0)
+  explicit InactivityCop(Ptr<ProxyMutex> &m) : Continuation(m.get()), default_inactivity_timeout(0)
   {
     SET_HANDLER(&InactivityCop::check_inactivity);
     REC_ReadConfigInteger(default_inactivity_timeout, "proxy.config.net.default_inactivity_timeout");
@@ -138,14 +138,15 @@ update_cop_config(const char *name, RecDataT data_type ATS_UNUSED, RecData data,
 
 #endif
 
-PollCont::PollCont(ProxyMutex *m, int pt) : Continuation(m), net_handler(NULL), nextPollDescriptor(NULL), poll_timeout(pt)
+PollCont::PollCont(Ptr<ProxyMutex> &m, int pt)
+  : Continuation(m.get()), net_handler(NULL), nextPollDescriptor(NULL), poll_timeout(pt)
 {
   pollDescriptor = new PollDescriptor();
   SET_HANDLER(&PollCont::pollEvent);
 }
 
-PollCont::PollCont(ProxyMutex *m, NetHandler *nh, int pt)
-  : Continuation(m), net_handler(nh), nextPollDescriptor(NULL), poll_timeout(pt)
+PollCont::PollCont(Ptr<ProxyMutex> &m, NetHandler *nh, int pt)
+  : Continuation(m.get()), net_handler(nh), nextPollDescriptor(NULL), poll_timeout(pt)
 {
   pollDescriptor = new PollDescriptor();
   SET_HANDLER(&PollCont::pollEvent);
diff --git a/iocore/net/UnixNetProcessor.cc b/iocore/net/UnixNetProcessor.cc
index 841efc0..a7cb2a5 100644
--- a/iocore/net/UnixNetProcessor.cc
+++ b/iocore/net/UnixNetProcessor.cc
@@ -85,7 +85,7 @@ Action *
 UnixNetProcessor::accept_internal(Continuation *cont, int fd, AcceptOptions const &opt)
 {
   EventType upgraded_etype = opt.etype; // setEtype requires non-const ref.
-  ProxyMutex *mutex = this_ethread()->mutex;
+  ProxyMutex *mutex = this_ethread()->mutex.get();
   int accept_threads = opt.accept_threads; // might be changed.
   IpEndpoint accept_ip;                    // local binding address.
   char thr_name[MAX_THREAD_NAME_LENGTH];
diff --git a/iocore/net/UnixNetVConnection.cc b/iocore/net/UnixNetVConnection.cc
index 899887a..a3e4355 100644
--- a/iocore/net/UnixNetVConnection.cc
+++ b/iocore/net/UnixNetVConnection.cc
@@ -253,7 +253,7 @@ static void
 read_from_net(NetHandler *nh, UnixNetVConnection *vc, EThread *thread)
 {
   NetState *s = &vc->read;
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
   int64_t r = 0;
 
   MUTEX_TRY_LOCK_FOR(lock, s->vio.mutex, thread, s->vio._cont);
@@ -416,7 +416,7 @@ read_from_net(NetHandler *nh, UnixNetVConnection *vc, EThread *thread)
 void
 write_to_net(NetHandler *nh, UnixNetVConnection *vc, EThread *thread)
 {
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
 
   NET_INCREMENT_DYN_STAT(net_calls_to_writetonet_stat);
   NET_INCREMENT_DYN_STAT(net_calls_to_writetonet_afterpoll_stat);
@@ -428,7 +428,7 @@ void
 write_to_net_io(NetHandler *nh, UnixNetVConnection *vc, EThread *thread)
 {
   NetState *s = &vc->write;
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
 
   MUTEX_TRY_LOCK_FOR(lock, s->vio.mutex, thread, s->vio._cont);
 
@@ -1012,7 +1012,7 @@ UnixNetVConnection::load_buffer_and_write(int64_t towrite, int64_t &wattempted,
       }
     }
 
-    ProxyMutex *mutex = thread->mutex;
+    ProxyMutex *mutex = thread->mutex.get();
     NET_INCREMENT_DYN_STAT(net_calls_to_write_stat);
   } while (r == wattempted && total_written < towrite);
 
diff --git a/mgmt/ProxyConfig.h b/mgmt/ProxyConfig.h
index b3a35a5..9247b3b 100644
--- a/mgmt/ProxyConfig.h
+++ b/mgmt/ProxyConfig.h
@@ -104,12 +104,12 @@ template <typename UpdateClass> struct ConfigUpdateContinuation : public Continu
     return EVENT_DONE;
   }
 
-  ConfigUpdateContinuation(ProxyMutex *m) : Continuation(m) { SET_HANDLER(&ConfigUpdateContinuation::update); }
+  ConfigUpdateContinuation(Ptr<ProxyMutex> &m) : Continuation(m.get()) { SET_HANDLER(&ConfigUpdateContinuation::update); }
 };
 
 template <typename UpdateClass>
 int
-ConfigScheduleUpdate(ProxyMutex *mutex)
+ConfigScheduleUpdate(Ptr<ProxyMutex> &mutex)
 {
   eventProcessor.schedule_imm(new ConfigUpdateContinuation<UpdateClass>(mutex), ET_CALL);
   return 0;
diff --git a/proxy/ICP.cc b/proxy/ICP.cc
index 3a48cb3..52602d6 100644
--- a/proxy/ICP.cc
+++ b/proxy/ICP.cc
@@ -1821,7 +1821,7 @@ ICPProcessor::ICPQuery(Continuation *c, URL *url)
 
   // Build continuation to process ICP request
   EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
   ICPRequestCont *rc = new (ICPRequestCont_allocator.alloc()) ICPRequestCont(this, c, url);
 
   ICP_INCREMENT_DYN_STAT(icp_query_requests_stat);
diff --git a/proxy/ICPConfig.cc b/proxy/ICPConfig.cc
index d3f12fa..f0a682b 100644
--- a/proxy/ICPConfig.cc
+++ b/proxy/ICPConfig.cc
@@ -518,7 +518,7 @@ void *
 ICPConfiguration::icp_config_change_callback(void *data, void *value, int startup)
 {
   EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = thread->mutex.get();
 
   //
   // Cast passed parameters to correct types
diff --git a/proxy/InkAPIInternal.h b/proxy/InkAPIInternal.h
index 7908d1f..06c4d1c 100644
--- a/proxy/InkAPIInternal.h
+++ b/proxy/InkAPIInternal.h
@@ -299,7 +299,7 @@ class LifecycleAPIHooks : public FeatureAPIHooks<TSLifecycleHookID, TS_LIFECYCLE
 class ConfigUpdateCallback : public Continuation
 {
 public:
-  ConfigUpdateCallback(INKContInternal *contp) : Continuation(contp->mutex), m_cont(contp)
+  ConfigUpdateCallback(INKContInternal *contp) : Continuation(contp->mutex.get()), m_cont(contp)
   {
     SET_HANDLER(&ConfigUpdateCallback::event_handler);
   }
diff --git a/proxy/InkIOCoreAPI.cc b/proxy/InkIOCoreAPI.cc
index cdd274f..cf0f4e8 100644
--- a/proxy/InkIOCoreAPI.cc
+++ b/proxy/InkIOCoreAPI.cc
@@ -338,7 +338,7 @@ TSVIOMutexGet(TSVIO viop)
   sdk_assert(sdk_sanity_check_iocore_structure(viop) == TS_SUCCESS);
 
   VIO *vio = (VIO *)viop;
-  return (TSMutex)((ProxyMutex *)vio->mutex);
+  return (TSMutex)(vio->mutex.get());
 }
 
 /* High Resolution Time */
diff --git a/proxy/logging/Log.cc b/proxy/logging/Log.cc
index 636610a..fd80cfb 100644
--- a/proxy/logging/Log.cc
+++ b/proxy/logging/Log.cc
@@ -1005,7 +1005,7 @@ Log::access(LogAccess *lad)
   int ret;
   static long sample = 1;
   long this_sample;
-  ProxyMutex *mutex = this_ethread()->mutex;
+  ProxyMutex *mutex = this_ethread()->mutex.get();
 
   // See if we're sampling and it is not time for another sample
   //
@@ -1061,7 +1061,7 @@ int
 Log::va_error(const char *format, va_list ap)
 {
   int ret_val = Log::SKIP;
-  ProxyMutex *mutex = this_ethread()->mutex;
+  ProxyMutex *mutex = this_ethread()->mutex.get();
 
   if (error_log) {
     ink_assert(format != NULL);
@@ -1196,7 +1196,7 @@ Log::flush_thread_main(void * /* args ATS_UNUSED */)
   ink_hrtime now, last_time = 0;
   int len, total_bytes;
   SLL<LogFlushData, LogFlushData::Link_link> link, invert_link;
-  ProxyMutex *mutex = this_thread()->mutex;
+  ProxyMutex *mutex = this_thread()->mutex.get();
 
   Log::flush_notify->lock();
 
diff --git a/proxy/logging/LogFile.cc b/proxy/logging/LogFile.cc
index 21cfb2b..e63de18 100644
--- a/proxy/logging/LogFile.cc
+++ b/proxy/logging/LogFile.cc
@@ -314,7 +314,7 @@ LogFile::preproc_and_try_delete(LogBuffer *lb)
     //
     LogFlushData *flush_data = new LogFlushData(this, lb);
 
-    ProxyMutex *mutex = this_thread()->mutex;
+    ProxyMutex *mutex = this_thread()->mutex.get();
 
     RecIncrRawStat(log_rsb, mutex->thread_holding, log_stat_num_flush_to_disk_stat, lb->header()->entry_count);
 
@@ -422,7 +422,7 @@ LogFile::write_ascii_logbuffer3(LogBufferHeader *buffer_header, const char *alt_
         m_name, this);
   ink_assert(buffer_header != NULL);
 
-  ProxyMutex *mutex = this_thread()->mutex;
+  ProxyMutex *mutex = this_thread()->mutex.get();
   LogBufferIterator iter(buffer_header);
   LogEntryHeader *entry_header;
   int fmt_entry_count = 0;
diff --git a/proxy/logging/LogObject.cc b/proxy/logging/LogObject.cc
index 2ce619b..2375d12 100644
--- a/proxy/logging/LogObject.cc
+++ b/proxy/logging/LogObject.cc
@@ -1301,7 +1301,7 @@ int
 LogObjectManager::log(LogAccess *lad)
 {
   int ret = Log::SKIP;
-  ProxyMutex *mutex = this_thread()->mutex;
+  ProxyMutex *mutex = this_thread()->mutex.get();
 
   for (unsigned i = 0; i < this->_objects.length(); i++) {
     //

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

[trafficserver] 30/33: TS-4425: Switch the remainder of proxy/ over to Ptr::get().

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit a95fdf3b67f2715d7a213523de8efbd7150f3a7e
Author: James Peach <jp...@apache.org>
AuthorDate: Sat May 7 14:05:50 2016 -0700

    TS-4425: Switch the remainder of proxy/ over to Ptr::get().
---
 proxy/CacheControl.cc             |  2 +-
 proxy/CoreUtils.cc                |  4 ++--
 proxy/CoreUtils.h                 |  2 ++
 proxy/FetchSM.cc                  | 16 +++++++++-------
 proxy/ICP.cc                      | 20 ++++++++++----------
 proxy/ICP.h                       | 10 +++++-----
 proxy/ICPConfig.cc                |  4 ++--
 proxy/InkAPI.cc                   | 16 +++++++++++-----
 proxy/InkAPIInternal.h            |  2 +-
 proxy/PluginVC.cc                 |  4 ++--
 proxy/ReverseProxy.cc             |  2 +-
 proxy/SocksProxy.cc               |  2 +-
 proxy/Transform.cc                |  2 +-
 proxy/congest/MT_hashtable.h      |  3 ++-
 proxy/http/HttpCacheSM.h          |  2 +-
 proxy/http/HttpProxyServerMain.cc |  5 ++---
 proxy/http/HttpSM.cc              |  8 ++++----
 proxy/http/HttpSessionManager.cc  |  4 ++--
 proxy/http/HttpTunnel.cc          |  2 +-
 proxy/http/HttpTunnel.h           |  2 +-
 proxy/http2/Http2ClientSession.h  |  2 +-
 21 files changed, 62 insertions(+), 52 deletions(-)

diff --git a/proxy/CacheControl.cc b/proxy/CacheControl.cc
index d344979..5f95c70 100644
--- a/proxy/CacheControl.cc
+++ b/proxy/CacheControl.cc
@@ -99,7 +99,7 @@ struct CC_UpdateContinuation : public Continuation {
     delete this;
     return EVENT_DONE;
   }
-  CC_UpdateContinuation(ProxyMutex *m) : Continuation(m) { SET_HANDLER(&CC_UpdateContinuation::file_update_handler); }
+  CC_UpdateContinuation(Ptr<ProxyMutex> &m) : Continuation(m) { SET_HANDLER(&CC_UpdateContinuation::file_update_handler); }
 };
 
 int
diff --git a/proxy/CoreUtils.cc b/proxy/CoreUtils.cc
index 3267bb7..8724d28 100644
--- a/proxy/CoreUtils.cc
+++ b/proxy/CoreUtils.cc
@@ -743,8 +743,8 @@ CoreUtils::process_EThread(EThread *eth_test)
   ats_free(buf);
 }
 
-static void
-print_netstate(NetState *n)
+void
+CoreUtils::print_netstate(NetState *n)
 {
   printf("      enabled: %d\n", n->enabled);
   printf("      op: %d  _cont: 0x%p\n", n->vio.op, n->vio._cont);
diff --git a/proxy/CoreUtils.h b/proxy/CoreUtils.h
index b9987b8..cd7e0da 100644
--- a/proxy/CoreUtils.h
+++ b/proxy/CoreUtils.h
@@ -92,6 +92,7 @@ class HdrHeap;
 
 class EThread;
 class UnixNetVConnection;
+struct NetState;
 
 class CoreUtils
 {
@@ -185,6 +186,7 @@ public:
   * outputs: none
   **********************************************************************/
   static void print_http_hdr(HTTPHdr *h, const char *name);
+  static void print_netstate(NetState *n);
 
   /**********************************************************************
   * purpose: loads a null terminated string from the core file
diff --git a/proxy/FetchSM.cc b/proxy/FetchSM.cc
index 1a94b39..2c35049 100644
--- a/proxy/FetchSM.cc
+++ b/proxy/FetchSM.cc
@@ -343,12 +343,10 @@ out:
 }
 
 void
-FetchSM::get_info_from_buffer(IOBufferReader *the_reader)
+FetchSM::get_info_from_buffer(IOBufferReader *reader)
 {
   char *buf, *info;
   int64_t read_avail, read_done;
-  IOBufferBlock *blk;
-  IOBufferReader *reader = the_reader;
 
   if (!reader) {
     client_bytes = 0;
@@ -369,9 +367,11 @@ FetchSM::get_info_from_buffer(IOBufferReader *the_reader)
   if (!(fetch_flags & TS_FETCH_FLAGS_STREAM) || !check_chunked()) {
     /* Read the data out of the reader */
     while (read_avail > 0) {
-      if (reader->block != NULL)
+      if (reader->block) {
         reader->skip_empty_blocks();
-      blk = reader->block;
+      }
+
+      IOBufferBlock *blk = reader->block.get();
 
       // This is the equivalent of TSIOBufferBlockReadStart()
       buf = blk->start() + reader->start_offset;
@@ -401,9 +401,11 @@ FetchSM::get_info_from_buffer(IOBufferReader *the_reader)
     /* Read the data out of the reader */
     read_avail = reader->read_avail();
     while (read_avail > 0) {
-      if (reader->block != NULL)
+      if (reader->block) {
         reader->skip_empty_blocks();
-      blk = reader->block;
+      }
+
+      IOBufferBlock *blk = reader->block.get();
 
       // This is the equivalent of TSIOBufferBlockReadStart()
       buf = blk->start() + reader->start_offset;
diff --git a/proxy/ICP.cc b/proxy/ICP.cc
index 5442331..3a48cb3 100644
--- a/proxy/ICP.cc
+++ b/proxy/ICP.cc
@@ -526,7 +526,7 @@ ICPPeerReadCont::PeerReadStateMachine(PeerReadData *s, Event *e)
       if (!_ICPpr->Lock())
         return EVENT_CONT; // unable to get lock, try again later
 
-      bool valid_peer = (_ICPpr->IdToPeer(s->_peer->GetPeerID()) == s->_peer);
+      bool valid_peer = (_ICPpr->IdToPeer(s->_peer->GetPeerID()) == s->_peer.get());
 
       if (valid_peer && _ICPpr->AllowICPQueries() && _ICPpr->GetConfig()->globalConfig()->ICPconfigured()) {
         // Note pending incoming ICP request or response
@@ -553,7 +553,7 @@ ICPPeerReadCont::PeerReadStateMachine(PeerReadData *s, Event *e)
 
       // Assumption of one outstanding read per peer...
       // Setup read from FD
-      ink_assert(s->_peer->buf == NULL);
+      ink_assert(!s->_peer->buf);
       Ptr<IOBufferBlock> buf = s->_peer->buf = new_IOBufferBlock();
       buf->alloc(ICPHandlerCont::ICPDataBuf_IOBuffer_sizeindex);
       s->_peer->fromaddrlen = sizeof(s->_peer->fromaddr);
@@ -563,7 +563,8 @@ ICPPeerReadCont::PeerReadStateMachine(PeerReadData *s, Event *e)
       s->_next_state = READ_DATA_DONE;
       RECORD_ICP_STATE_CHANGE(s, 0, READ_DATA_DONE);
       ink_assert(s->_peer->readAction == NULL);
-      Action *a = s->_peer->RecvFrom_re(this, this, buf, buf->write_avail() - 1, &s->_peer->fromaddr.sa, &s->_peer->fromaddrlen);
+      Action *a =
+        s->_peer->RecvFrom_re(this, this, buf.get(), buf->write_avail() - 1, &s->_peer->fromaddr.sa, &s->_peer->fromaddrlen);
       if (!a) {
         a = ACTION_IO_ERROR;
       }
@@ -702,7 +703,7 @@ ICPPeerReadCont::PeerReadStateMachine(PeerReadData *s, Event *e)
       // we hand off the decoded buffer from the Peer to the PeerReadData
       s->_sender = from;
       s->_rICPmsg_len = s->_bytesReceived;
-      ink_assert(s->_buf == NULL);
+      ink_assert(!s->_buf);
       s->_buf = s->_peer->buf;
       s->_rICPmsg = (ICPMsg_t *)s->_buf->start();
       s->_peer->buf = NULL;
@@ -2044,7 +2045,7 @@ ICPProcessor::SetupListenSockets()
   int index;
   ip_port_text_buffer ipb, ipb2;
   for (index = 0; index < (_nPeerList + 1); ++index) {
-    if ((P = _PeerList[index])) {
+    if ((P = _PeerList[index].get())) {
       if ((P->GetType() == PEER_PARENT) || (P->GetType() == PEER_SIBLING)) {
         ParentSiblingPeer *pPS = (ParentSiblingPeer *)P;
 
@@ -2078,7 +2079,7 @@ ICPProcessor::SetupListenSockets()
   // We funnel all unicast sends and receives through
   // the local peer UDP socket.
   //
-  ParentSiblingPeer *pPS = (ParentSiblingPeer *)((Peer *)_LocalPeer);
+  ParentSiblingPeer *pPS = (ParentSiblingPeer *)(GetLocalPeer());
 
   NetVCOptions options;
   options.local_ip.assign(pPS->GetIP());
@@ -2105,9 +2106,8 @@ ICPProcessor::ShutdownListenSockets()
   ink_assert(!PendingQuery());
   Peer *P;
 
-  int index;
-  for (index = 0; index < (_nPeerList + 1); ++index) {
-    if ((P = _PeerList[index])) {
+  for (int index = 0; index < (_nPeerList + 1); ++index) {
+    if ((P = IdToPeer(index))) {
       if (P->GetType() == PEER_LOCAL) {
         ParentSiblingPeer *pPS = (ParentSiblingPeer *)P;
         (void)pPS->GetChan()->close();
@@ -2253,7 +2253,7 @@ ICPProcessor::GenericFindListPeer(IpAddr const &ip, uint16_t port, int validList
   Peer *P;
   port = htons(port);
   for (int n = 0; n < validListItems; ++n) {
-    if ((P = List[n])) {
+    if ((P = List[n].get())) {
       if ((P->GetIP() == ip) && ((port == 0) || (ats_ip_port_cast(P->GetIP()) == port)))
         return P;
     }
diff --git a/proxy/ICP.h b/proxy/ICP.h
index f90e9f8..5c282e2 100644
--- a/proxy/ICP.h
+++ b/proxy/ICP.h
@@ -818,12 +818,12 @@ public:
   inline Peer *
   GetLocalPeer()
   {
-    return _LocalPeer;
+    return _LocalPeer.get();
   }
   inline Peer *
   IdToPeer(int id)
   {
-    return _PeerList[id];
+    return _PeerList[id].get();
   }
   inline ICPConfiguration *
   GetConfig()
@@ -918,7 +918,7 @@ private:
   inline Peer *
   GetNthSendPeer(int n, int bias)
   {
-    return _SendPeerList[(bias + n) % (_nSendPeerList + 1)];
+    return _SendPeerList[(bias + n) % (_nSendPeerList + 1)].get();
   }
 
   inline int
@@ -929,7 +929,7 @@ private:
   inline Peer *
   GetNthRecvPeer(int n, int bias)
   {
-    return _RecvPeerList[(bias + n) % (_nRecvPeerList + 1)];
+    return _RecvPeerList[(bias + n) % (_nRecvPeerList + 1)].get();
   }
 
   inline int
@@ -951,7 +951,7 @@ private:
   inline Peer *
   GetNthParentPeer(int n, int bias)
   {
-    return _ParentPeerList[(bias + n) % (_nParentPeerList + 1)];
+    return _ParentPeerList[(bias + n) % (_nParentPeerList + 1)].get();
   }
   inline int
   GetStartingParentPeerBias()
diff --git a/proxy/ICPConfig.cc b/proxy/ICPConfig.cc
index f668ac7..d3f12fa 100644
--- a/proxy/ICPConfig.cc
+++ b/proxy/ICPConfig.cc
@@ -1028,7 +1028,7 @@ Action *
 MultiCastPeer::RecvFrom_re(Continuation *cont, void *token, IOBufferBlock * /* bufblock ATS_UNUSED */, int len,
                            struct sockaddr *from, socklen_t *fromlen)
 {
-  Action *a = udpNet.recvfrom_re(cont, token, _recv_chan.fd, from, fromlen, buf, len, true, 0);
+  Action *a = udpNet.recvfrom_re(cont, token, _recv_chan.fd, from, fromlen, buf.get(), len, true, 0);
   return a;
 }
 
@@ -1431,7 +1431,7 @@ ICPProcessor::DumpICPConfig()
         GetConfig()->globalConfig()->ICPReplyToUnknownPeer(), GetConfig()->globalConfig()->ICPDefaultReplyPort());
 
   for (int i = 0; i < (_nPeerList + 1); i++) {
-    P = _PeerList[i];
+    P = IdToPeer(i);
     id = P->GetPeerID();
     type = P->GetType();
     const char *str_type;
diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index 00b544d..e29ad00 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -646,6 +646,12 @@ sdk_sanity_check_null_ptr(void *ptr)
   return TS_SUCCESS;
 }
 
+static TSReturnCode
+sdk_sanity_check_mutex(Ptr<ProxyMutex> &m)
+{
+  return m ? TS_SUCCESS : TS_ERROR;
+}
+
 /**
   The function checks if the buffer is Modifiable and returns true if
   it is modifiable, else returns false.
@@ -4354,7 +4360,7 @@ TSContMutexGet(TSCont contp)
   sdk_assert(sdk_sanity_check_iocore_structure(contp) == TS_SUCCESS);
 
   Continuation *c = (Continuation *)contp;
-  return (TSMutex)((ProxyMutex *)c->mutex);
+  return (TSMutex)(c->mutex.get());
 }
 
 /* HTTP hooks */
@@ -6418,7 +6424,7 @@ TSHttpTxnServerIntercept(TSCont contp, TSHttpTxn txnp)
   INKContInternal *i = (INKContInternal *)contp;
 
   // Must have a mutex
-  sdk_assert(sdk_sanity_check_null_ptr((void *)i->mutex) == TS_SUCCESS);
+  sdk_assert(sdk_sanity_check_mutex(i->mutex) == TS_SUCCESS);
 
   http_sm->plugin_tunnel_type = HTTP_PLUGIN_AS_SERVER;
   http_sm->plugin_tunnel = PluginVCCore::alloc();
@@ -6435,7 +6441,7 @@ TSHttpTxnIntercept(TSCont contp, TSHttpTxn txnp)
   INKContInternal *i = (INKContInternal *)contp;
 
   // Must have a mutex
-  sdk_assert(sdk_sanity_check_null_ptr((void *)i->mutex) == TS_SUCCESS);
+  sdk_assert(sdk_sanity_check_mutex(i->mutex) == TS_SUCCESS);
 
   http_sm->plugin_tunnel_type = HTTP_PLUGIN_AS_INTERCEPT;
   http_sm->plugin_tunnel = PluginVCCore::alloc();
@@ -7536,7 +7542,7 @@ TSAIORead(int fd, off_t offset, char *buf, size_t buffSize, TSCont contp)
 
   pAIO->aiocb.aio_buf = buf;
   pAIO->action = pCont;
-  pAIO->thread = ((ProxyMutex *)pCont->mutex)->thread_holding;
+  pAIO->thread = pCont->mutex->thread_holding;
 
   if (ink_aio_read(pAIO, 1) == 1)
     return TS_SUCCESS;
@@ -7574,7 +7580,7 @@ TSAIOWrite(int fd, off_t offset, char *buf, const size_t bufSize, TSCont contp)
   pAIO->aiocb.aio_buf = buf;
   pAIO->aiocb.aio_nbytes = bufSize;
   pAIO->action = pCont;
-  pAIO->thread = ((ProxyMutex *)pCont->mutex)->thread_holding;
+  pAIO->thread = pCont->mutex->thread_holding;
 
   if (ink_aio_write(pAIO, 1) == 1)
     return TS_SUCCESS;
diff --git a/proxy/InkAPIInternal.h b/proxy/InkAPIInternal.h
index 9c42436..7908d1f 100644
--- a/proxy/InkAPIInternal.h
+++ b/proxy/InkAPIInternal.h
@@ -307,7 +307,7 @@ public:
   int
   event_handler(int, void *)
   {
-    if (m_cont->mutex != NULL) {
+    if (m_cont->mutex) {
       MUTEX_TRY_LOCK(trylock, m_cont->mutex, this_ethread());
       if (!trylock.is_locked()) {
         eventProcessor.schedule_in(this, HRTIME_MSECONDS(10), ET_TASK);
diff --git a/proxy/PluginVC.cc b/proxy/PluginVC.cc
index a0ec05d..7510c59 100644
--- a/proxy/PluginVC.cc
+++ b/proxy/PluginVC.cc
@@ -145,7 +145,7 @@ PluginVC::main_handler(int event, void *data)
       return 0;
     }
 
-    if (read_side_mutex.m_ptr != read_state.vio.mutex.m_ptr) {
+    if (read_side_mutex != read_state.vio.mutex) {
       // It's possible some swapped the mutex on us before
       //  we were able to grab it
       Mutex_unlock(read_side_mutex, my_ethread);
@@ -167,7 +167,7 @@ PluginVC::main_handler(int event, void *data)
       return 0;
     }
 
-    if (write_side_mutex.m_ptr != write_state.vio.mutex.m_ptr) {
+    if (write_side_mutex != write_state.vio.mutex) {
       // It's possible some swapped the mutex on us before
       //  we were able to grab it
       Mutex_unlock(write_side_mutex, my_ethread);
diff --git a/proxy/ReverseProxy.cc b/proxy/ReverseProxy.cc
index 43af4ed..3595f52 100644
--- a/proxy/ReverseProxy.cc
+++ b/proxy/ReverseProxy.cc
@@ -132,7 +132,7 @@ struct UR_UpdateContinuation : public Continuation {
     delete this;
     return EVENT_DONE;
   }
-  UR_UpdateContinuation(ProxyMutex *m) : Continuation(m)
+  UR_UpdateContinuation(Ptr<ProxyMutex> &m) : Continuation(m)
   {
     SET_HANDLER((UR_UpdContHandler)&UR_UpdateContinuation::file_update_handler);
   }
diff --git a/proxy/SocksProxy.cc b/proxy/SocksProxy.cc
index 091c1cd..cd283b3 100644
--- a/proxy/SocksProxy.cc
+++ b/proxy/SocksProxy.cc
@@ -347,7 +347,7 @@ SocksProxy::mainEvent(int event, void *data)
     OneWayTunnel *s_to_c = OneWayTunnel::OneWayTunnel_alloc();
 
     c_to_s->init(clientVC, serverVC, NULL, clientVIO, reader);
-    s_to_c->init(serverVC, clientVC, /*aCont = */ NULL, 0 /*best guess */, c_to_s->mutex);
+    s_to_c->init(serverVC, clientVC, /*aCont = */ NULL, 0 /*best guess */, c_to_s->mutex.get());
 
     OneWayTunnel::SetupTwoWayTunnel(c_to_s, s_to_c);
 
diff --git a/proxy/Transform.cc b/proxy/Transform.cc
index 86dcb18..6d395c3 100644
--- a/proxy/Transform.cc
+++ b/proxy/Transform.cc
@@ -385,7 +385,7 @@ TransformTerminus::reenable(VIO *vio)
   -------------------------------------------------------------------------*/
 
 TransformVConnection::TransformVConnection(Continuation *cont, APIHook *hooks)
-  : TransformVCChain(cont->mutex), m_cont(cont), m_terminus(this), m_closed(0)
+  : TransformVCChain(cont->mutex.get()), m_cont(cont), m_terminus(this), m_closed(0)
 {
   INKVConnInternal *xform;
 
diff --git a/proxy/congest/MT_hashtable.h b/proxy/congest/MT_hashtable.h
index 12cebb9..62666f6 100644
--- a/proxy/congest/MT_hashtable.h
+++ b/proxy/congest/MT_hashtable.h
@@ -347,10 +347,11 @@ public:
       delete hashTables[i];
     }
   }
+
   ProxyMutex *
   lock_for_key(key_t key)
   {
-    return locks[part_num(key)];
+    return locks[part_num(key)].get();
   }
 
   int
diff --git a/proxy/http/HttpCacheSM.h b/proxy/http/HttpCacheSM.h
index e5a9a5f..77b349a 100644
--- a/proxy/http/HttpCacheSM.h
+++ b/proxy/http/HttpCacheSM.h
@@ -60,7 +60,7 @@ public:
   HttpCacheSM();
 
   void
-  init(HttpSM *sm_arg, ProxyMutex *amutex)
+  init(HttpSM *sm_arg, Ptr<ProxyMutex> &amutex)
   {
     master_sm = sm_arg;
     mutex = amutex;
diff --git a/proxy/http/HttpProxyServerMain.cc b/proxy/http/HttpProxyServerMain.cc
index 76c0925..e59cce2 100644
--- a/proxy/http/HttpProxyServerMain.cc
+++ b/proxy/http/HttpProxyServerMain.cc
@@ -266,9 +266,8 @@ init_HttpProxyServer(int n_accept_threads)
     plugin_http_transparent_accept = new HttpSessionAccept(ha_opt);
     plugin_http_transparent_accept->mutex = new_ProxyMutex();
   }
-  if (ssl_plugin_mutex == NULL) {
-    ssl_plugin_mutex = mutexAllocator.alloc();
-    ssl_plugin_mutex->init("SSL Acceptor List");
+  if (!ssl_plugin_mutex) {
+    ssl_plugin_mutex = new_ProxyMutex();
   }
 
   // Do the configuration defined ports.
diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc
index 66c684a..1024a66 100644
--- a/proxy/http/HttpSM.cc
+++ b/proxy/http/HttpSM.cc
@@ -2078,7 +2078,7 @@ HttpSM::process_srv_info(HostDBInfo *r)
     HostDBRoundRobin *rr = r->rr();
     HostDBInfo *srv = NULL;
     if (rr) {
-      srv = rr->select_best_srv(t_state.dns_info.srv_hostname, &mutex.m_ptr->thread_holding->generator, ink_cluster_time(),
+      srv = rr->select_best_srv(t_state.dns_info.srv_hostname, &mutex->thread_holding->generator, ink_cluster_time(),
                                 (int)t_state.txn_conf->down_server_timeout);
     }
     if (!srv) {
@@ -4464,7 +4464,7 @@ HttpSM::do_range_setup_if_necessary()
         content_type = t_state.cache_info.object_read->response_get()->value_get(MIME_FIELD_CONTENT_TYPE, MIME_LEN_CONTENT_TYPE,
                                                                                  &field_content_type_len);
         // create a Range: transform processor for requests of type Range: bytes=1-2,4-5,10-100 (eg. multiple ranges)
-        range_trans = transformProcessor.range_transform(mutex, t_state.ranges, t_state.num_range_fields,
+        range_trans = transformProcessor.range_transform(mutex.get(), t_state.ranges, t_state.num_range_fields,
                                                          &t_state.hdr_info.transform_response, content_type, field_content_type_len,
                                                          t_state.cache_info.object_read->object_size_get());
         api_hooks.append(TS_HTTP_RESPONSE_TRANSFORM_HOOK, range_trans);
@@ -5055,7 +5055,7 @@ HttpSM::do_post_transform_open()
   ink_assert(post_transform_info.vc == NULL);
 
   if (is_action_tag_set("http_post_nullt")) {
-    txn_hook_prepend(TS_HTTP_REQUEST_TRANSFORM_HOOK, transformProcessor.null_transform(mutex));
+    txn_hook_prepend(TS_HTTP_REQUEST_TRANSFORM_HOOK, transformProcessor.null_transform(mutex.get()));
   }
 
   post_transform_info.vc = transformProcessor.open(this, api_hooks.get(TS_HTTP_REQUEST_TRANSFORM_HOOK));
@@ -5076,7 +5076,7 @@ HttpSM::do_transform_open()
   APIHook *hooks;
 
   if (is_action_tag_set("http_nullt")) {
-    txn_hook_prepend(TS_HTTP_RESPONSE_TRANSFORM_HOOK, transformProcessor.null_transform(mutex));
+    txn_hook_prepend(TS_HTTP_RESPONSE_TRANSFORM_HOOK, transformProcessor.null_transform(mutex.get()));
   }
 
   hooks = api_hooks.get(TS_HTTP_RESPONSE_TRANSFORM_HOOK);
diff --git a/proxy/http/HttpSessionManager.cc b/proxy/http/HttpSessionManager.cc
index 004beaa..bfc1005 100644
--- a/proxy/http/HttpSessionManager.cc
+++ b/proxy/http/HttpSessionManager.cc
@@ -279,8 +279,8 @@ HttpSessionManager::acquire_session(Continuation * /* cont ATS_UNUSED */, sockad
     // Now check to see if we have a connection in our shared connection pool
     EThread *ethread = this_ethread();
     ProxyMutex *pool_mutex = (TS_SERVER_SESSION_SHARING_POOL_THREAD == sm->t_state.http_config_param->server_session_sharing_pool) ?
-                               ethread->server_session_pool->mutex :
-                               m_g_pool->mutex;
+                               ethread->server_session_pool->mutex.get() :
+                               m_g_pool->mutex.get();
     MUTEX_TRY_LOCK(lock, pool_mutex, ethread);
     if (lock.is_locked()) {
       if (TS_SERVER_SESSION_SHARING_POOL_THREAD == sm->t_state.http_config_param->server_session_sharing_pool) {
diff --git a/proxy/http/HttpTunnel.cc b/proxy/http/HttpTunnel.cc
index adc84ae..222a4a3 100644
--- a/proxy/http/HttpTunnel.cc
+++ b/proxy/http/HttpTunnel.cc
@@ -534,7 +534,7 @@ HttpTunnel::HttpTunnel()
 }
 
 void
-HttpTunnel::init(HttpSM *sm_arg, ProxyMutex *amutex)
+HttpTunnel::init(HttpSM *sm_arg, Ptr<ProxyMutex> &amutex)
 {
   HttpConfigParams *params = sm_arg->t_state.http_config_param;
   sm = sm_arg;
diff --git a/proxy/http/HttpTunnel.h b/proxy/http/HttpTunnel.h
index c4fce16..7cc4a0f 100644
--- a/proxy/http/HttpTunnel.h
+++ b/proxy/http/HttpTunnel.h
@@ -300,7 +300,7 @@ class HttpTunnel : public Continuation
 public:
   HttpTunnel();
 
-  void init(HttpSM *sm_arg, ProxyMutex *amutex);
+  void init(HttpSM *sm_arg, Ptr<ProxyMutex> &amutex);
   void reset();
   void kill_tunnel();
   bool
diff --git a/proxy/http2/Http2ClientSession.h b/proxy/http2/Http2ClientSession.h
index b0ddc69..bfb156f 100644
--- a/proxy/http2/Http2ClientSession.h
+++ b/proxy/http2/Http2ClientSession.h
@@ -124,7 +124,7 @@ public:
   xmit(MIOBuffer *iobuffer)
   {
     if (ioblock) {
-      iobuffer->append_block(this->ioblock);
+      iobuffer->append_block(this->ioblock.get());
     } else {
       iobuffer->write(this->hdr.raw, sizeof(this->hdr.raw));
     }

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

[trafficserver] 01/33: TS-4425: Make the RefCountObj refcount private.

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 090a0685a61a24392a05423d7749fd8315fd6d4f
Author: James Peach <jp...@apache.org>
AuthorDate: Wed May 4 21:34:25 2016 -0700

    TS-4425: Make the RefCountObj refcount private.
---
 lib/ts/Ptr.h          | 1 +
 proxy/InkIOCoreAPI.cc | 4 ++--
 proxy/hdrs/HdrHeap.cc | 7 ++++---
 proxy/hdrs/HdrTest.cc | 5 ++++-
 proxy/logging/Log.cc  | 2 +-
 5 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/lib/ts/Ptr.h b/lib/ts/Ptr.h
index a8d130a..edefcf2 100644
--- a/lib/ts/Ptr.h
+++ b/lib/ts/Ptr.h
@@ -69,6 +69,7 @@ public:
     delete this;
   }
 
+private:
   volatile int m_refcount;
 };
 
diff --git a/proxy/InkIOCoreAPI.cc b/proxy/InkIOCoreAPI.cc
index d8b462f..d8bbc36 100644
--- a/proxy/InkIOCoreAPI.cc
+++ b/proxy/InkIOCoreAPI.cc
@@ -54,7 +54,7 @@ sdk_sanity_check_mutex(TSMutex mutex)
 
   ProxyMutex *mutexp = (ProxyMutex *)mutex;
 
-  if (mutexp->m_refcount < 0)
+  if (mutexp->refcount() < 0)
     return TS_ERROR;
   if (mutexp->nthread_holding < 0)
     return TS_ERROR;
@@ -210,7 +210,7 @@ TSMutexCheck(TSMutex mutex)
 {
   ProxyMutex *mutexp = (ProxyMutex *)mutex;
 
-  if (mutexp->m_refcount < 0)
+  if (mutexp->refcount() < 0)
     return -1;
   if (mutexp->nthread_holding < 0)
     return -1;
diff --git a/proxy/hdrs/HdrHeap.cc b/proxy/hdrs/HdrHeap.cc
index 4fe3c69..28dd399 100644
--- a/proxy/hdrs/HdrHeap.cc
+++ b/proxy/hdrs/HdrHeap.cc
@@ -155,13 +155,14 @@ new_HdrStrHeap(int requested_size)
 
   //    Debug("hdrs", "Allocated string heap in size %d", alloc_size);
 
-  // Patch virtual function table ptr
-  *((void **)sh) = *((void **)&str_proto_heap);
+  // Placement new the HdrStrHeap.
+  sh = new (sh) HdrStrHeap();
 
   sh->m_heap_size = alloc_size;
   sh->m_free_size = alloc_size - STR_HEAP_HDR_SIZE;
   sh->m_free_start = ((char *)sh) + STR_HEAP_HDR_SIZE;
-  sh->m_refcount = 0;
+
+  ink_assert(sh->refcount() == 0);
 
   ink_assert(sh->m_free_size > 0);
 
diff --git a/proxy/hdrs/HdrTest.cc b/proxy/hdrs/HdrTest.cc
index 5ec020c..71fc29f 100644
--- a/proxy/hdrs/HdrTest.cc
+++ b/proxy/hdrs/HdrTest.cc
@@ -1257,7 +1257,10 @@ HdrTest::test_http_hdr_print_and_copy_aux(int testnum, const char *request, cons
   /*** (2) copy the request header ***/
   HTTPHdr new_hdr, marshal_hdr;
   RefCountObj ref;
-  ref.m_refcount = 100;
+
+  // Pretend to pin this object with a refcount.
+  ref.refcount_inc();
+
   int marshal_len = hdr.m_heap->marshal(marshal_buf, marshal_bufsize);
   marshal_hdr.create(HTTP_TYPE_REQUEST);
   marshal_hdr.unmarshal(marshal_buf, marshal_len, &ref);
diff --git a/proxy/logging/Log.cc b/proxy/logging/Log.cc
index c71e373..6e481ca 100644
--- a/proxy/logging/Log.cc
+++ b/proxy/logging/Log.cc
@@ -1164,7 +1164,7 @@ Log::preproc_thread_main(void *args)
       // TODO: the bytes_to_disk should be set to Log
 
       Debug("log-preproc", "%zu buffers preprocessed from LogConfig %p (refcount=%d) this round", buffers_preproced, current,
-            current->m_refcount);
+            current->refcount());
 
       configProcessor.release(log_configid, current);
     }

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

[trafficserver] 23/33: TS-4425: Switch CacheWrite.cc over to Ptr::get().

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 5df323ea1f320fd360cdd08dd3eb0c2e5d615a17
Author: James Peach <jp...@apache.org>
AuthorDate: Fri May 6 18:57:31 2016 -0700

    TS-4425: Switch CacheWrite.cc over to Ptr::get().
---
 iocore/cache/CacheWrite.cc | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/iocore/cache/CacheWrite.cc b/iocore/cache/CacheWrite.cc
index cd56a5b..af69c07 100644
--- a/iocore/cache/CacheWrite.cc
+++ b/iocore/cache/CacheWrite.cc
@@ -224,7 +224,7 @@ iobufferblock_memcpy(char *p, int len, IOBufferBlock *ab, int offset)
     max_bytes -= offset;
     if (max_bytes <= 0) {
       offset = -max_bytes;
-      b = b->next;
+      b = b->next.get();
       continue;
     }
     int bytes = len;
@@ -233,7 +233,7 @@ iobufferblock_memcpy(char *p, int len, IOBufferBlock *ab, int offset)
     ::memcpy(p, start + offset, bytes);
     p += bytes;
     len -= bytes;
-    b = b->next;
+    b = b->next.get();
     offset = 0;
   }
   return p;
@@ -811,7 +811,7 @@ agg_copy(char *p, CacheVC *vc)
         iobufferblock_memcpy(doc->data(), vc->write_len, res_alt_blk, 0);
       else
 #endif
-        iobufferblock_memcpy(doc->data(), vc->write_len, vc->blocks, vc->offset);
+        iobufferblock_memcpy(doc->data(), vc->write_len, vc->blocks.get(), vc->offset);
 #ifdef VERIFY_JTEST_DATA
       if (f.use_first_key && header_len) {
         int ib = 0, xd = 0;
@@ -1218,7 +1218,7 @@ CacheVC::openWriteCloseDataDone(int event, Event *e)
     fragment++;
     write_pos += write_len;
     dir_insert(&key, vol, &dir);
-    blocks = iobufferblock_skip(blocks, &offset, &length, write_len);
+    blocks = iobufferblock_skip(blocks.get(), &offset, &length, write_len);
     next_CacheKey(&key, &key);
     if (length) {
       write_len = length;
@@ -1315,7 +1315,7 @@ CacheVC::openWriteWriteDone(int event, Event *e)
     write_pos += write_len;
     dir_insert(&key, vol, &dir);
     DDebug("cache_insert", "WriteDone: %X, %X, %d", key.slice32(0), first_key.slice32(0), write_len);
-    blocks = iobufferblock_skip(blocks, &offset, &length, write_len);
+    blocks = iobufferblock_skip(blocks.get(), &offset, &length, write_len);
     next_CacheKey(&key, &key);
   }
   if (closed)
@@ -1480,7 +1480,7 @@ CacheVC::openWriteStartDone(int event, Event *e)
       if (!(doc->first_key == first_key))
         goto Lcollision;
 
-      if (doc->magic != DOC_MAGIC || !doc->hlen || this->load_http_info(write_vector, doc, buf) != doc->hlen) {
+      if (doc->magic != DOC_MAGIC || !doc->hlen || this->load_http_info(write_vector, doc, buf.object()) != doc->hlen) {
         err = ECACHE_BAD_META_DATA;
         goto Lfailure;
       }

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

[trafficserver] 09/33: TS-4425: Add Ptr Continuation constructor.

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 4e9d4e37bd4ca2d182116826b3809ad8a09160b3
Author: James Peach <jp...@apache.org>
AuthorDate: Thu May 5 20:05:10 2016 -0700

    TS-4425: Add Ptr<ProxyMutex> Continuation constructor.
---
 iocore/eventsystem/I_Continuation.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/iocore/eventsystem/I_Continuation.h b/iocore/eventsystem/I_Continuation.h
index 9ba78b4..9660cab 100644
--- a/iocore/eventsystem/I_Continuation.h
+++ b/iocore/eventsystem/I_Continuation.h
@@ -161,6 +161,7 @@ public:
 
   */
   Continuation(ProxyMutex *amutex = NULL);
+  Continuation(Ptr<ProxyMutex> &amutex);
 };
 
 /**
@@ -191,6 +192,17 @@ public:
 #define SET_CONTINUATION_HANDLER(_c, _h) (_c->handler = ((ContinuationHandler)_h))
 #endif
 
+inline Continuation::Continuation(Ptr<ProxyMutex> &amutex)
+  : handler(NULL),
+#ifdef DEBUG
+    handler_name(NULL),
+#endif
+    mutex(amutex)
+{
+  // Pick up the control flags from the creating thread
+  this->control_flags.set_flags(get_cont_flags().get_flags());
+}
+
 inline Continuation::Continuation(ProxyMutex *amutex)
   : handler(NULL),
 #ifdef DEBUG

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

[trafficserver] 24/33: TS-4425: Switch iocore/net over to Ptr::get().

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit d5b79b213188a0ab1d769ac3c17244b274d1e632
Author: James Peach <jp...@apache.org>
AuthorDate: Sat May 7 12:46:11 2016 -0700

    TS-4425: Switch iocore/net over to Ptr::get().
---
 iocore/net/I_UDPPacket.h          |  2 +-
 iocore/net/P_CompletionUtil.h     |  2 +-
 iocore/net/P_Socks.h              |  2 +-
 iocore/net/P_UDPConnection.h      |  2 +-
 iocore/net/P_UDPIOEvent.h         | 23 ++++++++++-----
 iocore/net/P_UDPPacket.h          | 18 ++++++------
 iocore/net/P_UnixCompletionUtil.h |  2 +-
 iocore/net/Socks.cc               |  2 +-
 iocore/net/UnixNetAccept.cc       | 19 ++++++++-----
 iocore/net/UnixNetProcessor.cc    | 12 ++++----
 iocore/net/UnixNetVConnection.cc  | 60 +++++++++++++++++++++++----------------
 iocore/net/UnixUDPNet.cc          |  9 +++---
 12 files changed, 89 insertions(+), 64 deletions(-)

diff --git a/iocore/net/I_UDPPacket.h b/iocore/net/I_UDPPacket.h
index 15850f2..7b0be5f 100644
--- a/iocore/net/I_UDPPacket.h
+++ b/iocore/net/I_UDPPacket.h
@@ -49,7 +49,7 @@ public:
   void setConnection(UDPConnection *c);
   UDPConnection *getConnection();
   IOBufferBlock *getIOBlockChain();
-  int64_t getPktLength();
+  int64_t getPktLength() const;
 
   /**
      Add IOBufferBlock (chain) to end of packet.
diff --git a/iocore/net/P_CompletionUtil.h b/iocore/net/P_CompletionUtil.h
index 5c4b9a4..03128c2 100644
--- a/iocore/net/P_CompletionUtil.h
+++ b/iocore/net/P_CompletionUtil.h
@@ -33,7 +33,7 @@ public:
   static void setContinuation(Event *e, Continuation *c);
   static void *getHandle(Event *e);
   static void setHandle(Event *e, void *handle);
-  static void setInfo(Event *e, int fd, IOBufferBlock *buf, int actual, int errno_);
+  static void setInfo(Event *e, int fd, const Ptr<IOBufferBlock> &buf, int actual, int errno_);
   static void setInfo(Event *e, int fd, struct msghdr *msg, int actual, int errno_);
   static int getBytesTransferred(Event *e);
   static IOBufferBlock *getIOBufferBlock(Event *e);
diff --git a/iocore/net/P_Socks.h b/iocore/net/P_Socks.h
index 7cf5e24..2b7270b 100644
--- a/iocore/net/P_Socks.h
+++ b/iocore/net/P_Socks.h
@@ -140,7 +140,7 @@ struct SocksEntry : public Continuation {
   int startEvent(int event, void *data);
   int mainEvent(int event, void *data);
   void findServer();
-  void init(ProxyMutex *m, SocksNetVC *netvc, unsigned char socks_support, unsigned char ver);
+  void init(Ptr<ProxyMutex> &m, SocksNetVC *netvc, unsigned char socks_support, unsigned char ver);
   void free();
 
   SocksEntry()
diff --git a/iocore/net/P_UDPConnection.h b/iocore/net/P_UDPConnection.h
index 4ee94f7..677c4e7 100644
--- a/iocore/net/P_UDPConnection.h
+++ b/iocore/net/P_UDPConnection.h
@@ -156,7 +156,7 @@ TS_INLINE void
 UDPConnection::setContinuation(Continuation *c)
 {
   // it is not safe to switch among continuations that don't share locks
-  ink_assert(mutex == NULL || c->mutex == mutex);
+  ink_assert(mutex.get() == NULL || c->mutex == mutex);
   mutex = c->mutex;
   ((UDPConnectionInternal *)this)->continuation = c;
 }
diff --git a/iocore/net/P_UDPIOEvent.h b/iocore/net/P_UDPIOEvent.h
index 4daddae..d202d64 100644
--- a/iocore/net/P_UDPIOEvent.h
+++ b/iocore/net/P_UDPIOEvent.h
@@ -31,14 +31,16 @@ class UDPIOEvent : public Event
 public:
   UDPIOEvent() : fd(-1), err(0), m(0), handle(0), b(0), bytesTransferred(0){};
   ~UDPIOEvent(){};
+
   void
-  setInfo(int fd_, IOBufferBlock *b_, int bytesTransferred_, int errno_)
+  setInfo(int fd_, const Ptr<IOBufferBlock> &b_, int bytesTransferred_, int errno_)
   {
     fd = fd_;
     b = b_;
     bytesTransferred = bytesTransferred_;
     err = errno_;
   };
+
   void
   setInfo(int fd_, struct msghdr *m_, int bytesTransferred_, int errno_)
   {
@@ -47,37 +49,44 @@ public:
     bytesTransferred = bytesTransferred_;
     err = errno_;
   };
+
   void
   setHandle(void *v)
   {
     handle = v;
   }
+
   void *
   getHandle()
   {
     return handle;
   }
-  void free();
+
   int
-  getBytesTransferred()
+  getBytesTransferred() const
   {
     return bytesTransferred;
   }
+
   IOBufferBlock *
-  getIOBufferBlock()
+  getIOBufferBlock() const
   {
-    return b;
+    return b.get();
   }
+
   int
-  getError()
+  getError() const
   {
     return err;
   }
+
   Continuation *
-  getContinuation()
+  getContinuation() const
   {
     return continuation;
   }
+
+  void free();
   static void free(UDPIOEvent *e);
 
 private:
diff --git a/iocore/net/P_UDPPacket.h b/iocore/net/P_UDPPacket.h
index 8c6bd6a..9a8d60f 100644
--- a/iocore/net/P_UDPPacket.h
+++ b/iocore/net/P_UDPPacket.h
@@ -91,9 +91,9 @@ UDPPacket::append_block(IOBufferBlock *block)
 
   if (block) {
     if (p->chain) { // append to end
-      IOBufferBlock *last = p->chain;
-      while (last->next != NULL) {
-        last = last->next;
+      IOBufferBlock *last = p->chain.get();
+      while (last->next) {
+        last = last->next.get();
       }
       last->next = block;
     } else {
@@ -103,16 +103,16 @@ UDPPacket::append_block(IOBufferBlock *block)
 }
 
 TS_INLINE int64_t
-UDPPacket::getPktLength()
+UDPPacket::getPktLength() const
 {
   UDPPacketInternal *p = (UDPPacketInternal *)this;
   IOBufferBlock *b;
 
   p->pktLength = 0;
-  b = p->chain;
+  b = p->chain.get();
   while (b) {
     p->pktLength += b->read_avail();
-    b = b->next;
+    b = b->next.get();
   }
   return p->pktLength;
 }
@@ -154,7 +154,8 @@ UDPPacket::setConnection(UDPConnection *c)
 TS_INLINE IOBufferBlock *
 UDPPacket::getIOBlockChain(void)
 {
-  return ((UDPPacketInternal *)this)->chain;
+  ink_assert(dynamic_cast<UDPPacketInternal *>(this) != NULL);
+  return ((UDPPacketInternal *)this)->chain.get();
 }
 
 TS_INLINE UDPConnection *
@@ -199,8 +200,9 @@ new_UDPPacket(struct sockaddr const *to, ink_hrtime when, IOBufferBlock *buf, in
   while (buf) {
     body = buf->clone();
     p->append_block(body);
-    buf = buf->next;
+    buf = buf->next.get();
   }
+
   return p;
 }
 
diff --git a/iocore/net/P_UnixCompletionUtil.h b/iocore/net/P_UnixCompletionUtil.h
index e9e6235..ea64d98 100644
--- a/iocore/net/P_UnixCompletionUtil.h
+++ b/iocore/net/P_UnixCompletionUtil.h
@@ -66,7 +66,7 @@ completionUtil::setHandle(Event *e, void *handle)
   u->setHandle(handle);
 }
 TS_INLINE void
-completionUtil::setInfo(Event *e, int fd, IOBufferBlock *buf, int actual, int errno_)
+completionUtil::setInfo(Event *e, int fd, const Ptr<IOBufferBlock> &buf, int actual, int errno_)
 {
   UDPIOEvent *u = (UDPIOEvent *)e;
   u->setInfo(fd, buf, actual, errno_);
diff --git a/iocore/net/Socks.cc b/iocore/net/Socks.cc
index 792c949..b65ee09 100644
--- a/iocore/net/Socks.cc
+++ b/iocore/net/Socks.cc
@@ -41,7 +41,7 @@ socks_conf_struct *g_socks_conf_stuff = 0;
 ClassAllocator<SocksEntry> socksAllocator("socksAllocator");
 
 void
-SocksEntry::init(ProxyMutex *m, SocksNetVC *vc, unsigned char socks_support, unsigned char ver)
+SocksEntry::init(Ptr<ProxyMutex> &m, SocksNetVC *vc, unsigned char socks_support, unsigned char ver)
 {
   mutex = m;
   buf = new_MIOBuffer();
diff --git a/iocore/net/UnixNetAccept.cc b/iocore/net/UnixNetAccept.cc
index 0510515..8e06ff1 100644
--- a/iocore/net/UnixNetAccept.cc
+++ b/iocore/net/UnixNetAccept.cc
@@ -84,9 +84,12 @@ net_accept(NetAccept *na, void *ep, bool blockable)
   UnixNetVConnection *vc = NULL;
   Connection con;
 
-  if (!blockable)
-    if (!MUTEX_TAKE_TRY_LOCK_FOR(na->action_->mutex, e->ethread, na->action_->continuation))
+  if (!blockable) {
+    if (!MUTEX_TAKE_TRY_LOCK(na->action_->mutex.get(), e->ethread)) {
       return 0;
+    }
+  }
+
   // do-while for accepting all the connections
   // added by YTS Team, yamsat
   do {
@@ -129,7 +132,7 @@ net_accept(NetAccept *na, void *ep, bool blockable)
 
 Ldone:
   if (!blockable)
-    MUTEX_UNTAKE_LOCK(na->action_->mutex, e->ethread);
+    MUTEX_UNTAKE_LOCK(na->action_->mutex.get(), e->ethread);
   return count;
 }
 
@@ -304,10 +307,12 @@ NetAccept::acceptEvent(int event, void *ep)
   // PollDescriptor *pd = get_PollDescriptor(e->ethread);
   ProxyMutex *m = 0;
 
-  if (action_->mutex)
-    m = action_->mutex;
-  else
-    m = mutex;
+  if (action_->mutex) {
+    m = action_->mutex.get();
+  } else {
+    m = mutex.get();
+  }
+
   MUTEX_TRY_LOCK(lock, m, e->ethread);
   if (lock.is_locked()) {
     if (action_->cancelled) {
diff --git a/iocore/net/UnixNetProcessor.cc b/iocore/net/UnixNetProcessor.cc
index e2c6268..841efc0 100644
--- a/iocore/net/UnixNetProcessor.cc
+++ b/iocore/net/UnixNetProcessor.cc
@@ -85,8 +85,7 @@ Action *
 UnixNetProcessor::accept_internal(Continuation *cont, int fd, AcceptOptions const &opt)
 {
   EventType upgraded_etype = opt.etype; // setEtype requires non-const ref.
-  EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = this_ethread()->mutex;
   int accept_threads = opt.accept_threads; // might be changed.
   IpEndpoint accept_ip;                    // local binding address.
   char thr_name[MAX_THREAD_NAME_LENGTH];
@@ -181,6 +180,7 @@ UnixNetProcessor::accept_internal(Continuation *cont, int fd, AcceptOptions cons
     setsockopt(na->server.fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &should_filter_int, sizeof(int));
   }
 #endif
+
 #ifdef TCP_INIT_CWND
   int tcp_init_cwnd = 0;
   REC_ReadConfigInteger(tcp_init_cwnd, "proxy.config.http.server_tcp_init_cwnd");
@@ -191,14 +191,14 @@ UnixNetProcessor::accept_internal(Continuation *cont, int fd, AcceptOptions cons
     }
   }
 #endif
-  return na->action_;
+
+  return na->action_.get();
 }
 
 Action *
 UnixNetProcessor::connect_re_internal(Continuation *cont, sockaddr const *target, NetVCOptions *opt)
 {
-  ProxyMutex *mutex = cont->mutex;
-  EThread *t = mutex->thread_holding;
+  EThread *t = cont->mutex->thread_holding;
   UnixNetVConnection *vc = (UnixNetVConnection *)this->allocate_vc(t);
 
   if (opt)
@@ -364,7 +364,7 @@ struct CheckConnect : public Continuation {
     }
   }
 
-  CheckConnect(ProxyMutex *m = NULL) : Continuation(m), connect_status(-1), recursion(0), timeout(0)
+  explicit CheckConnect(Ptr<ProxyMutex> &m) : Continuation(m.get()), connect_status(-1), recursion(0), timeout(0)
   {
     SET_HANDLER(&CheckConnect::handle_connect);
     buf = new_empty_MIOBuffer(1);
diff --git a/iocore/net/UnixNetVConnection.cc b/iocore/net/UnixNetVConnection.cc
index 59b30bd..899887a 100644
--- a/iocore/net/UnixNetVConnection.cc
+++ b/iocore/net/UnixNetVConnection.cc
@@ -291,7 +291,7 @@ read_from_net(NetHandler *nh, UnixNetVConnection *vc, EThread *thread)
 
   // read data
   int64_t rattempted = 0, total_read = 0;
-  int niov = 0;
+  unsigned niov = 0;
   IOVec tiovec[NET_MAX_IOV];
   if (toread) {
     IOBufferBlock *b = buf.writer()->first_write_block();
@@ -311,14 +311,13 @@ read_from_net(NetHandler *nh, UnixNetVConnection *vc, EThread *thread)
           if (a >= togo)
             break;
         }
-        b = b->next;
+        b = b->next.get();
       }
 
-      if (niov == 1) {
-        r = socketManager.read(vc->con.fd, tiovec[0].iov_base, tiovec[0].iov_len);
-      } else {
-        r = socketManager.readv(vc->con.fd, &tiovec[0], niov);
-      }
+      ink_assert(niov > 0);
+      ink_assert(niov < countof(tiovec));
+      r = socketManager.readv(vc->con.fd, &tiovec[0], niov);
+
       NET_INCREMENT_DYN_STAT(net_calls_to_read_stat);
 
       if (vc->origin_trace) {
@@ -390,10 +389,12 @@ read_from_net(NetHandler *nh, UnixNetVConnection *vc, EThread *thread)
       Debug("iocore_net", "read_from_net, read finished - signal done");
       return;
     } else {
-      if (read_signal_and_update(VC_EVENT_READ_READY, vc) != EVENT_CONT)
+      if (read_signal_and_update(VC_EVENT_READ_READY, vc) != EVENT_CONT) {
         return;
+      }
+
       // change of lock... don't look at shared variables!
-      if (lock.get_mutex() != s->vio.mutex.m_ptr) {
+      if (lock.get_mutex() != s->vio.mutex.get()) {
         read_reschedule(nh, vc);
         return;
       }
@@ -431,7 +432,7 @@ write_to_net_io(NetHandler *nh, UnixNetVConnection *vc, EThread *thread)
 
   MUTEX_TRY_LOCK_FOR(lock, s->vio.mutex, thread, s->vio._cont);
 
-  if (!lock.is_locked() || lock.get_mutex() != s->vio.mutex.m_ptr) {
+  if (!lock.is_locked() || lock.get_mutex() != s->vio.mutex.get()) {
     write_reschedule(nh, vc);
     return;
   }
@@ -574,12 +575,14 @@ write_to_net_io(NetHandler *nh, UnixNetVConnection *vc, EThread *thread)
       if (write_signal_and_update(VC_EVENT_WRITE_READY, vc) != EVENT_CONT) {
         return;
       }
+
       // change of lock... don't look at shared variables!
-      if (lock.get_mutex() != s->vio.mutex.m_ptr) {
+      if (lock.get_mutex() != s->vio.mutex.get()) {
         write_reschedule(nh, vc);
         return;
       }
     }
+
     if (!buf.reader()->read_avail()) {
       write_disable(nh, vc);
       return;
@@ -950,11 +953,11 @@ UnixNetVConnection::load_buffer_and_write(int64_t towrite, int64_t &wattempted,
 
   // XXX Rather than dealing with the block directly, we should use the IOBufferReader API.
   int64_t offset = buf.reader()->start_offset;
-  IOBufferBlock *b = buf.reader()->block;
+  IOBufferBlock *b = buf.reader()->block.get();
 
   do {
     IOVec tiovec[NET_MAX_IOV];
-    int niov = 0;
+    unsigned niov = 0;
     int64_t total_written_last = total_written;
     while (b && niov < NET_MAX_IOV) {
       // check if we have done this block
@@ -962,15 +965,20 @@ UnixNetVConnection::load_buffer_and_write(int64_t towrite, int64_t &wattempted,
       l -= offset;
       if (l <= 0) {
         offset = -l;
-        b = b->next;
+        b = b->next.get();
         continue;
       }
+
       // check if to amount to write exceeds that in this buffer
       int64_t wavail = towrite - total_written;
-      if (l > wavail)
+      if (l > wavail) {
         l = wavail;
-      if (!l)
+      }
+
+      if (!l) {
         break;
+      }
+
       total_written += l;
       // build an iov entry
       tiovec[niov].iov_len = l;
@@ -978,13 +986,14 @@ UnixNetVConnection::load_buffer_and_write(int64_t towrite, int64_t &wattempted,
       niov++;
       // on to the next block
       offset = 0;
-      b = b->next;
+      b = b->next.get();
     }
+
     wattempted = total_written - total_written_last;
-    if (niov == 1)
-      r = socketManager.write(con.fd, tiovec[0].iov_base, tiovec[0].iov_len);
-    else
-      r = socketManager.writev(con.fd, &tiovec[0], niov);
+
+    ink_assert(niov > 0);
+    ink_assert(niov < countof(tiovec));
+    r = socketManager.writev(con.fd, &tiovec[0], niov);
 
     if (origin_trace) {
       char origin_trace_ip[INET6_ADDRSTRLEN];
@@ -1136,11 +1145,12 @@ UnixNetVConnection::mainEvent(int event, Event *e)
   ink_assert(thread == this_ethread());
 
   MUTEX_TRY_LOCK(hlock, get_NetHandler(thread)->mutex, e->ethread);
-  MUTEX_TRY_LOCK(rlock, read.vio.mutex ? (ProxyMutex *)read.vio.mutex : (ProxyMutex *)e->ethread->mutex, e->ethread);
-  MUTEX_TRY_LOCK(wlock, write.vio.mutex ? (ProxyMutex *)write.vio.mutex : (ProxyMutex *)e->ethread->mutex, e->ethread);
+  MUTEX_TRY_LOCK(rlock, read.vio.mutex ? read.vio.mutex : e->ethread->mutex, e->ethread);
+  MUTEX_TRY_LOCK(wlock, write.vio.mutex ? write.vio.mutex : e->ethread->mutex, e->ethread);
+
   if (!hlock.is_locked() || !rlock.is_locked() || !wlock.is_locked() ||
-      (read.vio.mutex.m_ptr && rlock.get_mutex() != read.vio.mutex.m_ptr) ||
-      (write.vio.mutex.m_ptr && wlock.get_mutex() != write.vio.mutex.m_ptr)) {
+      (read.vio.mutex && rlock.get_mutex() != read.vio.mutex.get()) ||
+      (write.vio.mutex && wlock.get_mutex() != write.vio.mutex.get())) {
 #ifdef INACTIVITY_TIMEOUT
     if (e == active_timeout)
 #endif
diff --git a/iocore/net/UnixUDPNet.cc b/iocore/net/UnixUDPNet.cc
index a17d46c..5370173 100644
--- a/iocore/net/UnixUDPNet.cc
+++ b/iocore/net/UnixUDPNet.cc
@@ -380,7 +380,7 @@ UDPReadContinuation::readPollEvent(int event_, Event *e)
   } else if (rlen < 0 && rlen != -EAGAIN) {
     // signal error.
     *fromaddrlen = tmp_fromlen;
-    completionUtil::setInfo(event, fd, (IOBufferBlock *)readbuf, rlen, errno);
+    completionUtil::setInfo(event, fd, readbuf, rlen, errno);
     c = completionUtil::getContinuation(event);
     // TODO: Should we deal with the return code?
     c->handleEvent(NET_EVENT_DATAGRAM_READ_ERROR, event);
@@ -434,7 +434,7 @@ UDPNetProcessor::recvfrom_re(Continuation *cont, void *token, int fd, struct soc
 
   if (actual > 0) {
     completionUtil::setThread(event, this_ethread());
-    completionUtil::setInfo(event, fd, buf, actual, errno);
+    completionUtil::setInfo(event, fd, make_ptr(buf), actual, errno);
     buf->fill(actual);
     cont->handleEvent(NET_EVENT_DATAGRAM_READ_COMPLETE, event);
     completionUtil::destroy(event);
@@ -449,7 +449,7 @@ UDPNetProcessor::recvfrom_re(Continuation *cont, void *token, int fd, struct soc
     return event;
   } else {
     completionUtil::setThread(event, this_ethread());
-    completionUtil::setInfo(event, fd, buf, actual, errno);
+    completionUtil::setInfo(event, fd, make_ptr(buf), actual, errno);
     cont->handleEvent(NET_EVENT_DATAGRAM_READ_ERROR, event);
     completionUtil::destroy(event);
     return ACTION_IO_ERROR;
@@ -749,7 +749,6 @@ sendPackets:
 void
 UDPQueue::SendUDPPacket(UDPPacketInternal *p, int32_t /* pktLen ATS_UNUSED */)
 {
-  IOBufferBlock *b;
   struct msghdr msg;
   struct iovec iov[32];
   int real_len = 0;
@@ -767,7 +766,7 @@ UDPQueue::SendUDPPacket(UDPPacketInternal *p, int32_t /* pktLen ATS_UNUSED */)
   msg.msg_namelen = sizeof(p->to);
   iov_len = 0;
 
-  for (b = p->chain; b != NULL; b = b->next) {
+  for (IOBufferBlock *b = p->chain.get(); b != NULL; b = b->next.get()) {
     iov[iov_len].iov_base = (caddr_t)b->start();
     iov[iov_len].iov_len = b->size();
     real_len += iov[iov_len].iov_len;

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

[trafficserver] 14/33: TS-4425: Switch CacheTest.cc over to Ptr::get().

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit a41002ecf019d77a9d577dabce5a68383b68b272
Author: James Peach <jp...@apache.org>
AuthorDate: Thu May 5 21:00:18 2016 -0700

    TS-4425: Switch CacheTest.cc over to Ptr::get().
---
 iocore/cache/CacheTest.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/iocore/cache/CacheTest.cc b/iocore/cache/CacheTest.cc
index 7673263..8ea8e48 100644
--- a/iocore/cache/CacheTest.cc
+++ b/iocore/cache/CacheTest.cc
@@ -555,7 +555,7 @@ test_RamCache(RegressionTest *t, RamCache *cache, const char *name, int64_t cach
       data.push_back(make_ptr(d));
       md5.u64[0] = ((uint64_t)i << 32) + i;
       md5.u64[1] = ((uint64_t)i << 32) + i;
-      cache->put(&md5, data[i], 1 << 15);
+      cache->put(&md5, data[i].get(), 1 << 15);
       // More hits for the first 10.
       for (int j = 0; j <= i && j < 10; j++) {
         Ptr<IOBufferData> data;
@@ -597,7 +597,7 @@ test_RamCache(RegressionTest *t, RamCache *cache, const char *name, int64_t cach
       IOBufferData *d = THREAD_ALLOC(ioDataAllocator, this_thread());
       d->alloc(BUFFER_SIZE_INDEX_16K);
       data.push_back(make_ptr(d));
-      cache->put(&md5, data.back(), 1 << 15);
+      cache->put(&md5, data.back().get(), 1 << 15);
       if (i >= sample_size / 2)
         misses++; // Sample last half of the gets.
     }
@@ -616,7 +616,7 @@ test_RamCache(RegressionTest *t, RamCache *cache, const char *name, int64_t cach
       IOBufferData *d = THREAD_ALLOC(ioDataAllocator, this_thread());
       d->alloc(BUFFER_SIZE_INDEX_8K + (r[i] % 3));
       data.push_back(make_ptr(d));
-      cache->put(&md5, data.back(), d->block_size());
+      cache->put(&md5, data.back().get(), d->block_size());
       if (i >= sample_size / 2)
         misses++; // Sample last half of the gets.
     }

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

[trafficserver] 15/33: TS-4425: Switch P_CacheInternal.h over to Ptr::get().

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 90859130376d3069d684e9311e54036ffe1a5093
Author: James Peach <jp...@apache.org>
AuthorDate: Thu May 5 21:04:51 2016 -0700

    TS-4425: Switch P_CacheInternal.h over to Ptr::get().
---
 iocore/cache/P_CacheInternal.h | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/iocore/cache/P_CacheInternal.h b/iocore/cache/P_CacheInternal.h
index 8db829b..7fd3162 100644
--- a/iocore/cache/P_CacheInternal.h
+++ b/iocore/cache/P_CacheInternal.h
@@ -234,17 +234,20 @@ struct CacheVC : public CacheVConnection {
     ink_assert(vio.op == VIO::READ);
     return !f.not_from_ram_cache;
   }
+
   int
   get_header(void **ptr, int *len)
   {
-    if (first_buf.m_ptr) {
+    if (first_buf) {
       Doc *doc = (Doc *)first_buf->data();
       *ptr = doc->hdr();
       *len = doc->hlen;
       return 0;
-    } else
-      return -1;
+    }
+
+    return -1;
   }
+
   int
   set_header(void *ptr, int len)
   {
@@ -252,10 +255,11 @@ struct CacheVC : public CacheVConnection {
     header_to_write_len = len;
     return 0;
   }
+
   int
   get_single_data(void **ptr, int *len)
   {
-    if (first_buf.m_ptr) {
+    if (first_buf) {
       Doc *doc = (Doc *)first_buf->data();
       if (doc->data_len() == doc->total_len) {
         *ptr = doc->data();
@@ -263,16 +267,20 @@ struct CacheVC : public CacheVConnection {
         return 0;
       }
     }
+
     return -1;
   }
+
   int
   get_volume_number() const
   {
     if (vol && vol->cache_vol) {
       return vol->cache_vol->vol_number;
     }
+
     return -1;
   }
+
   bool
   is_compressed_in_ram() const
   {
@@ -560,7 +568,7 @@ TS_INLINE int
 free_CacheVC(CacheVC *cont)
 {
   Debug("cache_free", "free %p", cont);
-  ProxyMutex *mutex = cont->mutex;
+  ProxyMutex *mutex = cont->mutex.get();
   Vol *vol = cont->vol;
   if (vol) {
     CACHE_DECREMENT_DYN_STAT(cont->base_stat + CACHE_STAT_ACTIVE);

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

[trafficserver] 06/33: TS-4425: Add unsafe Ptr::swizzle().

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 5389f2602fcbe8d8e7dc0b577db90da09cc23671
Author: James Peach <jp...@apache.org>
AuthorDate: Sat May 7 13:50:48 2016 -0700

    TS-4425: Add unsafe Ptr::swizzle().
---
 lib/ts/Ptr.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lib/ts/Ptr.h b/lib/ts/Ptr.h
index d1288fa..3391608 100644
--- a/lib/ts/Ptr.h
+++ b/lib/ts/Ptr.h
@@ -161,6 +161,15 @@ public:
     return tmp;
   }
 
+  // XXX Clearly this is not safe. This is used in HdrHeap::unmarshal() to swizzle
+  // the refcount of the managed heap pointers. That code needs to be cleaned up
+  // so that this can be removed. Do not use this in new code.
+  void
+  swizzle(RefCountObj *ptr)
+  {
+    m_ptr = ptr;
+  }
+
   T *m_ptr;
 };
 

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

[trafficserver] 12/33: TS-4425: Switch CacheDir.cc over to Ptr::get().

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

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 3001e09987890b4c4db37a4c5dec91249aa5d2f9
Author: James Peach <jp...@apache.org>
AuthorDate: Thu May 5 20:50:22 2016 -0700

    TS-4425: Switch CacheDir.cc over to Ptr::get().
---
 iocore/cache/CacheDir.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/iocore/cache/CacheDir.cc b/iocore/cache/CacheDir.cc
index eb5ab9c..fa279f9 100644
--- a/iocore/cache/CacheDir.cc
+++ b/iocore/cache/CacheDir.cc
@@ -33,19 +33,19 @@
 
 #define CACHE_INC_DIR_USED(_m)                            \
   do {                                                    \
-    ProxyMutex *mutex = _m;                               \
+    ProxyMutex *mutex = _m.get();                         \
     CACHE_INCREMENT_DYN_STAT(cache_direntries_used_stat); \
   } while (0)
 
 #define CACHE_DEC_DIR_USED(_m)                            \
   do {                                                    \
-    ProxyMutex *mutex = _m;                               \
+    ProxyMutex *mutex = _m.get();                         \
     CACHE_DECREMENT_DYN_STAT(cache_direntries_used_stat); \
   } while (0)
 
 #define CACHE_INC_DIR_COLLISIONS(_m)                                \
   do {                                                              \
-    ProxyMutex *mutex = _m;                                         \
+    ProxyMutex *mutex = _m.get();                                   \
     CACHE_INCREMENT_DYN_STAT(cache_directory_collision_count_stat); \
   } while (0);
 

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