InspectorCounters.h [plain text]
#ifndef InspectorCounters_h
#define InspectorCounters_h
#include <wtf/FastAllocBase.h>
#if !ASSERT_DISABLED
#include <wtf/MainThread.h>
#if PLATFORM(IOS)
#include "WebCoreThread.h"
#endif
#endif
namespace WebCore {
class InspectorCounters {
public:
enum CounterType {
DocumentCounter,
NodeCounter,
JSEventListenerCounter,
CounterTypeLength
};
static inline void incrementCounter(CounterType type)
{
#if ENABLE(INSPECTOR)
#if !PLATFORM(IOS)
ASSERT(isMainThread());
#else
ASSERT((isMainThread() || pthread_main_np()) && WebThreadIsLockedOrDisabled());
#endif
++s_counters[type];
#else
UNUSED_PARAM(type);
#endif
}
static inline void decrementCounter(CounterType type)
{
#if ENABLE(INSPECTOR)
#if !PLATFORM(IOS)
ASSERT(isMainThread());
#else
ASSERT((isMainThread() || pthread_main_np()) && WebThreadIsLockedOrDisabled());
#endif
--s_counters[type];
#else
UNUSED_PARAM(type);
#endif
}
#if ENABLE(INSPECTOR)
static int counterValue(CounterType);
#endif
private:
InspectorCounters();
#if ENABLE(INSPECTOR)
static int s_counters[CounterTypeLength];
#endif
};
#if ENABLE(INSPECTOR)
class ThreadLocalInspectorCounters {
WTF_MAKE_FAST_ALLOCATED;
public:
enum CounterType {
JSEventListenerCounter,
CounterTypeLength
};
ThreadLocalInspectorCounters();
inline void incrementCounter(CounterType type)
{
++m_counters[type];
}
inline void decrementCounter(CounterType type)
{
--m_counters[type];
}
int counterValue(CounterType);
static ThreadLocalInspectorCounters& current();
private:
int m_counters[CounterTypeLength];
};
#endif
}
#endif // !defined(InspectorCounters_h)