Skip to content

Commit

Permalink
Ensure ThreadCache constructor runs.
Browse files Browse the repository at this point in the history
LinkedList's default constructor initializes state.  Freshly allocated
ThreadCache's either come from mmap (SystemAlloc) and all-zeroes are valid or
are reused and have been initialized.

PiperOrigin-RevId: 573026806
Change-Id: I8b92ec3e8535a89ab1c78311b33287997e6915a1
  • Loading branch information
ckennelly authored and copybara-github committed Oct 12, 2023
1 parent d697cb9 commit 5b4b217
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 8 deletions.
1 change: 0 additions & 1 deletion tcmalloc/testing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,6 @@ cc_test(
srcs = ["parallel_test.cc"],
copts = TCMALLOC_DEFAULT_COPTS,
malloc = "//tcmalloc/internal:system_malloc",
tags = ["nomsan"],
deps = [
"//tcmalloc:tcmalloc_internal_methods_only", # buildcleaner: keep
"@com_google_absl//absl/base:config",
Expand Down
4 changes: 0 additions & 4 deletions tcmalloc/testing/parallel_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ struct Allocator {
};

TEST(ParallelTest, Stable) {
#ifdef ABSL_HAVE_MEMORY_SANITIZER
// TODO(b/148986845): Enable this.
GTEST_SKIP() << "Skipping under msan.";
#endif
#ifdef ABSL_HAVE_THREAD_SANITIZER
// TODO(b/274996721): Enable this when Span::nonempty_index_ does not
// conflict with other bitfields.
Expand Down
4 changes: 2 additions & 2 deletions tcmalloc/thread_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ABSL_CONST_INIT thread_local ThreadCache* ThreadCache::thread_local_data_
ABSL_CONST_INIT bool ThreadCache::tsd_inited_ = false;
pthread_key_t ThreadCache::heap_key_;

void ThreadCache::Init(pthread_t tid) {
ThreadCache::ThreadCache(pthread_t tid) {
size_ = 0;

max_size_ = 0;
Expand Down Expand Up @@ -299,7 +299,7 @@ ThreadCache* ThreadCache::CreateCacheIfNecessary() {
ThreadCache* ThreadCache::NewHeap(pthread_t tid) {
// Create the heap and add it to the linked list
ThreadCache* heap = tc_globals.threadcache_allocator().New();
heap->Init(tid);
new (heap) ThreadCache(tid);
heap->next_ = thread_heaps_;
heap->prev_ = nullptr;
if (thread_heaps_ != nullptr) {
Expand Down
3 changes: 2 additions & 1 deletion tcmalloc/thread_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ namespace tcmalloc_internal {

class ThreadCache {
public:
void Init(pthread_t tid) ABSL_EXCLUSIVE_LOCKS_REQUIRED(pageheap_lock);
explicit ThreadCache(pthread_t tid)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(pageheap_lock);
void Cleanup();

// Accessors (mostly just for printing stats)
Expand Down

0 comments on commit 5b4b217

Please sign in to comment.