ThreadGlobalData.cpp [plain text]
#include "config.h"
#include "ThreadGlobalData.h"
#include "CachedResourceRequestInitiators.h"
#include "EventNames.h"
#include "TextCodecICU.h"
#include "ThreadTimers.h"
#include <wtf/MainThread.h>
#include <wtf/ThreadSpecific.h>
#include <wtf/Threading.h>
#include <wtf/WTFThreadData.h>
#include <wtf/text/StringImpl.h>
#if PLATFORM(MAC)
#include "TextCodeCMac.h"
#endif
#if ENABLE(WEB_REPLAY)
#include "ReplayInputTypes.h"
#endif
namespace WebCore {
ThreadSpecific<ThreadGlobalData>* ThreadGlobalData::staticData;
#if USE(WEB_THREAD)
ThreadGlobalData* ThreadGlobalData::sharedMainThreadStaticData;
#endif
ThreadGlobalData::ThreadGlobalData()
: m_cachedResourceRequestInitiators(adoptPtr(new CachedResourceRequestInitiators))
, m_eventNames(adoptPtr(new EventNames))
, m_threadTimers(adoptPtr(new ThreadTimers))
#if ENABLE(WEB_REPLAY)
, m_inputTypes(std::make_unique<ReplayInputTypes>())
#endif
#ifndef NDEBUG
, m_isMainThread(isMainThread())
#endif
, m_cachedConverterICU(adoptPtr(new ICUConverterWrapper))
#if PLATFORM(MAC)
, m_cachedConverterTEC(adoptPtr(new TECConverterWrapper))
#endif
{
wtfThreadData();
StringImpl::empty();
}
ThreadGlobalData::~ThreadGlobalData()
{
}
void ThreadGlobalData::destroy()
{
#if PLATFORM(MAC)
m_cachedConverterTEC.clear();
#endif
m_cachedConverterICU.clear();
#if ENABLE(WEB_REPLAY)
m_inputTypes = nullptr;
#endif
m_eventNames.clear();
m_threadTimers.clear();
}
#if USE(WEB_THREAD)
void ThreadGlobalData::setWebCoreThreadData()
{
ASSERT(isWebThread());
ASSERT(&threadGlobalData() != ThreadGlobalData::sharedMainThreadStaticData);
ThreadGlobalData::staticData->replace(ThreadGlobalData::sharedMainThreadStaticData);
ASSERT(&threadGlobalData() == ThreadGlobalData::sharedMainThreadStaticData);
}
#endif
ThreadGlobalData& threadGlobalData()
{
#if USE(WEB_THREAD)
if (UNLIKELY(!ThreadGlobalData::staticData)) {
ThreadGlobalData::staticData = new ThreadSpecific<ThreadGlobalData>;
if (pthread_main_np())
ThreadGlobalData::sharedMainThreadStaticData = *ThreadGlobalData::staticData;
}
return **ThreadGlobalData::staticData;
#else
if (!ThreadGlobalData::staticData)
ThreadGlobalData::staticData = new ThreadSpecific<ThreadGlobalData>;
return **ThreadGlobalData::staticData;
#endif
}
}