From: Amos Jeffries Date: Mon, 29 Oct 2012 04:59:58 +0000 (-0600) Subject: Polish: update the RefCount API a bt and split Lock out X-Git-Tag: SQUID_3_4_0_1~542 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8bf217bd43b7f15a7e2c14aa21800dc16b7e9af4;p=thirdparty%2Fsquid.git Polish: update the RefCount API a bt and split Lock out * 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 --- diff --git a/src/AccessLogEntry.h b/src/AccessLogEntry.h index 8ed08f930c..a0307979c2 100644 --- a/src/AccessLogEntry.h +++ b/src/AccessLogEntry.h @@ -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 diff --git a/src/ClientRequestContext.h b/src/ClientRequestContext.h index f597107598..3c7f817c7e 100644 --- a/src/ClientRequestContext.h +++ b/src/ClientRequestContext.h @@ -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 diff --git a/src/DelayIdComposite.h b/src/DelayIdComposite.h index 9e50c4db78..d073cb8257 100644 --- a/src/DelayIdComposite.h +++ b/src/DelayIdComposite.h @@ -38,8 +38,8 @@ #define DELAYIDCOMPOSITE_H #if USE_DELAY_POOLS +#include "base/RefCount.h" #include "fatal.h" -#include "RefCount.h" class DeferredRead; diff --git a/src/DiskIO/DiskDaemon/DiskdFile.cc b/src/DiskIO/DiskDaemon/DiskdFile.cc index 9625d0eb79..9ab2b7b3c1 100644 --- a/src/DiskIO/DiskDaemon/DiskdFile.cc +++ b/src/DiskIO/DiskDaemon/DiskdFile.cc @@ -386,7 +386,7 @@ DiskdFile::readDone(diomsg * M) assert (M->requestor); ReadRequest::Pointer readRequest = dynamic_cast(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(M->requestor); /* remove the free protection */ - writeRequest->RefCountDereference(); + writeRequest->unlock(); if (M->status < 0) { errorOccured = true; diff --git a/src/DiskIO/DiskDaemon/DiskdIOStrategy.cc b/src/DiskIO/DiskDaemon/DiskdIOStrategy.cc index 75f8f65d9e..fcc0b45400 100644 --- a/src/DiskIO/DiskDaemon/DiskdIOStrategy.cc +++ b/src/DiskIO/DiskDaemon/DiskdIOStrategy.cc @@ -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); } diff --git a/src/DiskIO/DiskDaemon/DiskdIOStrategy.h b/src/DiskIO/DiskDaemon/DiskdIOStrategy.h index 57f8efb4af..df214b1c15 100644 --- a/src/DiskIO/DiskDaemon/DiskdIOStrategy.h +++ b/src/DiskIO/DiskDaemon/DiskdIOStrategy.h @@ -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; diff --git a/src/DiskIO/DiskDaemon/diomsg.h b/src/DiskIO/DiskDaemon/diomsg.h index 897985d408..0dc8ad29e9 100644 --- a/src/DiskIO/DiskDaemon/diomsg.h +++ b/src/DiskIO/DiskDaemon/diomsg.h @@ -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; diff --git a/src/DiskIO/DiskFile.h b/src/DiskIO/DiskFile.h index b94f8763f7..9e45b30a08 100644 --- a/src/DiskIO/DiskFile.h +++ b/src/DiskIO/DiskFile.h @@ -31,10 +31,9 @@ #ifndef SQUID_DISKFILE_H #define SQUID_DISKFILE_H +#include "base/RefCount.h" #include "typedefs.h" -#include "RefCount.h" - class IORequestor; class ReadRequest; diff --git a/src/DiskIO/DiskIOStrategy.h b/src/DiskIO/DiskIOStrategy.h index e9f9f0d599..ef8d06cb76 100644 --- a/src/DiskIO/DiskIOStrategy.h +++ b/src/DiskIO/DiskIOStrategy.h @@ -31,8 +31,8 @@ #ifndef SQUID_DISKIOSTRATEGY_H #define SQUID_DISKIOSTRATEGY_H +#include "base/RefCount.h" #include "Store.h" -#include "RefCount.h" class DiskFile; diff --git a/src/DiskIO/IORequestor.h b/src/DiskIO/IORequestor.h index 3ec6ec7bbe..a21e030286 100644 --- a/src/DiskIO/IORequestor.h +++ b/src/DiskIO/IORequestor.h @@ -32,7 +32,7 @@ #ifndef SQUID_IOREQUESTOR_H #define SQUID_IOREQUESTOR_H -#include "RefCount.h" +#include "base/RefCount.h" class ReadRequest; diff --git a/src/DiskIO/ReadRequest.h b/src/DiskIO/ReadRequest.h index 6effe383af..741ee61af9 100644 --- a/src/DiskIO/ReadRequest.h +++ b/src/DiskIO/ReadRequest.h @@ -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 { diff --git a/src/DiskIO/WriteRequest.h b/src/DiskIO/WriteRequest.h index 7731e2519c..2f2c57a157 100644 --- a/src/DiskIO/WriteRequest.h +++ b/src/DiskIO/WriteRequest.h @@ -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 { diff --git a/src/MemBlob.cc b/src/MemBlob.cc index 5daf73f3bf..9fc3964980 100644 --- a/src/MemBlob.cc +++ b/src/MemBlob.cc @@ -142,6 +142,6 @@ MemBlob::dump(std::ostream &os) const << "mem:" << static_cast(mem) << ",capacity:" << capacity << ",size:" << size - << ",refs:" << RefCountCount() << "; "; + << ",refs:" << LockCount() << "; "; return os; } diff --git a/src/MemBlob.h b/src/MemBlob.h index 86d54c13a9..7fe3b99990 100644 --- a/src/MemBlob.h +++ b/src/MemBlob.h @@ -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 diff --git a/src/NullDelayId.h b/src/NullDelayId.h index a151d3ade8..41f7025226 100644 --- a/src/NullDelayId.h +++ b/src/NullDelayId.h @@ -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 diff --git a/src/SquidConfig.h b/src/SquidConfig.h index 40a8a235f8..b93a99876e 100644 --- a/src/SquidConfig.h +++ b/src/SquidConfig.h @@ -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 diff --git a/src/Store.h b/src/Store.h index 32b216aa55..44c1fda799 100644 --- a/src/Store.h +++ b/src/Store.h @@ -35,13 +35,13 @@ \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" diff --git a/src/StoreIOState.h b/src/StoreIOState.h index 17317b8aca..6f0f6d2676 100644 --- a/src/StoreIOState.h +++ b/src/StoreIOState.h @@ -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 { diff --git a/src/StoreSearch.h b/src/StoreSearch.h index ca018471bc..0eb3d88cbf 100644 --- a/src/StoreSearch.h +++ b/src/StoreSearch.h @@ -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 diff --git a/src/adaptation/History.h b/src/adaptation/History.h index 2067a7f709..4a3b4361dc 100644 --- a/src/adaptation/History.h +++ b/src/adaptation/History.h @@ -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 diff --git a/src/adaptation/Message.h b/src/adaptation/Message.h index 282865e0a0..64ac1f6862 100644 --- a/src/adaptation/Message.h +++ b/src/adaptation/Message.h @@ -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; diff --git a/src/adaptation/Service.h b/src/adaptation/Service.h index 87c31f57d7..3b60b4bf51 100644 --- a/src/adaptation/Service.h +++ b/src/adaptation/Service.h @@ -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 diff --git a/src/adaptation/ServiceConfig.h b/src/adaptation/ServiceConfig.h index dc73a59d12..940c45a965 100644 --- a/src/adaptation/ServiceConfig.h +++ b/src/adaptation/ServiceConfig.h @@ -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 diff --git a/src/adaptation/ServiceGroups.h b/src/adaptation/ServiceGroups.h index b21a417401..043bb74e69 100644 --- a/src/adaptation/ServiceGroups.h +++ b/src/adaptation/ServiceGroups.h @@ -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 { diff --git a/src/adaptation/icap/History.h b/src/adaptation/icap/History.h index d72c28705d..839ff8a92d 100644 --- a/src/adaptation/icap/History.h +++ b/src/adaptation/icap/History.h @@ -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 diff --git a/src/adaptation/icap/icap_log.h b/src/adaptation/icap/icap_log.h index 5cb88c1826..f11de68a9e 100644 --- a/src/adaptation/icap/icap_log.h +++ b/src/adaptation/icap/icap_log.h @@ -2,7 +2,7 @@ #define ICAP_LOG_H_ #include "AccessLogEntry.h" -#include "RefCount.h" +#include "base/RefCount.h" typedef RefCount AccessLogEntryPointer; class AccessLogEntry; diff --git a/src/auth/Scheme.h b/src/auth/Scheme.h index 2842bd3e0f..8a677eb5b9 100644 --- a/src/auth/Scheme.h +++ b/src/auth/Scheme.h @@ -34,7 +34,7 @@ #if USE_AUTH #include "Array.h" -#include "RefCount.h" +#include "base/RefCount.h" /** \defgroup AuthSchemeAPI Authentication Scheme API diff --git a/src/auth/User.cc b/src/auth/User.cc index 43266f2c31..d42041109d 100644 --- a/src/auth/User.cc +++ b/src/auth/User.cc @@ -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."); diff --git a/src/auth/User.h b/src/auth/User.h index a5ae2ea9e7..11d2e15078 100644 --- a/src/auth/User.h +++ b/src/auth/User.h @@ -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; diff --git a/src/auth/UserRequest.cc b/src/auth/UserRequest.cc index 01bfd7285e..fa65fcc636 100644 --- a/src/auth/UserRequest.cc +++ b/src/auth/UserRequest.cc @@ -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) { diff --git a/src/auth/basic/UserRequest.h b/src/auth/basic/UserRequest.h index 304e8cf9df..4dafb094f3 100644 --- a/src/auth/basic/UserRequest.h +++ b/src/auth/basic/UserRequest.h @@ -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); diff --git a/src/auth/digest/UserRequest.cc b/src/auth/digest/UserRequest.cc index dfd72462aa..11764a319e 100644 --- a/src/auth/digest/UserRequest.cc +++ b/src/auth/digest/UserRequest.cc @@ -28,7 +28,7 @@ Auth::Digest::UserRequest::UserRequest() : */ Auth::Digest::UserRequest::~UserRequest() { - assert(RefCountCount()==0); + assert(LockCount()==0); safe_free(nonceb64); safe_free(cnonce); diff --git a/src/auth/negotiate/UserRequest.cc b/src/auth/negotiate/UserRequest.cc index c93e70375a..1b0aef6299 100644 --- a/src/auth/negotiate/UserRequest.cc +++ b/src/auth/negotiate/UserRequest.cc @@ -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); diff --git a/src/auth/ntlm/UserRequest.cc b/src/auth/ntlm/UserRequest.cc index 3648d51feb..2d31ff4f3d 100644 --- a/src/auth/ntlm/UserRequest.cc +++ b/src/auth/ntlm/UserRequest.cc @@ -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 index 0000000000..5153fda9f5 --- /dev/null +++ b/src/base/Lock.h @@ -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 */ diff --git a/src/base/Makefile.am b/src/base/Makefile.am index 3ad8e4d2ec..38e4f3b143 100644 --- a/src/base/Makefile.am +++ b/src/base/Makefile.am @@ -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) + diff --git a/include/RefCount.h b/src/base/RefCount.h similarity index 78% rename from include/RefCount.h rename to src/base/RefCount.h index c0f0fe9be6..a9ef060ace 100644 --- a/include/RefCount.h +++ b/src/base/RefCount.h @@ -33,10 +33,19 @@ #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 #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 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 inline std::ostream &operator <<(std::ostream &os, const RefCount &p) { if (p != NULL) - return os << p.getRaw() << '*' << p->RefCountCount(); + return os << p.getRaw() << '*' << p->LockCount(); else return os << "NULL"; } diff --git a/test-suite/refcount.cc b/src/base/testRefCount.cc similarity index 97% rename from test-suite/refcount.cc rename to src/base/testRefCount.cc index 6e90955315..e343b16599 100644 --- a/test-suite/refcount.cc +++ b/src/base/testRefCount.cc @@ -1,4 +1,3 @@ - /* * DEBUG: section -- Refcount allocator * AUTHOR: Robert Collins @@ -32,14 +31,14 @@ */ #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 Pointer; diff --git a/src/clientStream.h b/src/clientStream.h index c5abb04e15..ce9b252c8a 100644 --- a/src/clientStream.h +++ b/src/clientStream.h @@ -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 ClientStreamData; +typedef RefCount ClientStreamData; class clientStreamNode; class ClientHttpRequest; diff --git a/src/client_side.h b/src/client_side.h index 6185817102..2df5c9b19b 100644 --- a/src/client_side.h +++ b/src/client_side.h @@ -34,13 +34,13 @@ #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" diff --git a/src/client_side_reply.h b/src/client_side_reply.h index 155b814d3e..50ece11369 100644 --- a/src/client_side_reply.h +++ b/src/client_side_reply.h @@ -31,10 +31,10 @@ #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" diff --git a/src/comm/Connection.h b/src/comm/Connection.h index 1f15a00463..ef10cba14e 100644 --- a/src/comm/Connection.h +++ b/src/comm/Connection.h @@ -37,12 +37,12 @@ #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" diff --git a/src/comm/forward.h b/src/comm/forward.h index ad333d0900..2d5a5031f0 100644 --- a/src/comm/forward.h +++ b/src/comm/forward.h @@ -2,7 +2,7 @@ #define _SQUID_COMM_FORWARD_H #include "Array.h" -#include "RefCount.h" +#include "base/RefCount.h" namespace Comm { diff --git a/src/esi/Element.h b/src/esi/Element.h index 9146988159..d8bbdc5155 100644 --- a/src/esi/Element.h +++ b/src/esi/Element.h @@ -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, diff --git a/src/esi/Parser.h b/src/esi/Parser.h index 9af51de866..82eaa2676a 100644 --- a/src/esi/Parser.h +++ b/src/esi/Parser.h @@ -40,8 +40,7 @@ public: virtual ~ESIParserClient() {}; }; -/* for RefCountable */ -#include "RefCount.h" +#include "base/RefCount.h" class ESIParser : public RefCountable { diff --git a/src/esi/Segment.h b/src/esi/Segment.h index 04e0ce4617..56ad448fed 100644 --- a/src/esi/Segment.h +++ b/src/esi/Segment.h @@ -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 diff --git a/src/format/Format.h b/src/format/Format.h index 7e9795a982..2415815c08 100644 --- a/src/format/Format.h +++ b/src/format/Format.h @@ -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. diff --git a/src/forward.h b/src/forward.h index da3e74a427..0a754c6ee9 100644 --- a/src/forward.h +++ b/src/forward.h @@ -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 */ diff --git a/src/fs/rock/RockSwapDir.cc b/src/fs/rock/RockSwapDir.cc index e8c23006f3..aa4dd966df 100644 --- a/src/fs/rock/RockSwapDir.cc +++ b/src/fs/rock/RockSwapDir.cc @@ -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); diff --git a/src/fs/ufs/RebuildState.h b/src/fs/ufs/RebuildState.h index 29f69fea2e..552da45d31 100644 --- a/src/fs/ufs/RebuildState.h +++ b/src/fs/ufs/RebuildState.h @@ -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" diff --git a/src/ipc/Request.h b/src/ipc/Request.h index 6e90a63691..ca4aa811b0 100644 --- a/src/ipc/Request.h +++ b/src/ipc/Request.h @@ -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 { diff --git a/src/ipc/Response.h b/src/ipc/Response.h index 6ecb25f433..dfd6fe2171 100644 --- a/src/ipc/Response.h +++ b/src/ipc/Response.h @@ -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 { diff --git a/src/ipc/mem/Pointer.h b/src/ipc/mem/Pointer.h index 4a1d95d859..55cb55b86b 100644 --- a/src/ipc/mem/Pointer.h +++ b/src/ipc/mem/Pointer.h @@ -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 { diff --git a/src/log/Formats.h b/src/log/Formats.h index 0e2dd16eca..b77953005f 100644 --- a/src/log/Formats.h +++ b/src/log/Formats.h @@ -2,7 +2,7 @@ #define _SQUID_LOG_FORMATS_H #include "AccessLogEntry.h" -#include "RefCount.h" +#include "base/RefCount.h" typedef RefCount AccessLogEntryPointer; class AccessLogEntry; diff --git a/src/mgr/QueryParam.h b/src/mgr/QueryParam.h index 6196689401..0770b05f46 100644 --- a/src/mgr/QueryParam.h +++ b/src/mgr/QueryParam.h @@ -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 { diff --git a/src/mgr/forward.h b/src/mgr/forward.h index b26c54a67e..e675166981 100644 --- a/src/mgr/forward.h +++ b/src/mgr/forward.h @@ -6,7 +6,7 @@ #ifndef SQUID_MGR_FORWARD_H #define SQUID_MGR_FORWARD_H -#include "RefCount.h" +#include "base/RefCount.h" namespace Mgr { diff --git a/src/ssl/ErrorDetailManager.h b/src/ssl/ErrorDetailManager.h index 7e69e8db11..a2809c884a 100644 --- a/src/ssl/ErrorDetailManager.h +++ b/src/ssl/ErrorDetailManager.h @@ -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 diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 5818f3502b..fa486c8767 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -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)