| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2012 Google, Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 113 |
| 114 // Supplementable<T> inherits from GarbageCollectedMixin virtually | 114 // Supplementable<T> inherits from GarbageCollectedMixin virtually |
| 115 // to allow ExecutionContext to derive from two GC mixin classes. | 115 // to allow ExecutionContext to derive from two GC mixin classes. |
| 116 template <typename T> | 116 template <typename T> |
| 117 class Supplementable : public virtual GarbageCollectedMixin { | 117 class Supplementable : public virtual GarbageCollectedMixin { |
| 118 WTF_MAKE_NONCOPYABLE(Supplementable); | 118 WTF_MAKE_NONCOPYABLE(Supplementable); |
| 119 | 119 |
| 120 public: | 120 public: |
| 121 void provideSupplement(const char* key, Supplement<T>* supplement) { | 121 void provideSupplement(const char* key, Supplement<T>* supplement) { |
| 122 #if DCHECK_IS_ON() | 122 #if DCHECK_IS_ON() |
| 123 DCHECK_EQ(m_threadId, currentThread()); | 123 DCHECK_EQ(m_creationThreadId, currentThread()); |
| 124 #endif | 124 #endif |
| 125 this->m_supplements.set(key, supplement); | 125 this->m_supplements.set(key, supplement); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void removeSupplement(const char* key) { | 128 void removeSupplement(const char* key) { |
| 129 #if DCHECK_IS_ON() | 129 #if DCHECK_IS_ON() |
| 130 DCHECK_EQ(m_threadId, currentThread()); | 130 DCHECK_EQ(m_creationThreadId, currentThread()); |
| 131 #endif | 131 #endif |
| 132 this->m_supplements.remove(key); | 132 this->m_supplements.remove(key); |
| 133 } | 133 } |
| 134 | 134 |
| 135 Supplement<T>* requireSupplement(const char* key) { | 135 Supplement<T>* requireSupplement(const char* key) { |
| 136 #if DCHECK_IS_ON() | 136 #if DCHECK_IS_ON() |
| 137 DCHECK_EQ(m_threadId, currentThread()); | 137 DCHECK_EQ(m_attachedThreadId, currentThread()); |
| 138 #endif | 138 #endif |
| 139 return this->m_supplements.get(key); | 139 return this->m_supplements.get(key); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void reattachThread() { | 142 void reattachThread() { |
| 143 #if DCHECK_IS_ON() | 143 #if DCHECK_IS_ON() |
| 144 m_threadId = currentThread(); | 144 m_attachedThreadId = currentThread(); |
| 145 #endif | 145 #endif |
| 146 } | 146 } |
| 147 | 147 |
| 148 DEFINE_INLINE_VIRTUAL_TRACE() { visitor->trace(m_supplements); } | 148 DEFINE_INLINE_VIRTUAL_TRACE() { visitor->trace(m_supplements); } |
| 149 | 149 |
| 150 protected: | 150 protected: |
| 151 using SupplementMap = | 151 using SupplementMap = |
| 152 HeapHashMap<const char*, Member<Supplement<T>>, PtrHash<const char>>; | 152 HeapHashMap<const char*, Member<Supplement<T>>, PtrHash<const char>>; |
| 153 SupplementMap m_supplements; | 153 SupplementMap m_supplements; |
| 154 | 154 |
| 155 Supplementable() | 155 Supplementable() |
| 156 #if DCHECK_IS_ON() | 156 #if DCHECK_IS_ON() |
| 157 : m_threadId(currentThread()) | 157 : m_attachedThreadId(currentThread()), |
| 158 m_creationThreadId(currentThread()) |
| 158 #endif | 159 #endif |
| 159 { | 160 { |
| 160 } | 161 } |
| 161 | 162 |
| 162 #if DCHECK_IS_ON() | 163 #if DCHECK_IS_ON() |
| 163 private: | 164 private: |
| 164 ThreadIdentifier m_threadId; | 165 ThreadIdentifier m_attachedThreadId; |
| 166 ThreadIdentifier m_creationThreadId; |
| 165 #endif | 167 #endif |
| 166 }; | 168 }; |
| 167 | 169 |
| 168 template <typename T> | 170 template <typename T> |
| 169 struct ThreadingTrait<Supplement<T>> { | 171 struct ThreadingTrait<Supplement<T>> { |
| 170 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; | 172 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; |
| 171 }; | 173 }; |
| 172 | 174 |
| 173 template <typename T> | 175 template <typename T> |
| 174 struct ThreadingTrait<Supplementable<T>> { | 176 struct ThreadingTrait<Supplementable<T>> { |
| 175 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; | 177 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; |
| 176 }; | 178 }; |
| 177 | 179 |
| 178 } // namespace blink | 180 } // namespace blink |
| 179 | 181 |
| 180 #endif // Supplementable_h | 182 #endif // Supplementable_h |
| OLD | NEW |