ThreadGlobalData.h [plain text]
#ifndef ThreadGlobalData_h
#define ThreadGlobalData_h
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/Noncopyable.h>
#include <wtf/OwnPtr.h>
#include <wtf/text/StringHash.h>
#if ENABLE(WORKERS)
#include <wtf/ThreadSpecific.h>
#include <wtf/Threading.h>
using WTF::ThreadSpecific;
#endif
namespace WebCore {
class EventNames;
class ThreadLocalInspectorCounters;
class ThreadTimers;
class XMLMIMETypeRegExp;
struct ICUConverterWrapper;
struct TECConverterWrapper;
class ThreadGlobalData {
WTF_MAKE_NONCOPYABLE(ThreadGlobalData);
public:
ThreadGlobalData();
~ThreadGlobalData();
void destroy();
EventNames& eventNames() { return *m_eventNames; }
ThreadTimers& threadTimers() { return *m_threadTimers; }
XMLMIMETypeRegExp& xmlTypeRegExp() { return *m_xmlTypeRegExp; }
#if USE(ICU_UNICODE)
ICUConverterWrapper& cachedConverterICU() { return *m_cachedConverterICU; }
#endif
#if PLATFORM(MAC)
TECConverterWrapper& cachedConverterTEC() { return *m_cachedConverterTEC; }
#endif
#if ENABLE(INSPECTOR)
ThreadLocalInspectorCounters& inspectorCounters() { return *m_inspectorCounters; }
#endif
private:
OwnPtr<EventNames> m_eventNames;
OwnPtr<ThreadTimers> m_threadTimers;
OwnPtr<XMLMIMETypeRegExp> m_xmlTypeRegExp;
#ifndef NDEBUG
bool m_isMainThread;
#endif
#if USE(ICU_UNICODE)
OwnPtr<ICUConverterWrapper> m_cachedConverterICU;
#endif
#if PLATFORM(MAC)
OwnPtr<TECConverterWrapper> m_cachedConverterTEC;
#endif
#if ENABLE(INSPECTOR)
OwnPtr<ThreadLocalInspectorCounters> m_inspectorCounters;
#endif
#if ENABLE(WORKERS)
static ThreadSpecific<ThreadGlobalData>* staticData;
#else
static ThreadGlobalData* staticData;
#endif
friend ThreadGlobalData& threadGlobalData();
};
inline ThreadGlobalData& threadGlobalData()
{
#if ENABLE(WORKERS)
if (!ThreadGlobalData::staticData)
ThreadGlobalData::staticData = new ThreadSpecific<ThreadGlobalData>;
return **ThreadGlobalData::staticData;
#else
if (!ThreadGlobalData::staticData) {
ThreadGlobalData::staticData = static_cast<ThreadGlobalData*>(fastMalloc(sizeof(ThreadGlobalData)));
new (ThreadGlobalData::staticData) ThreadGlobalData;
}
return *ThreadGlobalData::staticData;
#endif
}
}
#endif // ThreadGlobalData_h