ThreadGlobalData.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #include "config.h"
  27. #include "ThreadGlobalData.h"
  28. #include "CachedResourceRequestInitiators.h"
  29. #include "EventNames.h"
  30. #include "InspectorCounters.h"
  31. #include "ThreadTimers.h"
  32. #include <wtf/MainThread.h>
  33. #include <wtf/WTFThreadData.h>
  34. #include <wtf/text/StringImpl.h>
  35. #if USE(ICU_UNICODE)
  36. #include "TextCodecICU.h"
  37. #endif
  38. #if PLATFORM(MAC)
  39. #include "TextCodecMac.h"
  40. #endif
  41. #if ENABLE(WORKERS)
  42. #include <wtf/Threading.h>
  43. #include <wtf/ThreadSpecific.h>
  44. using namespace WTF;
  45. #endif
  46. namespace WebCore {
  47. #if ENABLE(WORKERS)
  48. ThreadSpecific<ThreadGlobalData>* ThreadGlobalData::staticData;
  49. #else
  50. ThreadGlobalData* ThreadGlobalData::staticData;
  51. #endif
  52. ThreadGlobalData::ThreadGlobalData()
  53. : m_cachedResourceRequestInitiators(adoptPtr(new CachedResourceRequestInitiators))
  54. , m_eventNames(adoptPtr(new EventNames))
  55. , m_threadTimers(adoptPtr(new ThreadTimers))
  56. #ifndef NDEBUG
  57. , m_isMainThread(isMainThread())
  58. #endif
  59. #if USE(ICU_UNICODE)
  60. , m_cachedConverterICU(adoptPtr(new ICUConverterWrapper))
  61. #endif
  62. #if PLATFORM(MAC)
  63. , m_cachedConverterTEC(adoptPtr(new TECConverterWrapper))
  64. #endif
  65. #if ENABLE(INSPECTOR)
  66. , m_inspectorCounters(adoptPtr(new ThreadLocalInspectorCounters()))
  67. #endif
  68. {
  69. // This constructor will have been called on the main thread before being called on
  70. // any other thread, and is only called once per thread - this makes this a convenient
  71. // point to call methods that internally perform a one-time initialization that is not
  72. // threadsafe.
  73. wtfThreadData();
  74. StringImpl::empty();
  75. }
  76. ThreadGlobalData::~ThreadGlobalData()
  77. {
  78. }
  79. void ThreadGlobalData::destroy()
  80. {
  81. #if PLATFORM(MAC)
  82. m_cachedConverterTEC.clear();
  83. #endif
  84. #if USE(ICU_UNICODE)
  85. m_cachedConverterICU.clear();
  86. #endif
  87. #if ENABLE(INSPECTOR)
  88. m_inspectorCounters.clear();
  89. #endif
  90. m_eventNames.clear();
  91. m_threadTimers.clear();
  92. }
  93. } // namespace WebCore