Chromium Code Reviews| Index: Source/heap/ThreadState.h |
| diff --git a/Source/heap/ThreadState.h b/Source/heap/ThreadState.h |
| index 026d9e5cead408e9aab2fdc581a7913004ba25e6..957cd178112aa84de190039e8248ea3fcf85de53 100644 |
| --- a/Source/heap/ThreadState.h |
| +++ b/Source/heap/ThreadState.h |
| @@ -71,12 +71,42 @@ enum ThreadAffinity { |
| MainThreadOnly, |
| }; |
| -// By default all types are considered to be used on the main thread only. |
| +class Node; |
| +class CSSValue; |
| + |
| template<typename T> |
| -struct ThreadingTrait { |
| +class DerivesNodeOrCSSValue { |
| +private: |
| + typedef char YesType; |
| + struct NoType { |
| + char padding[8]; |
| + }; |
| + |
| + static YesType check(Node*); |
| + static YesType check(CSSValue*); |
| + static NoType check(void*); |
| + |
| +public: |
| + static const bool value = sizeof(check(static_cast<T*>(0))) == sizeof(YesType); |
| +}; |
| + |
| +template<typename T, bool derivesNodeOrCSSValue = DerivesNodeOrCSSValue<T>::value > class DefaultThreadingTrait; |
|
zerny-chromium
2014/02/21 07:04:54
I think this can use:
derivesNodeOrCSSValue = I
|
| + |
| +template<typename T> |
| +struct DefaultThreadingTrait<T, false> { |
|
haraken
2014/02/21 06:51:08
Would you add a comment to mention that only Node
|
| static const ThreadAffinity Affinity = MainThreadOnly; |
| }; |
| +template<typename T> |
| +struct DefaultThreadingTrait<T, true> { |
| + static const ThreadAffinity Affinity = AnyThread; |
| +}; |
| + |
| +template<typename T> |
| +struct ThreadingTrait { |
| + static const ThreadAffinity Affinity = DefaultThreadingTrait<T>::Affinity; |
| +}; |
| + |
| // Marks the specified class as being used from multiple threads. When |
| // a class is used from multiple threads we go through thread local |
| // storage to get the heap in which to allocate an object of that type |
| @@ -545,6 +575,7 @@ public: |
| static ThreadState* state() { return ThreadState::current(); } |
| }; |
| +/* |
| // FIXME: Experiment if the threading affinity really matters for performance. |
| // FIXME: Move these macros and other related structures to a separate file. |
| USED_FROM_MULTIPLE_THREADS(Algorithm); |
| @@ -576,6 +607,7 @@ USED_FROM_MULTIPLE_THREADS(XPathExpression); |
| USED_FROM_MULTIPLE_THREADS(XPathNSResolver); |
| USED_FROM_MULTIPLE_THREADS(XPathResult); |
| USED_FROM_MULTIPLE_THREADS(XSLTProcessor); |
| +*/ |
| } |