]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/cbdata.cc
Cleanup: zap CVS Id tags
[thirdparty/squid.git] / src / cbdata.cc
index 8d45e520fcd7a67fae32ce3b4017746fc6a0f9cf..5675a787f94065f6120acf9824d2a097dc3be1bc 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: cbdata.cc,v 1.73 2006/09/03 04:09:36 hno Exp $
+ * $Id$
  *
  * DEBUG: section 45    Callback Data Registry
  * ORIGINAL AUTHOR: Duane Wessels
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
  *  (at your option) any later version.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
  *
  */
 
-/*
+/**
+ \defgroup CBDATAInternal Callback Data Allocator Internals
+ \ingroup CBDATAAPI
+ *
  * These routines manage a set of registered callback data pointers.
- * One of the easiest ways to make Squid coredump is to issue a 
+ * One of the easiest ways to make Squid coredump is to issue a
  * callback to for some data structure which has previously been
  * freed.  With these routines, we register (add) callback data
  * pointers, lock them just before registering the callback function,
@@ -68,7 +71,7 @@ class CBDataCall
 {
 
 public:
-    CBDataCall (char const *callLabel, char const *aFile, int aLine) : label(callLabel), file(aFile), line(aLine){}
+    CBDataCall (char const *callLabel, char const *aFile, int aLine) : label(callLabel), file(aFile), line(aLine) {}
 
     char const *label;
     char const *file;
@@ -77,11 +80,13 @@ public:
 
 #endif
 
+/// \ingroup CBDATAInternal
 #define OFFSET_OF(TYPE, MEMBER) ((size_t) &(((TYPE) *)0)->(MEMBER))
 
+/// \ingroup CBDATAInternal
 class cbdata
 {
-    /* TODO: examine making cbdata templated on this - so we get type
+    /** \todo examine making cbdata templated on this - so we get type
      * safe access to data - RBC 20030902 */
 public:
 #if HASHED_CBDATA
@@ -106,8 +111,7 @@ public:
     cbdata_type type;
 #if CBDATA_DEBUG
 
-    void addHistory(char const *label, char const *file, int line)
-    {
+    void addHistory(char const *label, char const *file, int line) {
         if (calls.size() > 1000)
             return;
 
@@ -146,13 +150,15 @@ cbdata::operator new(size_t size, void *where)
     return where;
 }
 
+/**
+ * Only ever invoked when placement new throws
+ * an exception. Used to prevent an incorrect
+ * free.
+ */
 void
 cbdata::operator delete(void *where, void *where2)
 {
-    /* Only ever invoked when placement new throws
-     * an exception. Used to prevent an incorrect
-     * free.
-     */
+    ; // empty.
 }
 
 long
@@ -163,7 +169,7 @@ cbdata::MakeOffset()
     return (long)dataOffset;
 }
 #else
-MEMPROXY_CLASS_INLINE(cbdata)
+MEMPROXY_CLASS_INLINE(cbdata);
 #endif
 
 static OBJH cbdataDump;
@@ -171,13 +177,14 @@ static OBJH cbdataDump;
 static OBJH cbdataDumpHistory;
 #endif
 
-struct CBDataIndex
-{
+/// \ingroup CBDATAInternal
+struct CBDataIndex {
     MemAllocator *pool;
     FREE *free_func;
 }
-
 *cbdata_index = NULL;
+
+/// \ingroup CBDATAInternal
 int cbdata_types = 0;
 
 #if HASHED_CBDATA
@@ -238,13 +245,13 @@ cbdataInternalInitType(cbdata_type type, const char *name, int size, FREE * free
     size += cbdata::Offset;
 #endif
 
-    cbdata_index[type].pool = MemPools::GetInstance().create(label, size);
+    cbdata_index[type].pool = memPoolCreate(label, size);
 
     cbdata_index[type].free_func = free_func;
 
 #if HASHED_CBDATA
     if (!cbdata_htable)
-       cbdata_htable = hash_create(cbdata_cmp, 1 << 12, cbdata_hash);
+        cbdata_htable = hash_create(cbdata_cmp, 1 << 12, cbdata_hash);
 #endif
 }
 
@@ -262,16 +269,17 @@ cbdataInternalAddType(cbdata_type type, const char *name, int size, FREE * free_
 }
 
 void
-cbdataRegisterWithCacheManager(CacheManager & manager)
+cbdataRegisterWithCacheManager(void)
 {
-    manager.registerAction("cbdata",
-                           "Callback Data Registry Contents",
-                           cbdataDump, 0, 1);
+    CacheManager *manager=CacheManager::GetInstance();
+    manager->registerAction("cbdata",
+                            "Callback Data Registry Contents",
+                            cbdataDump, 0, 1);
 #if CBDATA_DEBUG
 
-    manager.registerAction("cbdatahistory",
-                           "Detailed call history for all current cbdata contents",
-                           cbdataDumpHistory, 0, 1);
+    manager->registerAction("cbdatahistory",
+                            "Detailed call history for all current cbdata contents",
+                            cbdataDumpHistory, 0, 1);
 #endif
 }
 
@@ -310,7 +318,7 @@ cbdataInternalAlloc(cbdata_type type)
     c->calls = Stack<CBDataCall *> ();
     c->addHistory("Alloc", file, line);
     dlinkAdd(c, &c->link, &cbdataEntries);
-    debug(45, 3) ("cbdataAlloc: %p %s:%d\n", p, file, line);
+    debugs(45, 3, "cbdataAlloc: " << p << " " << file << ":" << line);
 #endif
 
     return p;
@@ -331,10 +339,10 @@ cbdataInternalFree(void *p)
 #endif
 #if CBDATA_DEBUG
 
-    debug(45, 3) ("cbdataFree: %p %s:%d\n", p, file, line);
+    debugs(45, 3, "cbdataFree: " << p << " " << file << ":" << line);
 #else
 
-    debug(45, 9) ("cbdataFree: %p\n", p);
+    debugs(45, 9, "cbdataFree: " << p);
 #endif
 
     c->check(__LINE__);
@@ -346,23 +354,22 @@ cbdataInternalFree(void *p)
 #endif
 
     if (c->locks) {
-        debug(45, 9) ("cbdataFree: %p has %d locks, not freeing\n",
-                      p, c->locks);
+        debugs(45, 9, "cbdataFree: " << p << " has " << c->locks << " locks, not freeing");
         return NULL;
     }
 
     cbdataCount--;
-    debug(45, 9) ("cbdataFree: Freeing %p\n", p);
+    debugs(45, 9, "cbdataFree: Freeing " << p);
 #if CBDATA_DEBUG
 
     dlinkDelete(&c->link, &cbdataEntries);
 #endif
 
     /* This is ugly. But: operator delete doesn't get
-     * the type parameter, so we can't use that 
+     * the type parameter, so we can't use that
      * to free the memory.
      * So, we free it ourselves.
-     * Note that this means a non-placement 
+     * Note that this means a non-placement
      * new would be a seriously bad idea.
      * Lastly, if we where a templated class,
      * we could use the normal delete operator
@@ -400,13 +407,13 @@ cbdataInternalLock(const void *p)
 
 #if CBDATA_DEBUG
 
-    debug(45, 3) ("cbdataLock: %p=%d %s:%d\n", p, c ? c->locks + 1 : -1, file, line);
+    debugs(45, 3, "cbdataLock: " << p << "=" << (c ? c->locks + 1 : -1) << " " << file << ":" << line);
 
     c->addHistory("Reference", file, line);
 
 #else
 
-    debug(45, 9) ("cbdataLock: %p=%d\n", p, c ? c->locks + 1 : -1);
+    debugs(45, 9, "cbdataLock: " << p << "=" << (c ? c->locks + 1 : -1));
 
 #endif
 
@@ -437,13 +444,13 @@ cbdataInternalUnlock(const void *p)
 
 #if CBDATA_DEBUG
 
-    debug(45, 3) ("cbdataUnlock: %p=%d %s:%d\n", p, c ? c->locks - 1 : -1, file, line);
+    debugs(45, 3, "cbdataUnlock: " << p << "=" << (c ? c->locks - 1 : -1) << " " << file << ":" << line);
 
     c->addHistory("Dereference", file, line);
 
 #else
 
-    debug(45, 9) ("cbdataUnlock: %p=%d\n", p, c ? c->locks - 1 : -1);
+    debugs(45, 9, "cbdataUnlock: " << p << "=" << (c ? c->locks - 1 : -1));
 
 #endif
 
@@ -460,7 +467,7 @@ cbdataInternalUnlock(const void *p)
 
     cbdataCount--;
 
-    debug(45, 9) ("cbdataUnlock: Freeing %p\n", p);
+    debugs(45, 9, "cbdataUnlock: Freeing " << p);
 
 #if CBDATA_DEBUG
 
@@ -469,10 +476,10 @@ cbdataInternalUnlock(const void *p)
 #endif
 
     /* This is ugly. But: operator delete doesn't get
-     * the type parameter, so we can't use that 
+     * the type parameter, so we can't use that
      * to free the memory.
      * So, we free it ourselves.
-     * Note that this means a non-placement 
+     * Note that this means a non-placement
      * new would be a seriously bad idea.
      * Lastly, if we where a templated class,
      * we could use the normal delete operator
@@ -497,7 +504,7 @@ cbdataReferenceValid(const void *p)
     if (p == NULL)
         return 1;              /* A NULL pointer cannot become invalid */
 
-    debug(45, 9) ("cbdataReferenceValid: %p\n", p);
+    debugs(45, 9, "cbdataReferenceValid: " << p);
 
 #if HASHED_CBDATA
     c = (cbdata *) hash_lookup(cbdata_htable, p);
@@ -544,20 +551,18 @@ void
 cbdata::dump(StoreEntry *sentry) const
 {
 #if HASHED_CBDATA
-    void *p = hash.key;
+    void *p = (void *)hash.key;
 #else
-    void *p = &data;
+    void *p = (void *)&data;
 #endif
     storeAppendPrintf(sentry, "%c%p\t%d\t%d\t%20s:%-5d\n", valid ? ' ' :
                       '!', p, type, locks, file, line);
 }
 
-struct CBDataDumper : public unary_function<cbdata, void>
-{
-    CBDataDumper(StoreEntry *anEntry):where(anEntry){}
+struct CBDataDumper : public unary_function<cbdata, void> {
+    CBDataDumper(StoreEntry *anEntry):where(anEntry) {}
 
-    void operator()(cbdata const &x)
-    {
+    void operator()(cbdata const &x) {
         x.dump(where);
     }
 
@@ -603,24 +608,20 @@ CBDATA_CLASS_INIT(generic_cbdata);
 
 #if CBDATA_DEBUG
 
-struct CBDataCallDumper : public unary_function<CBDataCall, void>
-{
-    CBDataCallDumper (StoreEntry *anEntry):where(anEntry){}
+struct CBDataCallDumper : public unary_function<CBDataCall, void> {
+    CBDataCallDumper (StoreEntry *anEntry):where(anEntry) {}
 
-    void operator()(CBDataCall const &x)
-    {
+    void operator()(CBDataCall const &x) {
         storeAppendPrintf(where, "%s\t%s\t%d\n", x.label, x.file, x.line);
     }
 
     StoreEntry *where;
 };
 
-struct CBDataHistoryDumper : public CBDataDumper
-{
-    CBDataHistoryDumper(StoreEntry *anEntry):CBDataDumper(anEntry),where(anEntry), callDumper(anEntry){}
+struct CBDataHistoryDumper : public CBDataDumper {
+    CBDataHistoryDumper(StoreEntry *anEntry):CBDataDumper(anEntry),where(anEntry), callDumper(anEntry) {}
 
-    void operator()(cbdata const &x)
-    {
+    void operator()(cbdata const &x) {
         CBDataDumper::operator()(x);
         storeAppendPrintf(where, "\n");
         storeAppendPrintf(where, "Action\tFile\tLine\n");