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 15 matching lines...) Expand all Loading... |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "wtf/WTF.h" | 31 #include "wtf/WTF.h" |
32 | 32 |
33 #include "wtf/Assertions.h" | 33 #include "wtf/Assertions.h" |
34 #include "wtf/Functional.h" | 34 #include "wtf/Functional.h" |
35 #include "wtf/Threading.h" | 35 #include "wtf/Threading.h" |
| 36 #include "wtf/WTFThreadData.h" |
36 #include "wtf/allocator/Partitions.h" | 37 #include "wtf/allocator/Partitions.h" |
37 #include "wtf/text/AtomicString.h" | 38 #include "wtf/text/AtomicString.h" |
38 #include "wtf/text/StringStatics.h" | 39 #include "wtf/text/StringStatics.h" |
39 #include "wtf/typed_arrays/ArrayBufferContents.h" | 40 #include "wtf/typed_arrays/ArrayBufferContents.h" |
40 | 41 |
41 namespace WTF { | 42 namespace WTF { |
42 | 43 |
43 extern void initializeThreading(); | 44 extern void initializeThreading(); |
44 | 45 |
45 bool s_initialized; | 46 bool s_initialized; |
46 bool s_shutdown; | 47 bool s_shutdown; |
47 void (*s_callOnMainThreadFunction)(MainThreadFunction, void*); | 48 void (*s_callOnMainThreadFunction)(MainThreadFunction, void*); |
48 ThreadIdentifier s_mainThreadIdentifier; | |
49 | 49 |
50 namespace internal { | 50 namespace internal { |
51 | 51 |
52 void callOnMainThread(MainThreadFunction* function, void* context) { | 52 void callOnMainThread(MainThreadFunction* function, void* context) { |
53 (*s_callOnMainThreadFunction)(function, context); | 53 (*s_callOnMainThreadFunction)(function, context); |
54 } | 54 } |
55 | 55 |
56 } // namespace internal | 56 } // namespace internal |
57 | 57 |
58 bool isMainThread() { | 58 bool isMainThread() { |
59 return currentThread() == s_mainThreadIdentifier; | 59 return WTFThreadData::isMainThread(); |
60 } | 60 } |
61 | 61 |
62 void initialize(void (*callOnMainThreadFunction)(MainThreadFunction, void*)) { | 62 void initialize(void (*callOnMainThreadFunction)(MainThreadFunction, void*)) { |
63 // WTF, and Blink in general, cannot handle being re-initialized, even if | 63 // WTF, and Blink in general, cannot handle being re-initialized, even if |
64 // shutdown first. Make that explicit here. | 64 // shutdown first. Make that explicit here. |
65 RELEASE_ASSERT(!s_initialized); | 65 RELEASE_ASSERT(!s_initialized); |
66 RELEASE_ASSERT(!s_shutdown); | 66 RELEASE_ASSERT(!s_shutdown); |
67 s_initialized = true; | 67 s_initialized = true; |
68 initializeThreading(); | 68 initializeThreading(); |
69 | 69 |
70 s_callOnMainThreadFunction = callOnMainThreadFunction; | 70 s_callOnMainThreadFunction = callOnMainThreadFunction; |
71 s_mainThreadIdentifier = currentThread(); | |
72 AtomicString::init(); | 71 AtomicString::init(); |
73 StringStatics::init(); | 72 StringStatics::init(); |
74 } | 73 } |
75 | 74 |
76 void shutdown() { | 75 void shutdown() { |
77 RELEASE_ASSERT(s_initialized); | 76 RELEASE_ASSERT(s_initialized); |
78 RELEASE_ASSERT(!s_shutdown); | 77 RELEASE_ASSERT(!s_shutdown); |
79 s_shutdown = true; | 78 s_shutdown = true; |
80 } | 79 } |
81 | 80 |
82 bool isShutdown() { | 81 bool isShutdown() { |
83 return s_shutdown; | 82 return s_shutdown; |
84 } | 83 } |
85 | 84 |
86 } // namespace WTF | 85 } // namespace WTF |
OLD | NEW |