Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: Source/wtf/WTF.cpp

Issue 1041103002: PartitionAlloc: Centralize Partition allocators into one place (Part 1) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/wtf/WTF.h ('k') | Source/wtf/text/CString.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « Source/wtf/WTF.h ('k') | Source/wtf/text/CString.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698