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

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

Issue 1044143002: Oilpan: Centralize Partition allocators into Partitions.h (part 2) (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/FastMalloc.h ('k') | Source/wtf/Partitions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2005, 2007, Google Inc. 1 // Copyright (c) 2005, 2007, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2011 Apple Inc. All rights reserv ed. 3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2011 Apple Inc. All rights reserv ed.
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 13 matching lines...) Expand all
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "wtf/FastMalloc.h" 32 #include "wtf/FastMalloc.h"
33 33
34 #include "wtf/PartitionAlloc.h" 34 #include "wtf/Partitions.h"
35 #include "wtf/SpinLock.h"
36 #include <string.h> 35 #include <string.h>
37 36
38 namespace WTF { 37 namespace WTF {
39 38
40 static PartitionAllocatorGeneric gPartition;
41 static int gLock = 0;
42 static bool gInitialized = false;
43
44 void* fastZeroedMalloc(size_t n) 39 void* fastZeroedMalloc(size_t n)
45 { 40 {
46 void* result = fastMalloc(n); 41 void* result = fastMalloc(n);
47 memset(result, 0, n); 42 memset(result, 0, n);
48 return result; 43 return result;
49 } 44 }
50 45
51 char* fastStrDup(const char* src) 46 char* fastStrDup(const char* src)
52 { 47 {
53 size_t len = strlen(src) + 1; 48 size_t len = strlen(src) + 1;
54 char* dup = static_cast<char*>(fastMalloc(len)); 49 char* dup = static_cast<char*>(fastMalloc(len));
55 memcpy(dup, src, len); 50 memcpy(dup, src, len);
56 return dup; 51 return dup;
57 } 52 }
58 53
59 void fastMallocShutdown()
60 {
61 gPartition.shutdown();
62 }
63
64 void* fastMalloc(size_t n) 54 void* fastMalloc(size_t n)
65 { 55 {
66 if (UNLIKELY(!gInitialized)) { 56 return partitionAllocGeneric(Partitions::getFastMallocPartition(), n);
67 spinLockLock(&gLock);
68 if (!gInitialized) {
69 gInitialized = true;
70 gPartition.init();
71 }
72 spinLockUnlock(&gLock);
73 }
74 return partitionAllocGeneric(gPartition.root(), n);
75 } 57 }
76 58
77 void fastFree(void* p) 59 void fastFree(void* p)
78 { 60 {
79 partitionFreeGeneric(gPartition.root(), p); 61 partitionFreeGeneric(Partitions::getFastMallocPartition(), p);
80 } 62 }
81 63
82 void* fastRealloc(void* p, size_t n) 64 void* fastRealloc(void* p, size_t n)
83 { 65 {
84 return partitionReallocGeneric(gPartition.root(), p, n); 66 return partitionReallocGeneric(Partitions::getFastMallocPartition(), p, n);
85 } 67 }
86 68
87 } // namespace WTF 69 } // namespace WTF
OLDNEW
« no previous file with comments | « Source/wtf/FastMalloc.h ('k') | Source/wtf/Partitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698