ThreadGlobalData.h [plain text]
#ifndef ThreadGlobalData_h
#define ThreadGlobalData_h
#include "StringHash.h"
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/Noncopyable.h>
#if ENABLE(WORKERS)
#include <wtf/ThreadSpecific.h>
#include <wtf/Threading.h>
using WTF::ThreadSpecific;
#endif
namespace WebCore {
class EventNames;
struct ICUConverterWrapper;
struct TECConverterWrapper;
class ThreadTimers;
class ThreadGlobalData : public Noncopyable {
public:
ThreadGlobalData();
~ThreadGlobalData();
EventNames& eventNames() { return *m_eventNames; }
StringImpl* emptyString() { return m_emptyString; }
HashSet<StringImpl*>& atomicStringTable() { return *m_atomicStringTable; }
ThreadTimers& threadTimers() { return *m_threadTimers; }
#if USE(ICU_UNICODE) || USE(GLIB_ICU_UNICODE_HYBRID)
ICUConverterWrapper& cachedConverterICU() { return *m_cachedConverterICU; }
#endif
private:
StringImpl* m_emptyString;
HashSet<StringImpl*>* m_atomicStringTable;
EventNames* m_eventNames;
ThreadTimers* m_threadTimers;
#ifndef NDEBUG
bool m_isMainThread;
#endif
#if USE(ICU_UNICODE) || USE(GLIB_ICU_UNICODE_HYBRID)
ICUConverterWrapper* m_cachedConverterICU;
#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