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

Side by Side Diff: base/allocator/allocator_shim.cc

Issue 10828054: Modify allocator_shim to support _aligned_alloc(), _aligned_free(). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Unit tests. Created 8 years, 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/allocator/allocator_shim.h" 5 #include "base/allocator/allocator_shim.h"
6 6
7 #include <config.h> 7 #include <config.h>
8 #include "base/allocator/allocator_extension_thunks.h" 8 #include "base/allocator/allocator_extension_thunks.h"
9 #include "base/profiler/alternate_timer.h" 9 #include "base/profiler/alternate_timer.h"
10 #include "base/sysinfo.h" 10 #include "base/sysinfo.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 #include "tcmalloc.cc" 58 #include "tcmalloc.cc"
59 #include "win_allocator.cc" 59 #include "win_allocator.cc"
60 60
61 // Forward declarations from jemalloc. 61 // Forward declarations from jemalloc.
62 extern "C" { 62 extern "C" {
63 void* je_malloc(size_t s); 63 void* je_malloc(size_t s);
64 void* je_realloc(void* p, size_t s); 64 void* je_realloc(void* p, size_t s);
65 void je_free(void* s); 65 void je_free(void* s);
66 size_t je_msize(void* p); 66 size_t je_msize(void* p);
67 bool je_malloc_init_hard(); 67 bool je_malloc_init_hard();
68 void* je_memalign(size_t a, size_t s);
68 } 69 }
69 70
70 extern "C" { 71 extern "C" {
71 72
72 // Call the new handler, if one has been set. 73 // Call the new handler, if one has been set.
73 // Returns true on successfully calling the handler, false otherwise. 74 // Returns true on successfully calling the handler, false otherwise.
74 inline bool call_new_handler(bool nothrow) { 75 inline bool call_new_handler(bool nothrow) {
75 // Get the current new handler. NB: this function is not 76 // Get the current new handler. NB: this function is not
76 // thread-safe. We make a feeble stab at making it so here, but 77 // thread-safe. We make a feeble stab at making it so here, but
77 // this lock only protects against tcmalloc interfering with 78 // this lock only protects against tcmalloc interfering with
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 293
293 // The CRT heap cleanup stub. 294 // The CRT heap cleanup stub.
294 extern "C" void _heap_term() {} 295 extern "C" void _heap_term() {}
295 296
296 // We set this to 1 because part of the CRT uses a check of _crtheap != 0 297 // We set this to 1 because part of the CRT uses a check of _crtheap != 0
297 // to test whether the CRT has been initialized. Once we've ripped out 298 // to test whether the CRT has been initialized. Once we've ripped out
298 // the allocators from libcmt, we need to provide this definition so that 299 // the allocators from libcmt, we need to provide this definition so that
299 // the rest of the CRT is still usable. 300 // the rest of the CRT is still usable.
300 extern "C" void* _crtheap = reinterpret_cast<void*>(1); 301 extern "C" void* _crtheap = reinterpret_cast<void*>(1);
301 302
303 // Provide support for aligned memory through Windows only _aligned_malloc().
304 void* _aligned_malloc(size_t size, size_t alignment) {
305 void* ptr;
306 for (;;) {
307 #ifdef ENABLE_DYNAMIC_ALLOCATOR_SWITCHING
308 switch (allocator) {
309 case JEMALLOC:
310 ptr = je_memalign(alignment, size);
311 break;
312 case WINHEAP:
313 case WINLFH:
314 ptr = win_heap_memalign(alignment, size);
315 break;
316 case TCMALLOC:
317 default:
318 ptr = tc_memalign(alignment, size);
319 break;
320 }
321 #else
322 // TCMalloc case.
323 ptr = tc_memalign(alignment, size);
324 #endif
325 if (ptr)
326 return ptr;
327
328 if (!new_mode || !call_new_handler(true))
329 break;
330 }
331 return ptr;
332 }
333
334 void _aligned_free(void* p) {
335 #ifdef ENABLE_DYNAMIC_ALLOCATOR_SWITCHING
336 switch (allocator) {
337 case JEMALLOC:
338 je_free(p);
339 return;
340 case WINHEAP:
341 case WINLFH:
342 win_heap_memalign_free(p);
343 return;
344 }
345 #endif
346 // TCMalloc case.
347 do_free(p);
348 }
349
302 #endif // WIN32 350 #endif // WIN32
303 351
304 #include "generic_allocators.cc" 352 #include "generic_allocators.cc"
305 353
306 } // extern C 354 } // extern C
307 355
308 namespace base { 356 namespace base {
309 namespace allocator { 357 namespace allocator {
310 358
311 void SetupSubprocessAllocator() { 359 void SetupSubprocessAllocator() {
(...skipping 23 matching lines...) Expand all
335 void TCMallocDoFreeForTest(void* ptr) { 383 void TCMallocDoFreeForTest(void* ptr) {
336 do_free(ptr); 384 do_free(ptr);
337 } 385 }
338 386
339 size_t ExcludeSpaceForMarkForTest(size_t size) { 387 size_t ExcludeSpaceForMarkForTest(size_t size) {
340 return ExcludeSpaceForMark(size); 388 return ExcludeSpaceForMark(size);
341 } 389 }
342 390
343 } // namespace allocator. 391 } // namespace allocator.
344 } // namespace base. 392 } // namespace base.
OLDNEW
« no previous file with comments | « no previous file | base/allocator/allocator_unittests.cc » ('j') | base/allocator/allocator_unittests.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698