[PATCH] D31306: Postpone lsan tls allocation until required

Francis Ricci via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 28 15:09:12 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL298947: Postpone lsan tls allocation until required (authored by fjricci).

Changed prior to commit:
  https://reviews.llvm.org/D31306?vs=92863&id=93311#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D31306

Files:
  compiler-rt/trunk/lib/lsan/lsan_common_mac.cc


Index: compiler-rt/trunk/lib/lsan/lsan_common_mac.cc
===================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common_mac.cc
+++ compiler-rt/trunk/lib/lsan/lsan_common_mac.cc
@@ -35,11 +35,11 @@
 
 static void make_tls_key() { CHECK_EQ(pthread_key_create(&key, NULL), 0); }
 
-static thread_local_data_t *get_tls_val() {
+static thread_local_data_t *get_tls_val(bool alloc) {
   pthread_once(&key_once, make_tls_key);
 
   thread_local_data_t *ptr = (thread_local_data_t *)pthread_getspecific(key);
-  if (ptr == NULL) {
+  if (ptr == NULL && alloc) {
     ptr = (thread_local_data_t *)InternalAlloc(sizeof(*ptr));
     ptr->disable_counter = 0;
     ptr->current_thread_id = kInvalidTid;
@@ -50,23 +50,26 @@
   return ptr;
 }
 
-bool DisabledInThisThread() { return get_tls_val()->disable_counter > 0; }
+bool DisabledInThisThread() {
+  thread_local_data_t *data = get_tls_val(false);
+  return data ? data->disable_counter > 0 : false;
+}
 
-void DisableInThisThread() { ++get_tls_val()->disable_counter; }
+void DisableInThisThread() { ++get_tls_val(true)->disable_counter; }
 
 void EnableInThisThread() {
-  int *disable_counter = &get_tls_val()->disable_counter;
+  int *disable_counter = &get_tls_val(true)->disable_counter;
   if (*disable_counter == 0) {
     DisableCounterUnderflow();
   }
   --*disable_counter;
 }
 
-u32 GetCurrentThread() { return get_tls_val()->current_thread_id; }
+u32 GetCurrentThread() { return get_tls_val(true)->current_thread_id; }
 
-void SetCurrentThread(u32 tid) { get_tls_val()->current_thread_id = tid; }
+void SetCurrentThread(u32 tid) { get_tls_val(true)->current_thread_id = tid; }
 
-AllocatorCache *GetAllocatorCache() { return &get_tls_val()->cache; }
+AllocatorCache *GetAllocatorCache() { return &get_tls_val(true)->cache; }
 
 void InitializePlatformSpecificModules() {
   CHECK(0 && "unimplemented");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31306.93311.patch
Type: text/x-patch
Size: 1902 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170328/cf8a71c5/attachment.bin>


More information about the llvm-commits mailing list