]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Polish: update the RefCount API a bt and split Lock out
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 29 Oct 2012 04:59:58 +0000 (22:59 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 29 Oct 2012 04:59:58 +0000 (22:59 -0600)
* Shuffle RefCount.h and its unit-tests into src/base/

* Reworks struct Refcountable_  into class LockableObject in its own header
 + changing the reference counter accessors to a lock()/unlock() names
 + some minor symbol updates of code directly utilizing the RefCountable_
   members

With this we can begin the process of replacing our multiple different
implementations of the reference-counting pattern using LockableObject.

No code changes have been made. Just symbol polishing.

TODO: update the unit-tests for refcounting to use CPPUnit

58 files changed:
src/AccessLogEntry.h
src/ClientRequestContext.h
src/DelayIdComposite.h
src/DiskIO/DiskDaemon/DiskdFile.cc
src/DiskIO/DiskDaemon/DiskdIOStrategy.cc
src/DiskIO/DiskDaemon/DiskdIOStrategy.h
src/DiskIO/DiskDaemon/diomsg.h
src/DiskIO/DiskFile.h
src/DiskIO/DiskIOStrategy.h
src/DiskIO/IORequestor.h
src/DiskIO/ReadRequest.h
src/DiskIO/WriteRequest.h
src/MemBlob.cc
src/MemBlob.h
src/NullDelayId.h
src/SquidConfig.h
src/Store.h
src/StoreIOState.h
src/StoreSearch.h
src/adaptation/History.h
src/adaptation/Message.h
src/adaptation/Service.h
src/adaptation/ServiceConfig.h
src/adaptation/ServiceGroups.h
src/adaptation/icap/History.h
src/adaptation/icap/icap_log.h
src/auth/Scheme.h
src/auth/User.cc
src/auth/User.h
src/auth/UserRequest.cc
src/auth/basic/UserRequest.h
src/auth/digest/UserRequest.cc
src/auth/negotiate/UserRequest.cc
src/auth/ntlm/UserRequest.cc
src/base/Lock.h [new file with mode: 0644]
src/base/Makefile.am
src/base/RefCount.h [moved from include/RefCount.h with 78% similarity]
src/base/testRefCount.cc [moved from test-suite/refcount.cc with 97% similarity]
src/clientStream.h
src/client_side.h
src/client_side_reply.h
src/comm/Connection.h
src/comm/forward.h
src/esi/Element.h
src/esi/Parser.h
src/esi/Segment.h
src/format/Format.h
src/forward.h
src/fs/rock/RockSwapDir.cc
src/fs/ufs/RebuildState.h
src/ipc/Request.h
src/ipc/Response.h
src/ipc/mem/Pointer.h
src/log/Formats.h
src/mgr/QueryParam.h
src/mgr/forward.h
src/ssl/ErrorDetailManager.h
test-suite/Makefile.am

index 8ed08f930c2533cca608bffc52e9243147881b12..a0307979c2487ab39504c8ef59a450315daa4acf 100644 (file)
@@ -31,6 +31,7 @@
 #define SQUID_HTTPACCESSLOGENTRY_H
 
 #include "anyp/PortCfg.h"
+#include "base/RefCount.h"
 #include "comm/Connection.h"
 #include "HttpHeader.h"
 #include "HttpVersion.h"
@@ -43,7 +44,6 @@
 #include "adaptation/icap/Elements.h"
 #endif
 #include "Notes.h"
-#include "RefCount.h"
 #if USE_SSL
 #include "ssl/gadgets.h"
 #endif
index f597107598db5a9aacb170fc62140ee22358d1dd..3c7f817c7e8e799408b3bcae313bc7f46019125d 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef SQUID_CLIENTREQUESTCONTEXT_H
 #define SQUID_CLIENTREQUESTCONTEXT_H
 
+#include "base/RefCount.h"
 #include "cbdata.h"
-#include "RefCount.h"
 #include "ipcache.h"
 
 #if USE_ADAPTATION
index 9e50c4db785f7578deacb6724a1d3fdae9cbd590..d073cb8257d176b99ff64417e2283e893d4dd527 100644 (file)
@@ -38,8 +38,8 @@
 #define DELAYIDCOMPOSITE_H
 
 #if USE_DELAY_POOLS
+#include "base/RefCount.h"
 #include "fatal.h"
-#include "RefCount.h"
 
 class DeferredRead;
 
index 9625d0eb79d06776e650fef7d1ac4db779875f6a..9ab2b7b3c14bdb2edb0d623d7a79f34f6fc7e3b8 100644 (file)
@@ -386,7 +386,7 @@ DiskdFile::readDone(diomsg * M)
     assert (M->requestor);
     ReadRequest::Pointer readRequest = dynamic_cast<ReadRequest *>(M->requestor);
     /* remove the free protection */
-    readRequest->RefCountDereference();
+    readRequest->unlock();
 
     if (M->status < 0) {
         ++diskd_stats.read.fail;
@@ -410,7 +410,7 @@ DiskdFile::writeDone(diomsg *M)
     assert (M->requestor);
     WriteRequest::Pointer writeRequest = dynamic_cast<WriteRequest *>(M->requestor);
     /* remove the free protection */
-    writeRequest->RefCountDereference();
+    writeRequest->unlock();
 
     if (M->status < 0) {
         errorOccured = true;
index 75f8f65d9edf25ead1503ec5e7300ceee6548c49..fcc0b45400afba95ee4e2b87679db2b8194d7f2c 100644 (file)
@@ -324,7 +324,7 @@ DiskdIOStrategy::handle(diomsg * M)
 
     if (M->newstyle) {
         DiskdFile *theFile = (DiskdFile *)M->callback_data;
-        theFile->RefCountDereference();
+        theFile->unlock();
         theFile->completed (M);
     } else
         switch (M->mtype) {
@@ -354,16 +354,16 @@ DiskdIOStrategy::handle(diomsg * M)
 }
 
 int
-DiskdIOStrategy::send(int mtype, int id, DiskdFile *theFile, size_t size, off_t offset, ssize_t shm_offset, RefCountable_ *requestor)
+DiskdIOStrategy::send(int mtype, int id, DiskdFile *theFile, size_t size, off_t offset, ssize_t shm_offset, Lock *requestor)
 {
     diomsg M;
     M.callback_data = cbdataReference(theFile);
-    theFile->RefCountReference();
+    theFile->lock();
     M.requestor = requestor;
     M.newstyle = true;
 
     if (requestor)
-        requestor->RefCountReference();
+        requestor->lock();
 
     return SEND(&M, mtype, id, size, offset, shm_offset);
 }
index 57f8efb4afac7b1218a019c46c4c3ca760a8b9b6..df214b1c15de67e665a15a286207f53ecb3336e3 100644 (file)
@@ -62,7 +62,7 @@ public:
 class DiskFile;
 
 class DiskdFile;
-
+class Lock;
 class ReadRequest;
 
 /// \ingroup diskd
@@ -80,8 +80,8 @@ public:
     virtual void init();
     virtual void sync();
     virtual int callback();
-    virtual void statfs(StoreEntry & sentry)const;
-    int send(int mtype, int id, DiskdFile *theFile, size_t size, off_t offset, ssize_t shm_offset, RefCountable_ *requestor);
+    virtual void statfs(StoreEntry & sentry) const;
+    int send(int mtype, int id, DiskdFile *theFile, size_t size, off_t offset, ssize_t shm_offset, Lock *requestor);
 
     /** public for accessing return address's */
     SharedMemory shm;
index 897985d408ef32e46c1d3aaa7f921b05e2add882..0dc8ad29e99f999314c81016d731b5713af8fc88 100644 (file)
@@ -17,14 +17,14 @@ enum {
     _MQD_UNLINK
 };
 
-struct RefCountable_;
+class Lock;
 
 struct diomsg {
     mtyp_t mtype;
     int id;
     int seq_no;
     void * callback_data;
-    RefCountable_ * requestor;
+    Lock * requestor;
     size_t size;
     off_t offset;
     int status;
index b94f8763f7efaf20df3d6d019280182e2b45ecfd..9e45b30a0842b813de2f1cfa29f8cabceaf1936f 100644 (file)
 #ifndef SQUID_DISKFILE_H
 #define SQUID_DISKFILE_H
 
+#include "base/RefCount.h"
 #include "typedefs.h"
 
-#include "RefCount.h"
-
 class IORequestor;
 
 class ReadRequest;
index e9f9f0d599c0345e40271f0a3374414797a2b783..ef8d06cb767e65cccee61a77d4c28267dfc94ca7 100644 (file)
@@ -31,8 +31,8 @@
 #ifndef SQUID_DISKIOSTRATEGY_H
 #define SQUID_DISKIOSTRATEGY_H
 
+#include "base/RefCount.h"
 #include "Store.h"
-#include "RefCount.h"
 
 class DiskFile;
 
index 3ec6ec7bbe3148f2885f03b20861049ddc5576b3..a21e0302868dae6c89f4242faf9f08d2ebfcdf8b 100644 (file)
@@ -32,7 +32,7 @@
 #ifndef SQUID_IOREQUESTOR_H
 #define SQUID_IOREQUESTOR_H
 
-#include "RefCount.h"
+#include "base/RefCount.h"
 
 class ReadRequest;
 
index 6effe383afeec0c33a160a3c773c69b660101ba0..741ee61af9cb89b9bf0196e223201fa6032845cb 100644 (file)
@@ -32,8 +32,8 @@
 #ifndef SQUID_READREQUEST_H
 #define SQUID_READREQUEST_H
 
+#include "base/RefCount.h"
 #include "cbdata.h"
-#include "RefCount.h"
 
 class ReadRequest : public RefCountable
 {
index 7731e2519c22ab0ea1fade24a57f45feff85dc09..2f2c57a157d3ce57bb01c9e45096bb51095c3564 100644 (file)
@@ -32,8 +32,8 @@
 #ifndef SQUID_WRITEREQUEST_H
 #define SQUID_WRITEREQUEST_H
 
+#include "base/RefCount.h"
 #include "cbdata.h"
-#include "RefCount.h"
 
 class WriteRequest : public RefCountable
 {
index 5daf73f3bf836cb1822c21f0f12d0a1821027ef6..9fc396498028147696a03f4245c790d6bcd9cd57 100644 (file)
@@ -142,6 +142,6 @@ MemBlob::dump(std::ostream &os) const
     << "mem:" << static_cast<void*>(mem)
     << ",capacity:" << capacity
     << ",size:" << size
-    << ",refs:" << RefCountCount() << "; ";
+    << ",refs:" << LockCount() << "; ";
     return os;
 }
index 86d54c13a9682b5be683bedebe52bc407bcd8d6f..7fe3b99990500a7e9ec3aab97303564796484909 100644 (file)
@@ -34,8 +34,8 @@
 #define MEMBLOB_DEBUGSECTION 24
 
 #include "base/InstanceId.h"
+#include "base/RefCount.h"
 #include "MemPool.h"
-#include "RefCount.h"
 
 /// Various MemBlob class-wide statistics.
 class MemBlobStats
index a151d3ade8effcd801f6b347a5486ca42982f14a..41f70252262685bbd761a99ea7b58b133b6df2b2 100644 (file)
@@ -38,7 +38,7 @@
 #define NULLDELAYID_H
 
 #if USE_DELAY_POOLS
-#include "RefCount.h"
+#include "base/RefCount.h"
 #include "DelayIdComposite.h"
 
 class NullDelayId : public DelayIdComposite
index 40a8a235f85d5a87f87f1352f4a08b95a15f5809..b93a99876e867b4528bac200bbadfd1f01e7d64e 100644 (file)
@@ -30,6 +30,7 @@
  */
 
 #include "acl/AclAddress.h"
+#include "base/RefCount.h"
 #include "ClientDelayConfig.h"
 #include "DelayConfig.h"
 #include "HelperChildConfig.h"
@@ -37,7 +38,6 @@
 #include "icmp/IcmpConfig.h"
 #include "ip/Address.h"
 #include "Notes.h"
-#include "RefCount.h"
 #include "YesNoNone.h"
 
 #if USE_SSL
index 32b216aa557af52e64689d299b288dfc3bab3096..44c1fda7995833607d8c849a3aca8aef3e7e3235 100644 (file)
  \ingroup FileSystems
  */
 
+#include "base/RefCount.h"
 #include "comm/forward.h"
 #include "CommRead.h"
 #include "hash.h"
 #include "HttpReply.h"
 #include "HttpRequestMethod.h"
 #include "Range.h"
-#include "RefCount.h"
 #include "RemovalPolicy.h"
 #include "StoreIOBuffer.h"
 #include "StoreStats.h"
index 17317b8aca384a4d4e1e015956a781ff9251c211..6f0f6d2676d28f37aff9c4361e17269656ac326a 100644 (file)
@@ -32,8 +32,8 @@
 #ifndef SQUID_STOREIOSTATE_H
 #define SQUID_STOREIOSTATE_H
 
+#include "base/RefCount.h"
 #include "cbdata.h"
-#include "RefCount.h"
 
 class StoreIOState : public RefCountable
 {
index ca018471bc1c49106105a98e568b3ec4b6b4c1e6..0eb3d88cbfc0ebabc4436d27ba360781f2b38abf 100644 (file)
@@ -31,7 +31,7 @@
 #ifndef SQUID_STORESEARCH_H
 #define SQUID_STORESEARCH_H
 
-#include "RefCount.h"
+#include "base/RefCount.h"
 #include "Store.h"
 
 class StoreSearch : public RefCountable
index 2067a7f709f2e83d73f5c1d0b6b27f043abb7c8a..4a3b4361dc51f573d0f18bd3b5b356da0930e2c0 100644 (file)
@@ -3,9 +3,9 @@
 
 #include "adaptation/DynamicGroupCfg.h"
 #include "Array.h"
+#include "base/RefCount.h"
 #include "HttpHeader.h"
 #include "Notes.h"
-#include "RefCount.h"
 #include "SquidString.h"
 
 namespace Adaptation
index 282865e0a0c62040be29bb0208abe6c758f79f70..64ac1f68628a900fb283841d7bf3ac6cd30bd2c9 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef SQUID__ADAPTATION__MESSAGE_H
 #define SQUID__ADAPTATION__MESSAGE_H
 
-#include "RefCount.h"
+#include "base/RefCount.h"
 
 class HttpMsg;
 class BodyPipe;
index 87c31f57d791facd5a1196ab057b37fbed885882..3b60b4bf51fcd5a0e92e5075340520460d9bd546 100644 (file)
@@ -2,10 +2,10 @@
 #define SQUID_ADAPTATION__SERVICE_H
 
 #include "SquidString.h"
-#include "RefCount.h"
 #include "adaptation/forward.h"
 #include "adaptation/Elements.h"
 #include "adaptation/ServiceConfig.h"
+#include "base/RefCount.h"
 
 // TODO: Move src/ICAP/ICAPServiceRep.h API comments here and update them
 
index dc73a59d12c3ce56ceccfe33bc326daf3ddd363d..940c45a9655d6b12ced34e94667e076385af8543 100644 (file)
@@ -2,7 +2,7 @@
 #define SQUID_ADAPTATION__SERVICE_CONFIG_H
 
 #include "SquidString.h"
-#include "RefCount.h"
+#include "base/RefCount.h"
 #include "adaptation/Elements.h"
 
 namespace Adaptation
index b21a417401dc3ae1c010b237cdf33a6bcd08c44e..043bb74e6997f0582157e89be38333b3f46d59cc 100644 (file)
@@ -3,9 +3,9 @@
 
 #include "SquidString.h"
 #include "Array.h"
-#include "RefCount.h"
 #include "adaptation/Elements.h"
 #include "adaptation/forward.h"
+#include "base/RefCount.h"
 
 namespace Adaptation
 {
index d72c28705d2c7b4259307bf64f329024b4be5c7e..839ff8a92df0f8db74693b243e4b748e77b6a5d1 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef SQUID_ICAPHISTORY_H
 #define SQUID_ICAPHISTORY_H
 
+#include "base/RefCount.h"
 #include "enums.h"
-#include "RefCount.h"
 #include "SquidString.h"
 
 namespace Adaptation
index 5cb88c182627753aea096b28dbec4a140ac5ebb0..f11de68a9eb7eb6e4276ecaede11283cea7f7b43 100644 (file)
@@ -2,7 +2,7 @@
 #define ICAP_LOG_H_
 
 #include "AccessLogEntry.h"
-#include "RefCount.h"
+#include "base/RefCount.h"
 
 typedef RefCount<AccessLogEntry> AccessLogEntryPointer;
 class AccessLogEntry;
index 2842bd3e0f11a566e788af11e89abdf7c26cef8e..8a677eb5b94db453c8acfd00dc3d8bc7f65891fb 100644 (file)
@@ -34,7 +34,7 @@
 #if USE_AUTH
 
 #include "Array.h"
-#include "RefCount.h"
+#include "base/RefCount.h"
 
 /**
  \defgroup AuthSchemeAPI       Authentication Scheme API
index 43266f2c318f7bad98497fe8bd7da4e8d90e8a7b..d42041109d5f6a1f88ca6424e76e57651bcf978f 100644 (file)
@@ -151,7 +151,7 @@ Auth::User::absorb(Auth::User::Pointer from)
 Auth::User::~User()
 {
     debugs(29, 5, HERE << "Freeing auth_user '" << this << "'.");
-    assert(RefCountCount() == 0);
+    assert(LockCount() == 0);
 
     /* free cached acl results */
     aclCacheMatchFlush(&proxy_match_cache);
@@ -223,7 +223,7 @@ Auth::User::cacheCleanup(void *datanotused)
                auth_user->auth_type << "\n\tUsername: " << username <<
                "\n\texpires: " <<
                (long int) (auth_user->expiretime + ::Config.authenticateTTL) <<
-               "\n\treferences: " << (long int) auth_user->RefCountCount());
+               "\n\treferences: " << auth_user->LockCount());
 
         if (auth_user->expiretime + ::Config.authenticateTTL <= current_time.tv_sec) {
             debugs(29, 5, HERE << "Removing user " << username << " from cache due to timeout.");
index a5ae2ea9e7b9753e0d22d7729399505f86ae8833..11d2e15078bc78eb0adad543bfc63a352c8de6ff 100644 (file)
@@ -36,9 +36,9 @@
 
 #include "auth/CredentialState.h"
 #include "auth/Type.h"
+#include "base/RefCount.h"
 #include "dlink.h"
 #include "ip/Address.h"
-#include "RefCount.h"
 
 class AuthUserHashPointer;
 class StoreEntry;
index 01bfd7285e6d6afecb63c18e536dec960501186d..fa65fcc636061a438a0866136cf90e5204ab7f30 100644 (file)
@@ -117,7 +117,7 @@ Auth::UserRequest::UserRequest():
 
 Auth::UserRequest::~UserRequest()
 {
-    assert(RefCountCount()==0);
+    assert(LockCount()==0);
     debugs(29, 5, HERE << "freeing request " << this);
 
     if (user() != NULL) {
index 304e8cf9df1844b7c03be5c19b3ca41223a16718..4dafb094f3a5e8546cd7670a2e5d61d75ac1e13d 100644 (file)
@@ -21,7 +21,7 @@ public:
     MEMPROXY_CLASS(Auth::Basic::UserRequest);
 
     UserRequest() {}
-    virtual ~UserRequest() { assert(RefCountCount()==0); }
+    virtual ~UserRequest() { assert(LockCount()==0); }
 
     virtual int authenticated() const;
     virtual void authenticate(HttpRequest * request, ConnStateData *conn, http_hdr_type type);
index dfd72462aa991454a0592d56e08c329420fbef08..11764a319eb5b6a15ccf5ef0a06d013fae6d509d 100644 (file)
@@ -28,7 +28,7 @@ Auth::Digest::UserRequest::UserRequest() :
  */
 Auth::Digest::UserRequest::~UserRequest()
 {
-    assert(RefCountCount()==0);
+    assert(LockCount()==0);
 
     safe_free(nonceb64);
     safe_free(cnonce);
index c93e70375aecae70ac02076af27fc37619d80b8b..1b0aef6299007d195cdb022df740744c5bd642df 100644 (file)
@@ -22,7 +22,7 @@ Auth::Negotiate::UserRequest::UserRequest()
 
 Auth::Negotiate::UserRequest::~UserRequest()
 {
-    assert(RefCountCount()==0);
+    assert(LockCount()==0);
     safe_free(server_blob);
     safe_free(client_blob);
 
index 3648d51feb52c150feab6fd4a05820c90b7fecdc..2d31ff4f3dddb23b3ede2d24ee5feebb1b1cb655 100644 (file)
@@ -19,7 +19,7 @@ Auth::Ntlm::UserRequest::UserRequest()
 
 Auth::Ntlm::UserRequest::~UserRequest()
 {
-    assert(RefCountCount()==0);
+    assert(LockCount()==0);
     safe_free(server_blob);
     safe_free(client_blob);
 
diff --git a/src/base/Lock.h b/src/base/Lock.h
new file mode 100644 (file)
index 0000000..5153fda
--- /dev/null
@@ -0,0 +1,58 @@
+#ifndef SQUID_SRC_BASE_LOCK_H
+#define SQUID_SRC_BASE_LOCK_H
+
+/**
+ * This class provides a tracking counter and presents
+ * lock(), unlock() and LockCount() accessors.
+ *
+ * All locks must be cleared with unlock() before this object
+ * is destroyed.
+ *
+ * Accessors provided by this interface are not private,
+ * to allow class hierarchies.
+ *
+ * Build with -DLOCKCOUNT_DEBUG flag to enable lock debugging.
+ * It is disabled by default due to the cost of debug output.
+ */
+class Lock {
+public:
+    Lock():count_(0) {}
+
+    virtual ~Lock() { assert(count_ == 0); }
+
+    /// Register one lock / reference against this object.
+    /// All locks must be cleared before it may be destroyed.
+    void lock() const {
+#if defined(LOCKCOUNT_DEBUG)
+        old_debug(0,1)("Incrementing this %p from count %u\n",this,count_);
+#endif
+        ++count_;
+    }
+
+    /// Clear one lock / reference against this object.
+    /// All locks must be cleared before it may be destroyed.
+    unsigned unlock() const {
+#if defined(LOCKCOUNT_DEBUG)
+        old_debug(0,1)("Decrementing this %p from count %u\n",this,count_);
+#endif
+        assert(count_ > 0);
+        return --count_;
+    }
+
+    /// Inspect the current count of references.
+    unsigned LockCount() const { return count_; }
+
+private:
+    mutable unsigned count_; ///< number of references currently being tracked
+};
+
+// For clarity we provide some aliases for the tracking mechanisms
+// using Lock so that we can easily see what type of smart pointers
+// are to be used for the child object.
+// NP: CbcPointer<> and RefCount<> pointers should be used consistently
+//     for any given child class type
+
+/// The locking interface for use on Reference-Counted classes
+#define RefCountable virtual Lock
+
+#endif /* SQUID_SRC_BASE_LOCK_H */
index 3ad8e4d2ecb7536337b73ceebabadfc1da7a98b3..38e4f3b1432da032503ef781b85f3f0dbbe38667 100644 (file)
@@ -16,9 +16,24 @@ libbase_la_SOURCES = \
        TidyPointer.h \
        CbcPointer.h \
        InstanceId.h \
+       Lock.h \
        RunnersRegistry.cc \
        RunnersRegistry.h \
        Subscription.h \
        TextException.cc \
        TextException.h \
        StringArea.h
+
+check_PROGRAMS += testRefCount
+
+testRefCount_SOURCES= \
+       Lock.h \
+       RefCount.h \
+       testRefCount.cc
+
+testRefCount_LDADD = \
+       libbase.la \
+       $(top_builddir)/lib/libmiscutil.la \
+       $(COMPAT_LIB) \
+       $(XTRA_LIBS)
+
similarity index 78%
rename from include/RefCount.h
rename to src/base/RefCount.h
index c0f0fe9be6fd2f23a7b14735825890cee7aba9ee..a9ef060ace8d79af1db5594dc1644c4f643d0429 100644 (file)
 #ifndef SQUID_REFCOUNT_H_
 #define SQUID_REFCOUNT_H_
 
+// reference counting requires the Lock API on base classes
+#include "base/Lock.h"
+
 #if HAVE_IOSTREAM
 #include <iostream>
 #endif
 
+/**
+ * Template for Reference Counting pointers.
+ *
+ * Objects of type 'C' must inherit from 'Lockable' in base/Lock.h
+ * which provides the locking interface used by reference counting.
+ */
 template <class C>
 class RefCount
 {
@@ -90,54 +99,24 @@ private:
         C const (*tempP_) (p_);
         p_ = newP;
 
-        if (tempP_ && tempP_->RefCountDereference() == 0)
+        if (tempP_ && tempP_->unlock() == 0)
             delete tempP_;
     }
 
     void reference (const RefCount& p) {
         if (p.p_)
-            p.p_->RefCountReference();
+            p.p_->lock();
     }
 
     C const *p_;
 
 };
 
-struct RefCountable_ {
-    RefCountable_():count_(0) {}
-
-    virtual ~RefCountable_() { assert(count_ == 0); }
-
-    /* Not private, to allow class hierarchies */
-    void RefCountReference() const {
-#if REFCOUNT_DEBUG
-        old_debug(0,1)("Incrementing this %p from count %u\n",this,count_);
-#endif
-
-        ++count_;
-    }
-
-    unsigned RefCountDereference() const {
-#if REFCOUNT_DEBUG
-        old_debug(0,1)("Decrementing this %p from count %u\n",this,count_);
-#endif
-
-        return --count_;
-    }
-
-    unsigned RefCountCount() const { return count_; } // for debugging only
-
-private:
-    mutable unsigned count_;
-};
-
-#define RefCountable virtual RefCountable_
-
 template <class C>
 inline std::ostream &operator <<(std::ostream &os, const RefCount<C> &p)
 {
     if (p != NULL)
-        return os << p.getRaw() << '*' << p->RefCountCount();
+        return os << p.getRaw() << '*' << p->LockCount();
     else
         return os << "NULL";
 }
similarity index 97%
rename from test-suite/refcount.cc
rename to src/base/testRefCount.cc
index 6e90955315153df907152d8f5b5c192e9dde8818..e343b165992514051ebf46946858425fc7f54452 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * DEBUG: section --    Refcount allocator
  * AUTHOR:  Robert Collins
  */
 
 #include "squid.h"
-#include "RefCount.h"
+#include "base/RefCount.h"
 
-class _ToRefCount :public RefCountable
-{
+// XXX: upgrade these tests to CPPUnit testing framework
 
+class _ToRefCount : public RefCountable
+{
 public:
     _ToRefCount () {++Instances;}
-
     ~_ToRefCount() {--Instances;}
 
     int someMethod() {
@@ -50,8 +49,6 @@ public:
     }
 
     static int Instances;
-
-private:
 };
 
 typedef RefCount<_ToRefCount> ToRefCount;
@@ -61,7 +58,6 @@ int _ToRefCount::Instances = 0;
 
 class AlsoRefCountable : public RefCountable, public _ToRefCount
 {
-
 public:
     typedef RefCount<AlsoRefCountable> Pointer;
 
index c5abb04e15954f42c9e1d45ed82263b4f027092f..ce9b252c8a1079f239f5a322749dda783aa216dd 100644 (file)
@@ -32,8 +32,8 @@
 #ifndef SQUID_CLIENTSTREAM_H
 #define SQUID_CLIENTSTREAM_H
 
+#include "base/RefCount.h"
 #include "dlink.h"
-#include "RefCount.h"
 #include "StoreIOBuffer.h"
 
 /**
@@ -96,7 +96,7 @@
  */
 
 /// \ingroup ClientStreamAPI
-typedef RefCount<RefCountable_> ClientStreamData;
+typedef RefCount<Lock> ClientStreamData;
 
 class clientStreamNode;
 class ClientHttpRequest;
index 6185817102ca38b0376a9888c5e80a8a49ea20e5..2df5c9b19b3e45c93ade440d7937afe663ac854d 100644 (file)
 #define SQUID_CLIENTSIDE_H
 
 #include "base/AsyncJob.h"
+#include "base/RefCount.h"
 #include "BodyPipe.h"
 #include "comm.h"
 #include "CommCalls.h"
 #include "HttpRequest.h"
 #include "HttpControlMsg.h"
 #include "HttpParser.h"
-#include "RefCount.h"
 #include "StoreIOBuffer.h"
 #if USE_AUTH
 #include "auth/UserRequest.h"
index 155b814d3ea438fa3ccd5be54fda6cfe7a311665..50ece1136938c53e0a7bd0590da34d41f323db30 100644 (file)
 #ifndef SQUID_CLIENTSIDEREPLY_H
 #define SQUID_CLIENTSIDEREPLY_H
 
+#include "base/RefCount.h"
 #include "client_side_request.h"
 #include "clientStream.h"
 #include "HttpHeader.h"
-#include "RefCount.h"
 #include "RequestFlags.h"
 #include "StoreClient.h"
 
index 1f15a004630a4074d2abebca1c0a407269413ce8..ef10cba14ed07965a8aa86c46510914b2090df8d 100644 (file)
 #ifndef _SQUIDCONNECTIONDETAIL_H_
 #define _SQUIDCONNECTIONDETAIL_H_
 
+#include "base/RefCount.h"
 #include "comm/forward.h"
 #include "defines.h"
 #include "hier_code.h"
 #include "ip/Address.h"
 #include "MemPool.h"
-#include "RefCount.h"
 #include "typedefs.h"
 #if USE_SQUID_EUI
 #include "eui/Eui48.h"
index ad333d0900d41b206af9496022c8e009d1278c46..2d5a5031f0a3452a804ba6f9ea12eaf04a1bee5b 100644 (file)
@@ -2,7 +2,7 @@
 #define _SQUID_COMM_FORWARD_H
 
 #include "Array.h"
-#include "RefCount.h"
+#include "base/RefCount.h"
 
 namespace Comm
 {
index 9146988159ea0d70debdef72581911db8c32235f..d8bbdc5155c51e184678faf2b5ea0ca4c3929461 100644 (file)
@@ -31,9 +31,9 @@
 #ifndef SQUID_ESIELEMENT_H
 #define SQUID_ESIELEMENT_H
 
+#include "base/RefCount.h"
 #include "Debug.h"
 #include "esi/Segment.h"
-#include "RefCount.h"
 
 typedef enum {
     ESI_PROCESS_COMPLETE = 0,
index 9af51de8663cab715b464366bc48f44cf7b97522..82eaa2676a2c3fe26cf0599da44acaa0c685e16f 100644 (file)
@@ -40,8 +40,7 @@ public:
     virtual ~ESIParserClient() {};
 };
 
-/* for RefCountable */
-#include "RefCount.h"
+#include "base/RefCount.h"
 
 class ESIParser : public RefCountable
 {
index 04e0ce46177741d44560a0c522a56faac3ac07ef..56ad448feda0cc2c9ad4b6001272452c094b36de 100644 (file)
@@ -35,9 +35,9 @@
  * or perhaps use membuffers here?
  */
 
+#include "base/RefCount.h"
 #include "cbdata.h"
 #include "defines.h"
-#include "RefCount.h"
 #include "SquidString.h"
 
 class ESISegment : public RefCountable
index 7e9795a98251bbc39d095befb633d4210dc78576..2415815c08ae25bdf5138c32571164c436141846 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef _SQUID_FORMAT_FORMAT_H
 #define _SQUID_FORMAT_FORMAT_H
 
-#include "RefCount.h"
+#include "base/RefCount.h"
 /*
  * Squid configuration allows users to define custom formats in
  * several components.
index da3e74a427af5c3baa005ad6350d9478bf2f072b..0a754c6ee9b720b8750944aebc17a0e56b6771d8 100644 (file)
@@ -2,13 +2,13 @@
 #define SQUID_FORWARD_H
 
 #include "Array.h"
+#include "base/RefCount.h"
 #include "comm.h"
 #include "comm/Connection.h"
 #include "err_type.h"
 #include "fde.h"
 #include "HttpStatusCode.h"
 #include "ip/Address.h"
-#include "RefCount.h"
 
 /* forward decls */
 
index e8c23006f3df44cee78d1c5926bbf225b6fb7309..aa4dd966df532684f718a4a56268a9b6d4c41ea1 100644 (file)
@@ -217,7 +217,7 @@ Rock::SwapDir::init()
 
     // XXX: SwapDirs aren't refcounted. We make IORequestor calls, which
     // are refcounted. We up our count once to avoid implicit delete's.
-    RefCountReference();
+    lock();
 
     Must(!map);
     map = new DirMap(path);
index 29f69fea2e4a86d381915fa7733cf391ed6fb171..552da45d31468aaeb9650eaab0e8fc8bd3ef667c 100644 (file)
@@ -30,7 +30,7 @@
 #ifndef SQUID_FS_UFS_REBUILDSTATE_H
 #define SQUID_FS_UFS_REBUILDSTATE_H
 
-#include "RefCount.h"
+#include "base/RefCount.h"
 #include "UFSSwapDir.h"
 #include "UFSSwapLogParser.h"
 #include "store_rebuild.h"
index 6e90a63691f8337aa61732c79d702116c7b94d57..ca4aa811b0a06f69c31e065c00e11c67aed16813 100644 (file)
@@ -6,8 +6,8 @@
 #ifndef SQUID_IPC_REQUEST_H
 #define SQUID_IPC_REQUEST_H
 
+#include "base/RefCount.h"
 #include "ipc/forward.h"
-#include "RefCount.h"
 
 namespace Ipc
 {
index 6ecb25f4333025aba0fca4af9de0942d3194e0c5..dfd6fe2171953860558670b5f7e8f7d90b1327bb 100644 (file)
@@ -6,8 +6,8 @@
 #ifndef SQUID_IPC_RESPONSE_H
 #define SQUID_IPC_RESPONSE_H
 
+#include "base/RefCount.h"
 #include "ipc/forward.h"
-#include "RefCount.h"
 
 namespace Ipc
 {
index 4a1d95d8590aac1d577e5f5da7f9a892db5faa6d..55cb55b86b63c4e022c6e0bae1a8370ec843a1ac 100644 (file)
@@ -4,9 +4,9 @@
 #ifndef SQUID_IPC_MEM_POINTER_H
 #define SQUID_IPC_MEM_POINTER_H
 
+#include "base/RefCount.h"
 #include "base/TextException.h"
 #include "ipc/mem/Segment.h"
-#include "RefCount.h"
 
 namespace Ipc
 {
index 0e2dd16eca3d9faa24449518edde42f7cb4a6c66..b77953005f2ecfbdb3535e6d426554aea3464e93 100644 (file)
@@ -2,7 +2,7 @@
 #define _SQUID_LOG_FORMATS_H
 
 #include "AccessLogEntry.h"
-#include "RefCount.h"
+#include "base/RefCount.h"
 
 typedef RefCount<AccessLogEntry> AccessLogEntryPointer;
 class AccessLogEntry;
index 6196689401c601281922b517b76dc5eb4e70b565..0770b05f46561842915eac7c17b31a80547747c3 100644 (file)
@@ -6,8 +6,8 @@
 #ifndef SQUID_MGR_QUERY_PARAM_H
 #define SQUID_MGR_QUERY_PARAM_H
 
+#include "base/RefCount.h"
 #include "ipc/forward.h"
-#include "RefCount.h"
 
 namespace Mgr
 {
index b26c54a67ec1d0ef3db18df805a0d1ca1f39aaa0..e675166981bbac2300a4ebd719fc4168af9a3b28 100644 (file)
@@ -6,7 +6,7 @@
 #ifndef SQUID_MGR_FORWARD_H
 #define SQUID_MGR_FORWARD_H
 
-#include "RefCount.h"
+#include "base/RefCount.h"
 
 namespace Mgr
 {
index 7e69e8db11c9394503785e634a8d9b5f0a739dc8..a2809c884adf2499a824db3e871f78bad9e970db 100644 (file)
@@ -1,9 +1,9 @@
 #ifndef _SQUID_SSL_ERRORDETAILMANAGER_H
 #define _SQUID_SSL_ERRORDETAILMANAGER_H
 
+#include "base/RefCount.h"
 #include "ssl/gadgets.h"
 #include "ssl/support.h"
-#include "RefCount.h"
 #include "SquidString.h"
 
 #if HAVE_MAP
index 5818f3502b11be35a6ec9d59e83c4c6a3b5ec319..fa486c876797f0bb21c58c382355dd4adc8e183b 100644 (file)
@@ -30,7 +30,6 @@ TESTS += debug \
        syntheticoperators \
        VirtualDeleteOperator \
        StackTest \
-       refcount\
        splay\
        MemPoolTest\
        mem_node_test\
@@ -43,7 +42,6 @@ check_PROGRAMS += debug \
                MemPoolTest\
                mem_node_test\
                mem_hdr_test \
-               refcount\
                splay \
                StackTest \
                syntheticoperators \
@@ -86,8 +84,6 @@ mem_hdr_test_LDADD = \
 
 MemPoolTest_SOURCES = MemPoolTest.cc
 
-refcount_SOURCES = refcount.cc
-
 splay_SOURCES = splay.cc
 
 StackTest_SOURCES = StackTest.cc $(DEBUG_SOURCE)