1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_THREADING_TRAITS_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_THREADING_TRAITS_H_
#include "third_party/blink/renderer/platform/wtf/allocator.h"
#include "third_party/blink/renderer/platform/wtf/deque.h"
#include "third_party/blink/renderer/platform/wtf/hash_counted_set.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/hash_table.h"
#include "third_party/blink/renderer/platform/wtf/type_traits.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink {
template <typename T>
class SameThreadCheckedMember;
template <typename T>
class TraceWrapperMember;
// ThreadAffinity indicates which threads objects can be used on. We
// distinguish between objects that can be used on the main thread
// only and objects that can be used on any thread.
//
// For objects that can only be used on the main thread, we avoid going
// through thread-local storage to get to the thread state. This is
// important for performance.
enum ThreadAffinity {
kAnyThread,
kMainThreadOnly,
};
// TODO(haraken): These forward declarations violate dependency rules.
// Remove them.
class Node;
class NodeList;
class NodeRareDataBase;
template <
typename T,
bool mainThreadOnly =
WTF::IsSubclass<typename std::remove_const<T>::type, Node>::value ||
WTF::IsSubclass<typename std::remove_const<T>::type, NodeList>::value ||
WTF::IsSubclass<typename std::remove_const<T>::type,
NodeRareDataBase>::value>
struct DefaultThreadingTrait;
template <typename T>
struct DefaultThreadingTrait<T, false> {
STATIC_ONLY(DefaultThreadingTrait);
static const ThreadAffinity kAffinity = kAnyThread;
};
template <typename T>
struct DefaultThreadingTrait<T, true> {
STATIC_ONLY(DefaultThreadingTrait);
static const ThreadAffinity kAffinity = kMainThreadOnly;
};
class HeapAllocator;
template <typename Table>
class HeapHashTableBacking;
template <typename T, typename Traits>
class HeapVectorBacking;
template <typename T>
class Member;
template <typename T>
class WeakMember;
template <typename T>
struct ThreadingTrait {
STATIC_ONLY(ThreadingTrait);
static const ThreadAffinity kAffinity = DefaultThreadingTrait<T>::kAffinity;
};
template <typename U>
class ThreadingTrait<const U> : public ThreadingTrait<U> {};
template <typename T>
struct ThreadingTrait<Member<T>> {
STATIC_ONLY(ThreadingTrait);
static const ThreadAffinity kAffinity = ThreadingTrait<T>::kAffinity;
};
template <typename T>
struct ThreadingTrait<SameThreadCheckedMember<T>> {
STATIC_ONLY(ThreadingTrait);
static const ThreadAffinity kAffinity = ThreadingTrait<T>::Affinity;
};
template <typename T>
struct ThreadingTrait<TraceWrapperMember<T>> {
STATIC_ONLY(ThreadingTrait);
static const ThreadAffinity kAffinity = ThreadingTrait<T>::kAffinity;
};
template <typename T>
struct ThreadingTrait<WeakMember<T>> {
STATIC_ONLY(ThreadingTrait);
static const ThreadAffinity kAffinity = ThreadingTrait<T>::kAffinity;
};
template <typename Key, typename Value, typename T, typename U, typename V>
struct ThreadingTrait<HashMap<Key, Value, T, U, V, HeapAllocator>> {
STATIC_ONLY(ThreadingTrait);
static const ThreadAffinity kAffinity =
(ThreadingTrait<Key>::kAffinity == kMainThreadOnly) &&
(ThreadingTrait<Value>::kAffinity == kMainThreadOnly)
? kMainThreadOnly
: kAnyThread;
};
template <typename First, typename Second>
struct ThreadingTrait<WTF::KeyValuePair<First, Second>> {
STATIC_ONLY(ThreadingTrait);
static const ThreadAffinity kAffinity =
(ThreadingTrait<First>::kAffinity == kMainThreadOnly) &&
(ThreadingTrait<Second>::kAffinity == kMainThreadOnly)
? kMainThreadOnly
: kAnyThread;
};
template <typename T, typename U, typename V>
struct ThreadingTrait<HashSet<T, U, V, HeapAllocator>> {
STATIC_ONLY(ThreadingTrait);
static const ThreadAffinity kAffinity = ThreadingTrait<T>::kAffinity;
};
template <typename T, size_t inlineCapacity>
struct ThreadingTrait<Vector<T, inlineCapacity, HeapAllocator>> {
STATIC_ONLY(ThreadingTrait);
static const ThreadAffinity kAffinity = ThreadingTrait<T>::kAffinity;
};
template <typename T, typename Traits>
struct ThreadingTrait<HeapVectorBacking<T, Traits>> {
STATIC_ONLY(ThreadingTrait);
static const ThreadAffinity kAffinity = ThreadingTrait<T>::Affinity;
};
template <typename T, size_t inlineCapacity>
struct ThreadingTrait<Deque<T, inlineCapacity, HeapAllocator>> {
STATIC_ONLY(ThreadingTrait);
static const ThreadAffinity kAffinity = ThreadingTrait<T>::kAffinity;
};
template <typename T, typename U, typename V>
struct ThreadingTrait<HashCountedSet<T, U, V, HeapAllocator>> {
STATIC_ONLY(ThreadingTrait);
static const ThreadAffinity kAffinity = ThreadingTrait<T>::kAffinity;
};
template <typename Table>
struct ThreadingTrait<HeapHashTableBacking<Table>> {
STATIC_ONLY(ThreadingTrait);
using Key = typename Table::KeyType;
using Value = typename Table::ValueType;
static const ThreadAffinity kAffinity =
(ThreadingTrait<Key>::Affinity == kMainThreadOnly) &&
(ThreadingTrait<Value>::Affinity == kMainThreadOnly)
? kMainThreadOnly
: kAnyThread;
};
template <typename T, typename U, typename V, typename W, typename X>
class HeapHashMap;
template <typename T, typename U, typename V>
class HeapHashSet;
template <typename T, wtf_size_t inlineCapacity>
class HeapVector;
template <typename T, wtf_size_t inlineCapacity>
class HeapDeque;
template <typename T, typename U, typename V>
class HeapHashCountedSet;
template <typename T, typename U, typename V, typename W, typename X>
struct ThreadingTrait<HeapHashMap<T, U, V, W, X>>
: public ThreadingTrait<HashMap<T, U, V, W, X, HeapAllocator>> {
STATIC_ONLY(ThreadingTrait);
};
template <typename T, typename U, typename V>
struct ThreadingTrait<HeapHashSet<T, U, V>>
: public ThreadingTrait<HashSet<T, U, V, HeapAllocator>> {
STATIC_ONLY(ThreadingTrait);
};
template <typename T, size_t inlineCapacity>
struct ThreadingTrait<HeapVector<T, inlineCapacity>>
: public ThreadingTrait<Vector<T, inlineCapacity, HeapAllocator>> {
STATIC_ONLY(ThreadingTrait);
};
template <typename T, size_t inlineCapacity>
struct ThreadingTrait<HeapDeque<T, inlineCapacity>>
: public ThreadingTrait<Deque<T, inlineCapacity, HeapAllocator>> {
STATIC_ONLY(ThreadingTrait);
};
template <typename T, typename U, typename V>
struct ThreadingTrait<HeapHashCountedSet<T, U, V>>
: public ThreadingTrait<HashCountedSet<T, U, V, HeapAllocator>> {
STATIC_ONLY(ThreadingTrait);
};
} // namespace blink
#endif
|