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

Side by Side Diff: third_party/tcmalloc/chromium/src/static_vars.cc

Issue 1715903002: Adapt upstream patches fixing potential deadlock in tcmalloc after fork. Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Updated README Created 4 years, 10 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
« no previous file with comments | « third_party/tcmalloc/chromium/src/maybe_threads.cc ('k') | no next file » | 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) 2008, Google Inc. 1 // Copyright (c) 2008, Google Inc.
2 // All rights reserved. 2 // 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 18 matching lines...) Expand all
29 29
30 // --- 30 // ---
31 // Author: Ken Ashcraft <opensource@google.com> 31 // Author: Ken Ashcraft <opensource@google.com>
32 32
33 #include "static_vars.h" 33 #include "static_vars.h"
34 #include <stddef.h> // for NULL 34 #include <stddef.h> // for NULL
35 #include <new> // for operator new 35 #include <new> // for operator new
36 #include "internal_logging.h" // for CHECK_CONDITION 36 #include "internal_logging.h" // for CHECK_CONDITION
37 #include "common.h" 37 #include "common.h"
38 #include "sampler.h" // for Sampler 38 #include "sampler.h" // for Sampler
39 #include "base/googleinit.h"
40 #include "maybe_threads.h"
39 41
40 namespace tcmalloc { 42 namespace tcmalloc {
41 43
44 #if defined(HAVE_FORK) && defined(HAVE_PTHREAD) && !defined(__APPLE__)
45
46 // These following two functions are registered via pthread_atfork to make
47 // sure the central_cache locks remain in a consisten state in the forked
48 // version of the thread.
49
50 void CentralCacheLockAll()
51 {
52 Static::pageheap_lock()->Lock();
53 for (int i = 0; i < kNumClasses; ++i)
54 Static::central_cache()[i].Lock();
55 }
56
57 void CentralCacheUnlockAll()
58 {
59 for (int i = 0; i < kNumClasses; ++i)
60 Static::central_cache()[i].Unlock();
61 Static::pageheap_lock()->Unlock();
62 }
63 #endif
64
42 SpinLock Static::pageheap_lock_(SpinLock::LINKER_INITIALIZED); 65 SpinLock Static::pageheap_lock_(SpinLock::LINKER_INITIALIZED);
43 SizeMap Static::sizemap_; 66 SizeMap Static::sizemap_;
44 CentralFreeListPadded Static::central_cache_[kNumClasses]; 67 CentralFreeListPadded Static::central_cache_[kNumClasses];
45 PageHeapAllocator<Span> Static::span_allocator_; 68 PageHeapAllocator<Span> Static::span_allocator_;
46 PageHeapAllocator<StackTrace> Static::stacktrace_allocator_; 69 PageHeapAllocator<StackTrace> Static::stacktrace_allocator_;
47 Span Static::sampled_objects_; 70 Span Static::sampled_objects_;
48 PageHeapAllocator<StackTraceTable::Bucket> Static::bucket_allocator_; 71 PageHeapAllocator<StackTraceTable::Bucket> Static::bucket_allocator_;
49 StackTrace* Static::growth_stacks_ = NULL; 72 StackTrace* Static::growth_stacks_ = NULL;
50 PageHeap* Static::pageheap_ = NULL; 73 PageHeap* Static::pageheap_ = NULL;
51 74
(...skipping 11 matching lines...) Expand all
63 } 86 }
64 // It's important to have PageHeap allocated, not in static storage, 87 // It's important to have PageHeap allocated, not in static storage,
65 // so that HeapLeakChecker does not consider all the byte patterns stored 88 // so that HeapLeakChecker does not consider all the byte patterns stored
66 // in is caches as pointers that are sources of heap object liveness, 89 // in is caches as pointers that are sources of heap object liveness,
67 // which leads to it missing some memory leaks. 90 // which leads to it missing some memory leaks.
68 pageheap_ = new (MetaDataAlloc(sizeof(PageHeap))) PageHeap; 91 pageheap_ = new (MetaDataAlloc(sizeof(PageHeap))) PageHeap;
69 DLL_Init(&sampled_objects_); 92 DLL_Init(&sampled_objects_);
70 Sampler::InitStatics(); 93 Sampler::InitStatics();
71 } 94 }
72 95
96
97 #if defined(HAVE_FORK) && defined(HAVE_PTHREAD) && !defined(__APPLE__)
98
99 static inline
100 void SetupAtForkLocksHandler()
101 {
102 perftools_pthread_atfork(
103 CentralCacheLockAll, // parent calls before fork
104 CentralCacheUnlockAll, // parent calls after fork
105 CentralCacheUnlockAll); // child calls after fork
106 }
107 REGISTER_MODULE_INITIALIZER(tcmalloc_fork_handler, SetupAtForkLocksHandler());
108
109 #endif
110
73 } // namespace tcmalloc 111 } // namespace tcmalloc
OLDNEW
« no previous file with comments | « third_party/tcmalloc/chromium/src/maybe_threads.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698