Commit 94afe7f4 authored by Gyuyoung Kim's avatar Gyuyoung Kim Committed by Commit Bot

OnionSoup: Merge platform/wtf/wtf_thread_data to platform/wtf/threading

As a step to acheive OnionSoup's goal, this CL merges WTFThreadData into
Threading. Major changes are as below,

 - Rename WTFThreadData class to Threading class.
 - Rename WtfThreadData() function to WtfThreading() function.
 - Remove wtf_thread_data.h/cc files.
 - Remove empty namespace in std_lib_extras.h

Bug: 950131
Change-Id: Ib120a3dc61fcb4559740db85cf4075e828bec1f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1558836Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Gyuyoung Kim <gyuyoung@igalia.com>
Cr-Commit-Position: refs/heads/master@{#649020}
parent 6d51c086
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "third_party/blink/renderer/platform/bindings/script_forbidden_scope.h" #include "third_party/blink/renderer/platform/bindings/script_forbidden_scope.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h" #include "third_party/blink/renderer/platform/wtf/assertions.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/thread_specific.h" #include "third_party/blink/renderer/platform/wtf/thread_specific.h"
namespace blink { namespace blink {
......
...@@ -219,8 +219,6 @@ jumbo_component("wtf") { ...@@ -219,8 +219,6 @@ jumbo_component("wtf") {
"wtf.h", "wtf.h",
"wtf_export.h", "wtf_export.h",
"wtf_size_t.h", "wtf_size_t.h",
"wtf_thread_data.cc",
"wtf_thread_data.h",
] ]
configs += [ configs += [
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h" #include "third_party/blink/renderer/platform/wtf/assertions.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/thread_specific.h" #include "third_party/blink/renderer/platform/wtf/thread_specific.h"
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "third_party/blink/renderer/platform/wtf/assertions.h" #include "third_party/blink/renderer/platform/wtf/assertions.h"
#include "third_party/blink/renderer/platform/wtf/threading.h" #include "third_party/blink/renderer/platform/wtf/threading.h"
#include "third_party/blink/renderer/platform/wtf/wtf_thread_data.h"
#if defined(OS_WIN) #if defined(OS_WIN)
#include <stddef.h> #include <stddef.h>
...@@ -90,7 +89,7 @@ size_t GetUnderestimatedStackSize() { ...@@ -90,7 +89,7 @@ size_t GetUnderestimatedStackSize() {
} }
return pthread_get_stacksize_np(pthread_self()); return pthread_get_stacksize_np(pthread_self());
#elif defined(OS_WIN) && defined(COMPILER_MSVC) #elif defined(OS_WIN) && defined(COMPILER_MSVC)
return WTFThreadData::ThreadStackSize(); return Threading::ThreadStackSize();
#else #else
#error "Stack frame size estimation not supported on this platform." #error "Stack frame size estimation not supported on this platform."
return 0; return 0;
......
...@@ -66,10 +66,6 @@ ...@@ -66,10 +66,6 @@
#define DEFINE_THREAD_SAFE_STATIC_LOCAL(Type, Name, Arguments) \ #define DEFINE_THREAD_SAFE_STATIC_LOCAL(Type, Name, Arguments) \
DEFINE_STATIC_LOCAL_IMPL(Type, Name, Arguments, true) DEFINE_STATIC_LOCAL_IMPL(Type, Name, Arguments, true)
namespace blink {
} // namespace blink
namespace WTF { namespace WTF {
template <typename Type> template <typename Type>
......
...@@ -10,13 +10,13 @@ ...@@ -10,13 +10,13 @@
#include "third_party/blink/renderer/platform/wtf/hash_set.h" #include "third_party/blink/renderer/platform/wtf/hash_set.h"
#include "third_party/blink/renderer/platform/wtf/text/string_hash.h" #include "third_party/blink/renderer/platform/wtf/text/string_hash.h"
#include "third_party/blink/renderer/platform/wtf/text/string_impl.h" #include "third_party/blink/renderer/platform/wtf/text/string_impl.h"
#include "third_party/blink/renderer/platform/wtf/threading.h"
#include "third_party/blink/renderer/platform/wtf/wtf_export.h" #include "third_party/blink/renderer/platform/wtf/wtf_export.h"
#include "third_party/blink/renderer/platform/wtf/wtf_thread_data.h"
namespace WTF { namespace WTF {
// The underlying storage that keeps the map of unique AtomicStrings. This is // The underlying storage that keeps the map of unique AtomicStrings. This is
// not thread safe and each WTFThreadData has one. // not thread safe and each Threading has one.
class WTF_EXPORT AtomicStringTable final { class WTF_EXPORT AtomicStringTable final {
USING_FAST_MALLOC(AtomicStringTable); USING_FAST_MALLOC(AtomicStringTable);
...@@ -26,7 +26,7 @@ class WTF_EXPORT AtomicStringTable final { ...@@ -26,7 +26,7 @@ class WTF_EXPORT AtomicStringTable final {
// Gets the shared table for the current thread. // Gets the shared table for the current thread.
static AtomicStringTable& Instance() { static AtomicStringTable& Instance() {
return WtfThreadData().GetAtomicStringTable(); return WtfThreading().GetAtomicStringTable();
} }
// Used by system initialization to preallocate enough storage for all of // Used by system initialization to preallocate enough storage for all of
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
#include "third_party/blink/renderer/platform/wtf/text/cstring.h" #include "third_party/blink/renderer/platform/wtf/text/cstring.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h" #include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/blink/renderer/platform/wtf/threading.h" #include "third_party/blink/renderer/platform/wtf/threading.h"
#include "third_party/blink/renderer/platform/wtf/wtf_thread_data.h"
namespace WTF { namespace WTF {
...@@ -50,7 +49,7 @@ ICUConverterWrapper::~ICUConverterWrapper() { ...@@ -50,7 +49,7 @@ ICUConverterWrapper::~ICUConverterWrapper() {
} }
static UConverter*& CachedConverterICU() { static UConverter*& CachedConverterICU() {
return WtfThreadData().CachedConverterICU().converter; return WtfThreading().CachedConverterICU().converter;
} }
std::unique_ptr<TextCodec> TextCodecICU::Create(const TextEncoding& encoding, std::unique_ptr<TextCodec> TextCodecICU::Create(const TextEncoding& encoding,
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
#include "third_party/blink/renderer/platform/wtf/allocator/partition_allocator.h" #include "third_party/blink/renderer/platform/wtf/allocator/partition_allocator.h"
#include "third_party/blink/renderer/platform/wtf/allocator/partitions.h" #include "third_party/blink/renderer/platform/wtf/allocator/partitions.h"
#include "third_party/blink/renderer/platform/wtf/stack_util.h" #include "third_party/blink/renderer/platform/wtf/stack_util.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/wtf.h" #include "third_party/blink/renderer/platform/wtf/wtf.h"
#include "third_party/blink/renderer/platform/wtf/wtf_export.h" #include "third_party/blink/renderer/platform/wtf/wtf_export.h"
...@@ -86,7 +85,7 @@ inline void ThreadSpecific<T>::Destroy(void* ptr) { ...@@ -86,7 +85,7 @@ inline void ThreadSpecific<T>::Destroy(void* ptr) {
// Never call destructors on the main thread. This is fine because Blink no // Never call destructors on the main thread. This is fine because Blink no
// longer has a graceful shutdown sequence. Be careful to call this function // longer has a graceful shutdown sequence. Be careful to call this function
// (which can be re-entrant) while the pointer is still set, to avoid lazily // (which can be re-entrant) while the pointer is still set, to avoid lazily
// allocating WTFThreadData after it is destroyed. // allocating Threading after it is destroyed.
if (IsMainThread()) if (IsMainThread())
return; return;
......
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
#include "third_party/blink/renderer/platform/wtf/threading.h" #include "third_party/blink/renderer/platform/wtf/threading.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "third_party/blink/renderer/platform/wtf/stack_util.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string_table.h"
#include "third_party/blink/renderer/platform/wtf/text/text_codec_icu.h"
namespace WTF { namespace WTF {
...@@ -29,4 +32,33 @@ void WillCreateThread() { ...@@ -29,4 +32,33 @@ void WillCreateThread() {
} }
#endif #endif
ThreadSpecific<Threading>* Threading::static_data_;
Threading::Threading()
: atomic_string_table_(new AtomicStringTable),
cached_converter_icu_(new ICUConverterWrapper),
thread_id_(CurrentThread()) {}
Threading::~Threading() = default;
void Threading::Initialize() {
DCHECK(!Threading::static_data_);
Threading::static_data_ = new ThreadSpecific<Threading>;
WtfThreading();
}
#if defined(OS_WIN) && defined(COMPILER_MSVC)
size_t Threading::ThreadStackSize() {
// Needed to bootstrap Threading on Windows, because this value is needed
// before the main thread data is fully initialized.
if (!Threading::static_data_->IsSet())
return internal::ThreadStackSize();
Threading& data = WtfThreading();
if (!data.thread_stack_size_)
data.thread_stack_size_ = internal::ThreadStackSize();
return data.thread_stack_size_;
}
#endif
} // namespace WTF } // namespace WTF
...@@ -31,10 +31,13 @@ ...@@ -31,10 +31,13 @@
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_THREADING_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_THREADING_H_
#include <stdint.h> #include <stdint.h>
#include <memory>
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h"
#include "base/threading/platform_thread.h" #include "base/threading/platform_thread.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "third_party/blink/renderer/platform/wtf/thread_specific.h"
#include "third_party/blink/renderer/platform/wtf/type_traits.h" #include "third_party/blink/renderer/platform/wtf/type_traits.h"
#include "third_party/blink/renderer/platform/wtf/wtf_export.h" #include "third_party/blink/renderer/platform/wtf/wtf_export.h"
...@@ -47,8 +50,54 @@ WTF_EXPORT bool IsBeforeThreadCreated(); ...@@ -47,8 +50,54 @@ WTF_EXPORT bool IsBeforeThreadCreated();
WTF_EXPORT void WillCreateThread(); WTF_EXPORT void WillCreateThread();
#endif #endif
class AtomicStringTable;
struct ICUConverterWrapper;
class WTF_EXPORT Threading {
DISALLOW_NEW();
public:
Threading();
~Threading();
AtomicStringTable& GetAtomicStringTable() { return *atomic_string_table_; }
ICUConverterWrapper& CachedConverterICU() { return *cached_converter_icu_; }
base::PlatformThreadId ThreadId() const { return thread_id_; }
// Must be called on the main thread before any callers to wtfThreadData().
static void Initialize();
#if defined(OS_WIN) && defined(COMPILER_MSVC)
static size_t ThreadStackSize();
#endif
private:
std::unique_ptr<AtomicStringTable> atomic_string_table_;
std::unique_ptr<ICUConverterWrapper> cached_converter_icu_;
base::PlatformThreadId thread_id_;
#if defined(OS_WIN) && defined(COMPILER_MSVC)
size_t thread_stack_size_ = 0u;
#endif
static ThreadSpecific<Threading>* static_data_;
friend Threading& WtfThreading();
DISALLOW_COPY_AND_ASSIGN(Threading);
};
inline Threading& WtfThreading() {
DCHECK(Threading::static_data_);
return **Threading::static_data_;
}
} // namespace WTF } // namespace WTF
using WTF::CurrentThread; using WTF::CurrentThread;
using WTF::Threading;
using WTF::WtfThreading;
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_THREADING_H_ #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_THREADING_H_
...@@ -44,9 +44,9 @@ ...@@ -44,9 +44,9 @@
#include "third_party/blink/renderer/platform/wtf/hash_map.h" #include "third_party/blink/renderer/platform/wtf/hash_map.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h" #include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/thread_specific.h" #include "third_party/blink/renderer/platform/wtf/thread_specific.h"
#include "third_party/blink/renderer/platform/wtf/threading.h"
#include "third_party/blink/renderer/platform/wtf/threading_primitives.h" #include "third_party/blink/renderer/platform/wtf/threading_primitives.h"
#include "third_party/blink/renderer/platform/wtf/time.h" #include "third_party/blink/renderer/platform/wtf/time.h"
#include "third_party/blink/renderer/platform/wtf/wtf_thread_data.h"
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
#include <objc/objc-auto.h> #include <objc/objc-auto.h>
......
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
#include "third_party/blink/renderer/platform/wtf/thread_specific.h" #include "third_party/blink/renderer/platform/wtf/thread_specific.h"
#include "third_party/blink/renderer/platform/wtf/threading.h" #include "third_party/blink/renderer/platform/wtf/threading.h"
#include "third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_contents.h" #include "third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_contents.h"
#include "third_party/blink/renderer/platform/wtf/wtf_thread_data.h"
namespace WTF { namespace WTF {
...@@ -69,7 +68,7 @@ void Initialize(void (*call_on_main_thread_function)(MainThreadFunction, ...@@ -69,7 +68,7 @@ void Initialize(void (*call_on_main_thread_function)(MainThreadFunction,
g_initialized = true; g_initialized = true;
g_main_thread_identifier = CurrentThread(); g_main_thread_identifier = CurrentThread();
WTFThreadData::Initialize(); Threading::Initialize();
// Force initialization of static DoubleToStringConverter converter variable // Force initialization of static DoubleToStringConverter converter variable
// inside EcmaScriptConverter function while we are in single thread mode. // inside EcmaScriptConverter function while we are in single thread mode.
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_WTF_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_WTF_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_WTF_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_WTF_H_
#include "third_party/blink/renderer/platform/wtf/threading.h" #include "base/threading/platform_thread.h"
#include "third_party/blink/renderer/platform/wtf/wtf_export.h" #include "third_party/blink/renderer/platform/wtf/wtf_export.h"
namespace WTF { namespace WTF {
......
/*
* Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "third_party/blink/renderer/platform/wtf/wtf_thread_data.h"
#include "third_party/blink/renderer/platform/wtf/stack_util.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string_table.h"
#include "third_party/blink/renderer/platform/wtf/text/text_codec_icu.h"
namespace WTF {
ThreadSpecific<WTFThreadData>* WTFThreadData::static_data_;
WTFThreadData::WTFThreadData()
: atomic_string_table_(new AtomicStringTable),
cached_converter_icu_(new ICUConverterWrapper),
thread_id_(WTF::CurrentThread()) {}
WTFThreadData::~WTFThreadData() = default;
void WTFThreadData::Initialize() {
DCHECK(!WTFThreadData::static_data_);
WTFThreadData::static_data_ = new ThreadSpecific<WTFThreadData>;
WtfThreadData();
}
#if defined(OS_WIN) && defined(COMPILER_MSVC)
size_t WTFThreadData::ThreadStackSize() {
// Needed to bootstrap WTFThreadData on Windows, because this value is needed
// before the main thread data is fully initialized.
if (!WTFThreadData::static_data_->IsSet())
return internal::ThreadStackSize();
WTFThreadData& data = WtfThreadData();
if (!data.thread_stack_size_)
data.thread_stack_size_ = internal::ThreadStackSize();
return data.thread_stack_size_;
}
#endif
} // namespace WTF
/*
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_WTF_THREAD_DATA_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_WTF_THREAD_DATA_H_
#include <memory>
#include "base/macros.h"
#include "build/build_config.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
#include "third_party/blink/renderer/platform/wtf/hash_set.h"
#include "third_party/blink/renderer/platform/wtf/text/string_hash.h"
#include "third_party/blink/renderer/platform/wtf/thread_specific.h"
#include "third_party/blink/renderer/platform/wtf/threading.h"
#include "third_party/blink/renderer/platform/wtf/wtf_export.h"
namespace WTF {
class AtomicStringTable;
struct ICUConverterWrapper;
class WTF_EXPORT WTFThreadData {
DISALLOW_NEW();
public:
WTFThreadData();
~WTFThreadData();
AtomicStringTable& GetAtomicStringTable() { return *atomic_string_table_; }
ICUConverterWrapper& CachedConverterICU() { return *cached_converter_icu_; }
base::PlatformThreadId ThreadId() const { return thread_id_; }
// Must be called on the main thread before any callers to wtfThreadData().
static void Initialize();
#if defined(OS_WIN) && defined(COMPILER_MSVC)
static size_t ThreadStackSize();
#endif
private:
std::unique_ptr<AtomicStringTable> atomic_string_table_;
std::unique_ptr<ICUConverterWrapper> cached_converter_icu_;
base::PlatformThreadId thread_id_;
#if defined(OS_WIN) && defined(COMPILER_MSVC)
size_t thread_stack_size_ = 0u;
#endif
static ThreadSpecific<WTFThreadData>* static_data_;
friend WTFThreadData& WtfThreadData();
DISALLOW_COPY_AND_ASSIGN(WTFThreadData);
};
inline WTFThreadData& WtfThreadData() {
DCHECK(WTFThreadData::static_data_);
return **WTFThreadData::static_data_;
}
} // namespace WTF
using WTF::WTFThreadData;
using WTF::WtfThreadData;
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_WTF_THREAD_DATA_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment