/* DEBUG: section 45 Callback Data Registry */
#include "squid.h"
+#include "base/Lock.h"
#include "cbdata.h"
#include "Generic.h"
#include "mem/Pool.h"
#include "mgr/Registration.h"
#include "Store.h"
-#include <climits>
-
#if USE_CBDATA_DEBUG
#include <algorithm>
#include <vector>
#include <map>
#endif
-static int cbdataCount = 0;
+static uint64_t cbdataCount = 0;
#if USE_CBDATA_DEBUG
dlink_list cbdataEntries;
#endif
* validate them before issuing the callback, and then free them
* when finished.
*/
-class cbdata
+class cbdata : public Lock
{
#if !WITH_VALGRIND
public:
#endif
cbdata() :
valid(0),
- locks(0),
+ type(CBDATA_UNKNOWN),
#if USE_CBDATA_DEBUG
file(NULL),
line(0),
~cbdata();
int valid;
- int32_t locks;
cbdata_type type;
#if USE_CBDATA_DEBUG
c->type = type;
c->valid = 1;
- c->locks = 0;
+ assert(c->LockCount() == 0);
c->cookie = (long) c ^ cbdata::Cookie;
++cbdataCount;
#if USE_CBDATA_DEBUG
c->addHistory("Free", file, line);
#endif
- if (c->locks) {
- debugs(45, 9, p << " has " << c->locks << " locks, not freeing");
+ if (c->LockCount()) {
+ debugs(45, 9, p << " has " << c->LockCount() << " locks, not freeing");
return NULL;
}
#endif
#if USE_CBDATA_DEBUG
- debugs(45, 3, p << "=" << (c ? c->locks + 1 : -1) << " " << file << ":" << line);
+ debugs(45, 3, p << "=" << (c ? c->LockCount() + 1 : -1) << " " << file << ":" << line);
c->addHistory("Reference", file, line);
#else
- debugs(45, 9, p << "=" << (c ? c->locks + 1 : -1));
+ debugs(45, 9, p << "=" << (c ? c->LockCount() + 1 : -1));
#endif
c->check(__LINE__);
- assert(c->locks < INT_MAX);
-
- ++ c->locks;
+ c->lock();
}
void
#endif
#if USE_CBDATA_DEBUG
- debugs(45, 3, p << "=" << (c ? c->locks - 1 : -1) << " " << file << ":" << line);
+ debugs(45, 3, p << "=" << (c ? c->LockCount() - 1 : -1) << " " << file << ":" << line);
c->addHistory("Dereference", file, line);
#else
- debugs(45, 9, p << "=" << (c ? c->locks - 1 : -1));
+ debugs(45, 9, p << "=" << (c ? c->LockCount() - 1 : -1));
#endif
c->check(__LINE__);
assert(c != NULL);
- assert(c->locks > 0);
-
- -- c->locks;
+ c->unlock();
- if (c->locks)
+ if (c->LockCount() > 0)
return;
if (c->valid) {
c->check(__LINE__);
- assert(c->locks > 0);
+ assert(c->LockCount() > 0);
return c->valid;
}
#else
void *p = (void *)&data;
#endif
- storeAppendPrintf(sentry, "%c%p\t%d\t%d\t%20s:%-5d\n", valid ? ' ' :
- '!', p, type, locks, file, line);
+ storeAppendPrintf(sentry, "%c%p\t%d\t%u\t%20s:%-5d\n", valid ? ' ' :
+ '!', p, type, LockCount(), file, line);
}
struct CBDataDumper : public unary_function<cbdata, void> {
static void
cbdataDump(StoreEntry * sentry)
{
- storeAppendPrintf(sentry, "%d cbdata entries\n", cbdataCount);
+ storeAppendPrintf(sentry, "%" PRIu64 " cbdata entries\n", cbdataCount);
#if USE_CBDATA_DEBUG
storeAppendPrintf(sentry, "Pointer\tType\tLocks\tAllocated by\n");
void
cbdataDumpHistory(StoreEntry *sentry)
{
- storeAppendPrintf(sentry, "%d cbdata entries\n", cbdataCount);
+ storeAppendPrintf(sentry, "%" PRIu64 " cbdata entries\n", cbdataCount);
storeAppendPrintf(sentry, "Pointer\tType\tLocks\tAllocated by\n");
CBDataHistoryDumper dumper(sentry);
for_each (cbdataEntries, dumper);