OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // | 64 // |
65 // FIXME: We should evaluate the performance gain. Having | 65 // FIXME: We should evaluate the performance gain. Having |
66 // ThreadAffinity is complicating the implementation and we should get | 66 // ThreadAffinity is complicating the implementation and we should get |
67 // rid of it if it is fast enough to go through thread-local storage | 67 // rid of it if it is fast enough to go through thread-local storage |
68 // always. | 68 // always. |
69 enum ThreadAffinity { | 69 enum ThreadAffinity { |
70 AnyThread, | 70 AnyThread, |
71 MainThreadOnly, | 71 MainThreadOnly, |
72 }; | 72 }; |
73 | 73 |
74 // By default all types are considered to be used on the main thread only. | 74 class Node; |
| 75 class CSSValue; |
| 76 |
| 77 template<typename T, bool derivesNodeOrCSSValue = WTF::IsSubclass<T, Node>::valu
e || WTF::IsSubclass<T, CSSValue>::value > struct DefaultThreadingTrait; |
| 78 |
| 79 template<typename T> |
| 80 struct DefaultThreadingTrait<T, false> { |
| 81 static const ThreadAffinity Affinity = AnyThread; |
| 82 }; |
| 83 |
| 84 template<typename T> |
| 85 struct DefaultThreadingTrait<T, true> { |
| 86 static const ThreadAffinity Affinity = MainThreadOnly; |
| 87 }; |
| 88 |
75 template<typename T> | 89 template<typename T> |
76 struct ThreadingTrait { | 90 struct ThreadingTrait { |
77 static const ThreadAffinity Affinity = MainThreadOnly; | 91 static const ThreadAffinity Affinity = DefaultThreadingTrait<T>::Affinity; |
78 }; | 92 }; |
79 | 93 |
80 // Marks the specified class as being used from multiple threads. When | 94 // Marks the specified class as being used from multiple threads. When |
81 // a class is used from multiple threads we go through thread local | 95 // a class is used from multiple threads we go through thread local |
82 // storage to get the heap in which to allocate an object of that type | 96 // storage to get the heap in which to allocate an object of that type |
83 // and when allocating a Persistent handle for an object with that | 97 // and when allocating a Persistent handle for an object with that |
84 // type. Notice that marking the base class does not automatically | 98 // type. Notice that marking the base class does not automatically |
85 // mark its descendants and they have to be explicitly marked. | 99 // mark its descendants and they have to be explicitly marked. |
86 #define USED_FROM_MULTIPLE_THREADS(Class) \ | 100 #define USED_FROM_MULTIPLE_THREADS(Class) \ |
87 class Class; \ | 101 class Class; \ |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 ASSERT(ThreadState::isMainThread()); | 552 ASSERT(ThreadState::isMainThread()); |
539 return ThreadState::mainThreadState(); | 553 return ThreadState::mainThreadState(); |
540 } | 554 } |
541 }; | 555 }; |
542 | 556 |
543 template<> class ThreadStateFor<AnyThread> { | 557 template<> class ThreadStateFor<AnyThread> { |
544 public: | 558 public: |
545 static ThreadState* state() { return ThreadState::current(); } | 559 static ThreadState* state() { return ThreadState::current(); } |
546 }; | 560 }; |
547 | 561 |
548 // FIXME: Experiment if the threading affinity really matters for performance. | |
549 // FIXME: Move these macros and other related structures to a separate file. | |
550 USED_FROM_MULTIPLE_THREADS(Crypto); | |
551 USED_FROM_MULTIPLE_THREADS(DOMParser); | |
552 USED_FROM_MULTIPLE_THREADS(DOMURL); | |
553 USED_FROM_MULTIPLE_THREADS(DeprecatedStorageQuota); | |
554 USED_FROM_MULTIPLE_THREADS(Event); | |
555 USED_FROM_MULTIPLE_THREADS(EventSource); | |
556 USED_FROM_MULTIPLE_THREADS(EventTarget); | |
557 USED_FROM_MULTIPLE_THREADS(Key); | |
558 USED_FROM_MULTIPLE_THREADS(KeyAlgorithm); | |
559 USED_FROM_MULTIPLE_THREADS(KeyPair); | |
560 USED_FROM_MULTIPLE_THREADS(MemoryInfo); | |
561 USED_FROM_MULTIPLE_THREADS(MessageEvent); | |
562 USED_FROM_MULTIPLE_THREADS(Notification); | |
563 USED_FROM_MULTIPLE_THREADS(NotificationCenter); | |
564 USED_FROM_MULTIPLE_THREADS(Performance); | |
565 USED_FROM_MULTIPLE_THREADS(PerformanceEntry); | |
566 USED_FROM_MULTIPLE_THREADS(PerformanceMark); | |
567 USED_FROM_MULTIPLE_THREADS(PerformanceNavigation); | |
568 USED_FROM_MULTIPLE_THREADS(PerformanceResourceTiming); | |
569 USED_FROM_MULTIPLE_THREADS(PerformanceTiming); | |
570 USED_FROM_MULTIPLE_THREADS(SubtleCrypto); | |
571 USED_FROM_MULTIPLE_THREADS(TextDecoder); | |
572 USED_FROM_MULTIPLE_THREADS(TextEncoder); | |
573 USED_FROM_MULTIPLE_THREADS(UserTiming); | |
574 USED_FROM_MULTIPLE_THREADS(WebKitNotification); | |
575 USED_FROM_MULTIPLE_THREADS(WorkerCrypto); | |
576 USED_FROM_MULTIPLE_THREADS(WorkerPerformance); | |
577 USED_FROM_MULTIPLE_THREADS(XMLHttpRequest); | |
578 USED_FROM_MULTIPLE_THREADS(XMLSerializer); | |
579 USED_FROM_MULTIPLE_THREADS(XPathEvaluator); | |
580 USED_FROM_MULTIPLE_THREADS(XPathExpression); | |
581 USED_FROM_MULTIPLE_THREADS(XPathNSResolver); | |
582 USED_FROM_MULTIPLE_THREADS(XPathResult); | |
583 USED_FROM_MULTIPLE_THREADS(XSLTProcessor); | |
584 | |
585 } | 562 } |
586 | 563 |
587 #endif // ThreadState_h | 564 #endif // ThreadState_h |
OLD | NEW |