ThreadGlobalData.cpp [plain text]
#include "config.h"
#include "ThreadGlobalData.h"
#include "DOMImplementation.h"
#include "EventNames.h"
#include "InspectorCounters.h"
#include "ThreadTimers.h"
#include <wtf/MainThread.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(adoptPtr(new EventNames))
, m_threadTimers(adoptPtr(new ThreadTimers))
, m_xmlTypeRegExp(adoptPtr(new XMLMIMETypeRegExp))
#ifndef NDEBUG
, m_isMainThread(pthread_main_np() || isMainThread())
#endif
#if USE(ICU_UNICODE)
, m_cachedConverterICU(adoptPtr(new ICUConverterWrapper))
#endif
#if ENABLE(INSPECTOR)
, m_inspectorCounters(adoptPtr(new ThreadLocalInspectorCounters()))
#endif
{
wtfThreadData();
StringImpl::empty();
}
ThreadGlobalData::~ThreadGlobalData()
{
}
void ThreadGlobalData::destroy()
{
#if USE(ICU_UNICODE)
m_cachedConverterICU.clear();
#endif
#if ENABLE(INSPECTOR)
m_inspectorCounters.clear();
#endif
m_eventNames.clear();
m_threadTimers.clear();
m_xmlTypeRegExp.clear();
}
#if ENABLE(WORKERS)
void ThreadGlobalData::setWebCoreThreadData()
{
ASSERT(isWebThread());
ASSERT(&threadGlobalData() != ThreadGlobalData::sharedMainThreadStaticData);
ThreadGlobalData::staticData->replace(ThreadGlobalData::sharedMainThreadStaticData);
ASSERT(&threadGlobalData() == ThreadGlobalData::sharedMainThreadStaticData);
}
#endif
}