ThreadGlobalData.cpp [plain text]
#include "config.h"
#include "ThreadGlobalData.h"
#include "DOMImplementation.h"
#include "EventNames.h"
#include "ThreadTimers.h"
#include <wtf/UnusedParam.h>
#include <wtf/WTFThreadData.h>
#include <wtf/text/StringImpl.h>
#if USE(ICU_UNICODE)
#include "TextCodecICU.h"
#endif
#if PLATFORM(MAC)
#include "TextCodecMac.h"
#endif
#if ENABLE(WORKERS)
#include <wtf/Threading.h>
#include <wtf/ThreadSpecific.h>
using namespace WTF;
#endif
namespace WebCore {
#if ENABLE(WORKERS)
ThreadSpecific<ThreadGlobalData>* ThreadGlobalData::staticData;
ThreadGlobalData* ThreadGlobalData::sharedMainThreadStaticData;
#else
ThreadGlobalData* ThreadGlobalData::staticData;
#endif
ThreadGlobalData::ThreadGlobalData()
: m_eventNames(new EventNames)
, m_threadTimers(new ThreadTimers)
, m_xmlTypeRegExp(new XMLMIMETypeRegExp)
#ifndef NDEBUG
, m_isMainThread(pthread_main_np() || isMainThread())
#endif
#if USE(ICU_UNICODE)
, m_cachedConverterICU(new ICUConverterWrapper)
#endif
{
wtfThreadData();
StringImpl::empty();
}
ThreadGlobalData::~ThreadGlobalData()
{
destroy();
}
void ThreadGlobalData::destroy()
{
#if USE(ICU_UNICODE)
delete m_cachedConverterICU;
m_cachedConverterICU = 0;
#endif
delete m_eventNames;
m_eventNames = 0;
delete m_threadTimers;
m_threadTimers = 0;
delete m_xmlTypeRegExp;
m_xmlTypeRegExp = 0;
}
#if ENABLE(WORKERS)
void ThreadGlobalData::setWebCoreThreadData()
{
ASSERT(isWebThread());
ASSERT(&threadGlobalData() != ThreadGlobalData::sharedMainThreadStaticData);
ThreadGlobalData::staticData->replace(ThreadGlobalData::sharedMainThreadStaticData);
ASSERT(&threadGlobalData() == ThreadGlobalData::sharedMainThreadStaticData);
}
#endif
}