1 /* 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * 25 */ 26 27 #include "config.h" 28 #include "ThreadGlobalData.h" 29 30 #include "EventNames.h" 31 #include "ThreadTimers.h" 32 #include <wtf/UnusedParam.h> 33 #include <wtf/WTFThreadData.h> 34 #include <wtf/text/StringImpl.h> 35 36 #if USE(ICU_UNICODE) 37 #include "TextCodecICU.h" 38 #endif 39 40 #if PLATFORM(MAC) 41 #include "TextCodecMac.h" 42 #endif 43 44 #if ENABLE(WORKERS) 45 #include <wtf/Threading.h> 46 #include <wtf/ThreadSpecific.h> 47 using namespace WTF; 48 #endif 49 50 namespace WebCore { 51 52 #if ENABLE(WORKERS) 53 ThreadSpecific<ThreadGlobalData>* ThreadGlobalData::staticData; 54 #else 55 ThreadGlobalData* ThreadGlobalData::staticData; 56 #endif 57 58 ThreadGlobalData::ThreadGlobalData() 59 : m_eventNames(new EventNames) 60 , m_threadTimers(new ThreadTimers) 61 #ifndef NDEBUG 62 , m_isMainThread(isMainThread()) 63 #endif 64 #if USE(ICU_UNICODE) 65 , m_cachedConverterICU(new ICUConverterWrapper) 66 #endif 67 #if PLATFORM(MAC) 68 , m_cachedConverterTEC(new TECConverterWrapper) 69 #endif 70 { 71 // This constructor will have been called on the main thread before being called on 72 // any other thread, and is only called once per thread - this makes this a convenient 73 // point to call methods that internally perform a one-time initialization that is not 74 // threadsafe. 75 wtfThreadData(); 76 StringImpl::empty(); 77 } 78 79 ThreadGlobalData::~ThreadGlobalData() 80 { 81 destroy(); 82 } 83 84 void ThreadGlobalData::destroy() 85 { 86 #if PLATFORM(MAC) 87 delete m_cachedConverterTEC; 88 m_cachedConverterTEC = 0; 89 #endif 90 91 #if USE(ICU_UNICODE) 92 delete m_cachedConverterICU; 93 m_cachedConverterICU = 0; 94 #endif 95 96 delete m_eventNames; 97 m_eventNames = 0; 98 delete m_threadTimers; 99 m_threadTimers = 0; 100 } 101 102 } // namespace WebCore 103