about summary refs log tree commit diff
path: root/absl/base/internal
diff options
context:
space:
mode:
authorGennadiy Civil <gennadiycivil@users.noreply.github.com>2017-10-30T14·56-0400
committerGitHub <noreply@github.com>2017-10-30T14·56-0400
commit200b5a7cb0fb256ab47c933b3150aed91d9d3470 (patch)
tree300713d880c593eb36cc6cea4bc8d1073bb03112 /absl/base/internal
parentd5134a7f11e32d11caa67e75ae2ae2e506fb54ba (diff)
parent0fece732a21c5ae8fef5fa8b3f0b8487bca68d83 (diff)
Merge branch 'master' into master
Diffstat (limited to 'absl/base/internal')
-rw-r--r--absl/base/internal/low_level_alloc.cc1
-rw-r--r--absl/base/internal/malloc_extension.cc7
-rw-r--r--absl/base/internal/malloc_extension.h7
-rw-r--r--absl/base/internal/spinlock_akaros.inc35
-rw-r--r--absl/base/internal/spinlock_wait.cc2
-rw-r--r--absl/base/internal/sysinfo.cc24
-rw-r--r--absl/base/internal/tsan_mutex_interface.h17
7 files changed, 89 insertions, 4 deletions
diff --git a/absl/base/internal/low_level_alloc.cc b/absl/base/internal/low_level_alloc.cc
index 08f89ea9ee54..8e2f9c98798b 100644
--- a/absl/base/internal/low_level_alloc.cc
+++ b/absl/base/internal/low_level_alloc.cc
@@ -30,6 +30,7 @@
 #ifndef ABSL_LOW_LEVEL_ALLOC_MISSING
 
 #ifndef _WIN32
+#include <pthread.h>
 #include <signal.h>
 #include <sys/mman.h>
 #include <unistd.h>
diff --git a/absl/base/internal/malloc_extension.cc b/absl/base/internal/malloc_extension.cc
index 3da981ce06a3..d48ec5bcf548 100644
--- a/absl/base/internal/malloc_extension.cc
+++ b/absl/base/internal/malloc_extension.cc
@@ -29,6 +29,13 @@ namespace base_internal {
 SysAllocator::~SysAllocator() {}
 void SysAllocator::GetStats(char* buffer, int) { buffer[0] = 0; }
 
+// Dummy key method to avoid weak vtable.
+void MallocExtensionWriter::UnusedKeyMethod() {}
+
+void StringMallocExtensionWriter::Write(const char* buf, int len) {
+  out_->append(buf, len);
+}
+
 // Default implementation -- does nothing
 MallocExtension::~MallocExtension() { }
 bool MallocExtension::VerifyAllMemory() { return true; }
diff --git a/absl/base/internal/malloc_extension.h b/absl/base/internal/malloc_extension.h
index 46b767ff2c3f..75a00ce9a78d 100644
--- a/absl/base/internal/malloc_extension.h
+++ b/absl/base/internal/malloc_extension.h
@@ -388,6 +388,9 @@ class MallocExtensionWriter {
   MallocExtensionWriter() {}
   MallocExtensionWriter(const MallocExtensionWriter&) = delete;
   MallocExtensionWriter& operator=(const MallocExtensionWriter&) = delete;
+
+ private:
+  virtual void UnusedKeyMethod();  // Dummy key method to avoid weak vtable.
 };
 
 // A subclass that writes to the std::string "out".  NOTE: The generated
@@ -396,9 +399,7 @@ class MallocExtensionWriter {
 class StringMallocExtensionWriter : public MallocExtensionWriter {
  public:
   explicit StringMallocExtensionWriter(std::string* out) : out_(out) {}
-  virtual void Write(const char* buf, int len) {
-    out_->append(buf, len);
-  }
+  void Write(const char* buf, int len) override;
 
  private:
   std::string* const out_;
diff --git a/absl/base/internal/spinlock_akaros.inc b/absl/base/internal/spinlock_akaros.inc
new file mode 100644
index 000000000000..051c8cf87fb6
--- /dev/null
+++ b/absl/base/internal/spinlock_akaros.inc
@@ -0,0 +1,35 @@
+// Copyright 2017 The Abseil Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// This file is an Akaros-specific part of spinlock_wait.cc
+
+#include <atomic>
+
+#include "absl/base/internal/scheduling_mode.h"
+
+extern "C" {
+
+ABSL_ATTRIBUTE_WEAK void AbslInternalSpinLockDelay(
+    std::atomic<uint32_t>* /* lock_word */, uint32_t /* value */,
+    int /* loop */, absl::base_internal::SchedulingMode /* mode */) {
+  // In Akaros, one must take care not to call anything that could cause a
+  // malloc(), a blocking system call, or a uthread_yield() while holding a
+  // spinlock. Our callers assume will not call into libraries or other
+  // arbitrary code.
+}
+
+ABSL_ATTRIBUTE_WEAK void AbslInternalSpinLockWake(
+    std::atomic<uint32_t>* /* lock_word */, bool /* all */) {}
+
+}  // extern "C"
diff --git a/absl/base/internal/spinlock_wait.cc b/absl/base/internal/spinlock_wait.cc
index 0fd36286629d..8f951b66dc36 100644
--- a/absl/base/internal/spinlock_wait.cc
+++ b/absl/base/internal/spinlock_wait.cc
@@ -23,6 +23,8 @@
 
 #if defined(_WIN32)
 #include "absl/base/internal/spinlock_win32.inc"
+#elif defined(__akaros__)
+#include "absl/base/internal/spinlock_akaros.inc"
 #else
 #include "absl/base/internal/spinlock_posix.inc"
 #endif
diff --git a/absl/base/internal/sysinfo.cc b/absl/base/internal/sysinfo.cc
index 9e0140fadb1f..00e98b662cc6 100644
--- a/absl/base/internal/sysinfo.cc
+++ b/absl/base/internal/sysinfo.cc
@@ -284,6 +284,30 @@ pid_t GetTID() {
   return syscall(SYS_gettid);
 }
 
+#elif defined(__akaros__)
+
+pid_t GetTID() {
+  // Akaros has a concept of "vcore context", which is the state the program
+  // is forced into when we need to make a user-level scheduling decision, or
+  // run a signal handler.  This is analogous to the interrupt context that a
+  // CPU might enter if it encounters some kind of exception.
+  //
+  // There is no current thread context in vcore context, but we need to give
+  // a reasonable answer if asked for a thread ID (e.g., in a signal handler).
+  // Thread 0 always exists, so if we are in vcore context, we return that.
+  //
+  // Otherwise, we know (since we are using pthreads) that the uthread struct
+  // current_uthread is pointing to is the first element of a
+  // struct pthread_tcb, so we extract and return the thread ID from that.
+  //
+  // TODO(dcross): Akaros anticipates moving the thread ID to the uthread
+  // structure at some point. We should modify this code to remove the cast
+  // when that happens.
+  if (in_vcore_context())
+    return 0;
+  return reinterpret_cast<struct pthread_tcb *>(current_uthread)->id;
+}
+
 #else
 
 // Fallback implementation of GetTID using pthread_getspecific.
diff --git a/absl/base/internal/tsan_mutex_interface.h b/absl/base/internal/tsan_mutex_interface.h
index a1303e67c8f5..6bb4faedb879 100644
--- a/absl/base/internal/tsan_mutex_interface.h
+++ b/absl/base/internal/tsan_mutex_interface.h
@@ -19,7 +19,22 @@
 #ifndef ABSL_BASE_INTERNAL_TSAN_MUTEX_INTERFACE_H_
 #define ABSL_BASE_INTERNAL_TSAN_MUTEX_INTERFACE_H_
 
-#ifdef THREAD_SANITIZER
+// ABSL_INTERNAL_HAVE_TSAN_INTERFACE
+// Macro intended only for internal use.
+//
+// Checks whether LLVM Thread Sanitizer interfaces are available.
+// First made available in LLVM 5.0 (Sep 2017).
+#ifdef ABSL_INTERNAL_HAVE_TSAN_INTERFACE
+#error "ABSL_INTERNAL_HAVE_TSAN_INTERFACE cannot be directly set."
+#endif
+
+#if defined(THREAD_SANITIZER) && defined(__has_include)
+#if __has_include(<sanitizer/tsan_interface.h>)
+#define ABSL_INTERNAL_HAVE_TSAN_INTERFACE 1
+#endif
+#endif
+
+#ifdef ABSL_INTERNAL_HAVE_TSAN_INTERFACE
 #include <sanitizer/tsan_interface.h>
 
 #define ABSL_TSAN_MUTEX_CREATE __tsan_mutex_create