Merge branch 'master' into master
This commit is contained in:
commit
200b5a7cb0
38 changed files with 461 additions and 191 deletions
|
|
@ -25,11 +25,10 @@ package(default_visibility = ["//visibility:public"])
|
|||
|
||||
licenses(["notice"]) # Apache 2.0
|
||||
|
||||
exports_files(["thread_annotations.h"])
|
||||
|
||||
cc_library(
|
||||
name = "spinlock_wait",
|
||||
srcs = [
|
||||
"internal/spinlock_akaros.inc",
|
||||
"internal/spinlock_posix.inc",
|
||||
"internal/spinlock_wait.cc",
|
||||
"internal/spinlock_win32.inc",
|
||||
|
|
@ -39,6 +38,9 @@ cc_library(
|
|||
"internal/spinlock_wait.h",
|
||||
],
|
||||
copts = ABSL_DEFAULT_COPTS,
|
||||
visibility = [
|
||||
"//absl/base:__pkg__",
|
||||
],
|
||||
deps = [":core_headers"],
|
||||
)
|
||||
|
||||
|
|
@ -83,6 +85,9 @@ cc_library(
|
|||
"internal/malloc_extension_c.h",
|
||||
],
|
||||
copts = ABSL_DEFAULT_COPTS,
|
||||
visibility = [
|
||||
"//absl:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
":core_headers",
|
||||
":dynamic_annotations",
|
||||
|
|
@ -108,6 +113,9 @@ cc_library(
|
|||
textual_hdrs = [
|
||||
"internal/malloc_hook_invoke.h",
|
||||
],
|
||||
visibility = [
|
||||
"//absl:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
":base",
|
||||
":config",
|
||||
|
|
@ -124,6 +132,9 @@ cc_library(
|
|||
"internal/invoke.h",
|
||||
],
|
||||
copts = ABSL_DEFAULT_COPTS,
|
||||
visibility = [
|
||||
"//absl:__subpackages__",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
|
|
@ -183,6 +194,9 @@ cc_library(
|
|||
features = [
|
||||
"-use_header_modules",
|
||||
],
|
||||
visibility = [
|
||||
"//absl:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
":base",
|
||||
":config",
|
||||
|
|
@ -205,6 +219,7 @@ cc_library(
|
|||
testonly = 1,
|
||||
hdrs = ["internal/exception_testing.h"],
|
||||
copts = ABSL_TEST_COPTS,
|
||||
visibility = ["//absl:__subpackages__"],
|
||||
deps = [
|
||||
":config",
|
||||
"@com_google_googletest//:gtest",
|
||||
|
|
|
|||
|
|
@ -372,4 +372,19 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
// For MSVC, `__has_include` is supported in VS 2017 15.3, which is later than
|
||||
// the support for <optional>, <any>, <string_view>. So we use _MSC_VER to check
|
||||
// whether we have VS 2017 RTM (when <optional>, <any>, <string_view> is
|
||||
// implemented) or higher.
|
||||
// Also, `__cplusplus` is not correctly set by MSVC, so we use `_MSVC_LANG` to
|
||||
// check the language version.
|
||||
// TODO(zhangxy): fix tests before enabling aliasing for `std::any`,
|
||||
// `std::string_view`.
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1910 && \
|
||||
((defined(_MSVC_LANG) && _MSVC_LANG > 201402) || __cplusplus > 201402)
|
||||
// #define ABSL_HAVE_STD_ANY 1
|
||||
#define ABSL_HAVE_STD_OPTIONAL 1
|
||||
// #define ABSL_HAVE_STD_STRING_VIEW 1
|
||||
#endif
|
||||
|
||||
#endif // ABSL_BASE_CONFIG_H_
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
|
|
|||
|
|
@ -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_;
|
||||
|
|
|
|||
35
absl/base/internal/spinlock_akaros.inc
Normal file
35
absl/base/internal/spinlock_akaros.inc
Normal file
|
|
@ -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"
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
#ifndef ABSL_BASE_MACROS_H_
|
||||
#define ABSL_BASE_MACROS_H_
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
|
||||
#include "absl/base/port.h"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue