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 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
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 "config.h" | 31 #include "config.h" |
32 #include "WTF.h" | 32 #include "WTF.h" |
33 | 33 |
34 #include "wtf/DefaultAllocator.h" | 34 #include "wtf/Assertions.h" |
35 #include "wtf/FastMalloc.h" | 35 #include "wtf/FastMalloc.h" |
| 36 #include "wtf/Partitions.h" |
36 | 37 |
37 namespace WTF { | 38 namespace WTF { |
38 | 39 |
39 extern void initializeThreading(); | 40 extern void initializeThreading(); |
40 | 41 |
41 bool s_initialized; | 42 bool s_initialized; |
42 bool s_shutdown; | 43 bool s_shutdown; |
43 bool Partitions::s_initialized; | |
44 PartitionAllocatorGeneric Partitions::m_bufferAllocator; | |
45 | 44 |
46 void initialize(TimeFunction currentTimeFunction, TimeFunction monotonicallyIncr
easingTimeFunction) | 45 void initialize(TimeFunction currentTimeFunction, TimeFunction monotonicallyIncr
easingTimeFunction) |
47 { | 46 { |
48 // WTF, and Blink in general, cannot handle being re-initialized, even if sh
utdown first. | 47 // WTF, and Blink in general, cannot handle being re-initialized, even if sh
utdown first. |
49 // Make that explicit here. | 48 // Make that explicit here. |
50 ASSERT(!s_initialized); | 49 ASSERT(!s_initialized); |
51 ASSERT(!s_shutdown); | 50 ASSERT(!s_shutdown); |
52 s_initialized = true; | 51 s_initialized = true; |
53 Partitions::initialize(); | |
54 setCurrentTimeFunction(currentTimeFunction); | 52 setCurrentTimeFunction(currentTimeFunction); |
55 setMonotonicallyIncreasingTimeFunction(monotonicallyIncreasingTimeFunction); | 53 setMonotonicallyIncreasingTimeFunction(monotonicallyIncreasingTimeFunction); |
| 54 Partitions::initialize(); |
56 initializeThreading(); | 55 initializeThreading(); |
57 } | 56 } |
58 | 57 |
59 void shutdown() | 58 void shutdown() |
60 { | 59 { |
61 ASSERT(s_initialized); | 60 ASSERT(s_initialized); |
62 ASSERT(!s_shutdown); | 61 ASSERT(!s_shutdown); |
63 s_shutdown = true; | 62 s_shutdown = true; |
64 Partitions::shutdown(); | 63 Partitions::shutdown(); |
65 } | 64 } |
66 | 65 |
67 bool isShutdown() | 66 bool isShutdown() |
68 { | 67 { |
69 return s_shutdown; | 68 return s_shutdown; |
70 } | 69 } |
71 | 70 |
72 void Partitions::initialize() | |
73 { | |
74 static int lock = 0; | |
75 // Guard against two threads hitting here in parallel. | |
76 spinLockLock(&lock); | |
77 if (!s_initialized) { | |
78 m_bufferAllocator.init(); | |
79 s_initialized = true; | |
80 } | |
81 spinLockUnlock(&lock); | |
82 } | |
83 | |
84 void Partitions::shutdown() | |
85 { | |
86 fastMallocShutdown(); | |
87 m_bufferAllocator.shutdown(); | |
88 } | |
89 | |
90 } // namespace WTF | 71 } // namespace WTF |
OLD | NEW |