[prev in list] [next in list] [prev in thread] [next in thread] 

List:       squid-cvs
Subject:    /bzr/squid3/trunk/ r12755: Polish: upgrade TunnelStateData to CBDATA_CLASS2()
From:       Amos Jeffries <squid3 () treenet ! co ! nz>
Date:       2013-04-07 12:47:59
Message-ID: 20130407125509.40514.qmail () squid-cache ! org
[Download RAW message or body]

--===============0704267386==
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------
revno: 12755
committer: Amos Jeffries <squid3@treenet.co.nz>
branch nick: trunk
timestamp: Sun 2013-04-07 06:47:59 -0600
message:
  Polish: upgrade TunnelStateData to CBDATA_CLASS2()
  
  CBDATA_CLASS2() removes the need to define new/delete operators and
  removes soem uses of cbdataFree()/cbdataAlloc()
  
  Also replaces several abuses of the cbdataInternal*() locking API with
  CbcPointer<> auto-pointers. The existence of some of these locks needing
  to be done is questionable since AsyncCalls scheduling protects better
  against the 'deleted under our feets' problem.
   For now the locks are retained since it is not yet easy to track down
  which are safe and which are removable.
modified:
  src/tunnel.cc

--===============0704267386==
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"; name="r12755.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

=== modified file 'src/tunnel.cc'
--- a/src/tunnel.cc	2013-04-07 12:32:06 +0000
+++ b/src/tunnel.cc	2013-04-07 12:47:59 +0000
@@ -86,8 +86,6 @@
     TunnelStateData &operator =(const TunnelStateData &); // do not implement
 
     class Connection;
-    void *operator new(size_t);
-    void operator delete (void *);
     static void ReadClient(const Comm::ConnectionPointer &, char *buf, size_t len, \
                comm_err_t errcode, int xerrno, void *data);
     static void ReadServer(const Comm::ConnectionPointer &, char *buf, size_t len, \
                comm_err_t errcode, int xerrno, void *data);
     static void WriteClientDone(const Comm::ConnectionPointer &, char *buf, size_t \
len, comm_err_t flag, int xerrno, void *data); @@ -140,7 +138,7 @@
     void copyRead(Connection &from, IOCB *completion);
 
 private:
-    CBDATA_CLASS(TunnelStateData);
+    CBDATA_CLASS2(TunnelStateData);
     void copy (size_t len, comm_err_t errcode, int xerrno, Connection &from, \
                Connection &to, IOCB *);
     void readServer(char *buf, size_t len, comm_err_t errcode, int xerrno);
     void readClient(char *buf, size_t len, comm_err_t errcode, int xerrno);
@@ -340,7 +338,7 @@
      * - RBC 20030229
      * from.conn->close() / to.conn->close() done here trigger close callbacks which \
                may free TunnelStateData
      */
-    cbdataInternalLock(this);	/* ??? should be locked by the caller... */
+    const CbcPointer<TunnelStateData> safetyLock(this);
 
     /* Bump the source connection read timeout on any activity */
     if (Comm::IsConnOpen(from.conn)) {
@@ -373,8 +371,6 @@
                                              CommIoCbPtrFun(completion, this));
         Comm::Write(to.conn, from.buf, len, call, NULL);
     }
-
-    cbdataInternalUnlock(this);	/* ??? */
 }
 
 /* Writes data from the client buffer to the server side */
@@ -420,12 +416,10 @@
         return;
     }
 
-    cbdataInternalLock(this);	/* ??? should be locked by the caller... */
+    const CbcPointer<TunnelStateData> safetyLock(this);	/* ??? should be locked by \
the caller... */  
     if (cbdataReferenceValid(this))
         copyRead(client, ReadClient);
-
-    cbdataInternalUnlock(this);	/* ??? */
 }
 
 /* Writes data from the server buffer to the client side */
@@ -482,12 +476,10 @@
         return;
     }
 
-    cbdataInternalLock(this);	/* ??? should be locked by the caller... */
+    CbcPointer<TunnelStateData> safetyLock(this);	/* ??? should be locked by the \
caller... */  
     if (cbdataReferenceValid(this))
         copyRead(server, ReadServer);
-
-    cbdataInternalUnlock(this);	/* ??? */
 }
 
 static void
@@ -496,11 +488,10 @@
     TunnelStateData *tunnelState = static_cast<TunnelStateData *>(io.data);
     debugs(26, 3, HERE << io.conn);
     /* Temporary lock to protect our own feets (comm_close -> tunnelClientClosed -> \
                Free) */
-    cbdataInternalLock(tunnelState);
+    CbcPointer<TunnelStateData> safetyLock(tunnelState);
 
     tunnelState->client.closeIfOpen();
     tunnelState->server.closeIfOpen();
-    cbdataInternalUnlock(tunnelState);
 }
 
 void
@@ -578,15 +569,13 @@
     debugs(26, 3, HERE << "FD " << fd);
     assert(tunnelState != NULL);
     /* temporary lock to save our own feets (comm_close -> tunnelClientClosed -> \
                Free) */
-    cbdataInternalLock(tunnelState);
+    CbcPointer<TunnelStateData> safetyLock(tunnelState);
 
     if (Comm::IsConnOpen(tunnelState->client.conn))
         tunnelState->client.conn->close();
 
     if (Comm::IsConnOpen(tunnelState->server.conn))
         tunnelState->server.conn->close();
-
-    cbdataInternalUnlock(tunnelState);
 }
 
 static void
@@ -797,21 +786,6 @@
 
 CBDATA_CLASS_INIT(TunnelStateData);
 
-void *
-TunnelStateData::operator new (size_t)
-{
-    CBDATA_INIT_TYPE(TunnelStateData);
-    TunnelStateData *result = cbdataAlloc(TunnelStateData);
-    return result;
-}
-
-void
-TunnelStateData::operator delete (void *address)
-{
-    TunnelStateData *t = static_cast<TunnelStateData *>(address);
-    cbdataFree(t);
-}
-
 bool
 TunnelStateData::noConnections() const
 {


--===============0704267386==--


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic