Commit 2c8a5b0d by Abseil Team Committed by Andy Getz

Export of internal Abseil changes

--
873b52b0a691e759413c5db27dafc541a5da5263 by Andy Getzendanner <durandal@google.com>:

Introduce an internal-only thread-local caching wrapper around GetTID.

PiperOrigin-RevId: 323055682

--
091a4537f1ef6e158acbf4261cfae1af7a3bdb7f by Abseil Team <absl-team@google.com>:

Internal change

PiperOrigin-RevId: 322864497

--
c80ccfff2a825819f31826a30f48cca3297699f8 by Evan Brown <ezb@google.com>:

Roll forward b-tree changes simplifying deletion and getting rid of recursion in clear_and_delete().

We also change clear_and_delete() to avoid some unnecessary comparisons by restructuring the loops.

PiperOrigin-RevId: 322658938

--
81464c0fb9c8c6268dca2e530aba99e75e1e59ae by Gennadiy Rozental <rogeeff@google.com>:

Eliminate definition of RunningOnValgrind inside the library.

Fixes #674
Fixes #657

PiperOrigin-RevId: 322508440
GitOrigin-RevId: 873b52b0a691e759413c5db27dafc541a5da5263
Change-Id: I20b40c9e8fc62edcf981caab467cca33cf6fd2ba
parent 41a6263f
......@@ -8,7 +8,6 @@ set(ABSL_INTERNAL_DLL_FILES
"base/casts.h"
"base/config.h"
"base/const_init.h"
"base/dynamic_annotations.cc"
"base/dynamic_annotations.h"
"base/internal/atomic_hook.h"
"base/internal/bits.h"
......
......@@ -116,7 +116,6 @@ cc_library(
cc_library(
name = "dynamic_annotations",
srcs = [
"dynamic_annotations.cc",
"internal/dynamic_annotations.h",
],
hdrs = [
......@@ -126,6 +125,7 @@ cc_library(
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
":config",
":core_headers",
],
)
......
......@@ -105,7 +105,6 @@ absl_cc_library(
HDRS
"dynamic_annotations.h"
SRCS
"dynamic_annotations.cc"
"internal/dynamic_annotations.h"
COPTS
${ABSL_DEFAULT_COPTS}
......
// 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
//
// https://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.
#include <stdlib.h>
#include <string.h>
#include "absl/base/dynamic_annotations.h"
// Compiler-based ThreadSanitizer defines
// DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL = 1
// and provides its own definitions of the functions.
#ifndef DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL
# define DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL 0
#endif
#if DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0 && !defined(__native_client__)
extern "C" {
static int GetRunningOnValgrind(void) {
#ifdef RUNNING_ON_VALGRIND
if (RUNNING_ON_VALGRIND) return 1;
#endif
char *running_on_valgrind_str = getenv("RUNNING_ON_VALGRIND");
if (running_on_valgrind_str) {
return strcmp(running_on_valgrind_str, "0") != 0;
}
return 0;
}
// See the comments in dynamic_annotations.h
int RunningOnValgrind(void) {
static volatile int running_on_valgrind = -1;
int local_running_on_valgrind = running_on_valgrind;
// C doesn't have thread-safe initialization of statics, and we
// don't want to depend on pthread_once here, so hack it.
ANNOTATE_BENIGN_RACE(&running_on_valgrind, "safe hack");
if (local_running_on_valgrind == -1)
running_on_valgrind = local_running_on_valgrind = GetRunningOnValgrind();
return local_running_on_valgrind;
}
// See the comments in dynamic_annotations.h
double ValgrindSlowdown(void) {
// Same initialization hack as in RunningOnValgrind().
static volatile double slowdown = 0.0;
double local_slowdown = slowdown;
ANNOTATE_BENIGN_RACE(&slowdown, "safe hack");
if (RunningOnValgrind() == 0) {
return 1.0;
}
if (local_slowdown == 0.0) {
char *env = getenv("VALGRIND_SLOWDOWN");
slowdown = local_slowdown = env ? atof(env) : 50.0;
}
return local_slowdown;
}
} // extern "C"
#endif // DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0
......@@ -47,7 +47,11 @@
#include <stddef.h>
#include "absl/base/attributes.h"
#include "absl/base/config.h"
#ifdef __cplusplus
#include "absl/base/macros.h"
#endif
// TODO(rogeeff): Remove after the backward compatibility period.
#include "absl/base/internal/dynamic_annotations.h" // IWYU pragma: export
......@@ -90,7 +94,8 @@
// Read/write annotations are enabled in Annotalysis mode; disabled otherwise.
#define ABSL_INTERNAL_READS_WRITES_ANNOTATIONS_ENABLED \
ABSL_INTERNAL_ANNOTALYSIS_ENABLED
#endif
#endif // ABSL_HAVE_THREAD_SANITIZER
#ifdef __cplusplus
#define ABSL_INTERNAL_BEGIN_EXTERN_C extern "C" {
......@@ -152,7 +157,7 @@
ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateRWLockCreate)(__FILE__, __LINE__, lock)
// Report that a linker initialized lock has been created at address `lock`.
#ifdef THREAD_SANITIZER
#ifdef ABSL_HAVE_THREAD_SANITIZER
#define ABSL_ANNOTATE_RWLOCK_CREATE_STATIC(lock) \
ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateRWLockCreateStatic) \
(__FILE__, __LINE__, lock)
......@@ -417,41 +422,30 @@ ABSL_NAMESPACE_END
#endif
#ifdef __cplusplus
#ifdef ABSL_HAVE_THREAD_SANITIZER
ABSL_INTERNAL_BEGIN_EXTERN_C
// -------------------------------------------------------------------------
// Return non-zero value if running under valgrind.
//
// If "valgrind.h" is included into dynamic_annotations.cc,
// the regular valgrind mechanism will be used.
// See http://valgrind.org/docs/manual/manual-core-adv.html about
// RUNNING_ON_VALGRIND and other valgrind "client requests".
// The file "valgrind.h" may be obtained by doing
// svn co svn://svn.valgrind.org/valgrind/trunk/include
//
// If for some reason you can't use "valgrind.h" or want to fake valgrind,
// there are two ways to make this function return non-zero:
// - Use environment variable: export RUNNING_ON_VALGRIND=1
// - Make your tool intercept the function RunningOnValgrind() and
// change its return value.
//
int RunningOnValgrind(void);
// ValgrindSlowdown returns:
// * 1.0, if (RunningOnValgrind() == 0)
// * 50.0, if (RunningOnValgrind() != 0 && getenv("VALGRIND_SLOWDOWN") ==
// NULL)
// * atof(getenv("VALGRIND_SLOWDOWN")) otherwise
// This function can be used to scale timeout values:
// EXAMPLE:
// for (;;) {
// DoExpensiveBackgroundTask();
// SleepForSeconds(5 * ValgrindSlowdown());
// }
//
double ValgrindSlowdown(void);
int RunningOnValgrind();
double ValgrindSlowdown();
ABSL_INTERNAL_END_EXTERN_C
#else
namespace absl {
ABSL_NAMESPACE_BEGIN
namespace base_internal {
ABSL_DEPRECATED(
"Don't use this interface. It is misleading and is being deleted.")
ABSL_ATTRIBUTE_ALWAYS_INLINE inline int RunningOnValgrind() { return 0; }
ABSL_DEPRECATED(
"Don't use this interface. It is misleading and is being deleted.")
ABSL_ATTRIBUTE_ALWAYS_INLINE inline double ValgrindSlowdown() { return 1.0; }
} // namespace base_internal
ABSL_NAMESPACE_END
} // namespace absl
using absl::base_internal::RunningOnValgrind;
using absl::base_internal::ValgrindSlowdown;
#endif
#endif
// -------------------------------------------------------------------------
// Address sanitizer annotations
......
......@@ -39,6 +39,7 @@
#endif
#include <string.h>
#include <cassert>
#include <cstdint>
#include <cstdio>
......@@ -50,6 +51,7 @@
#include <vector>
#include "absl/base/call_once.h"
#include "absl/base/config.h"
#include "absl/base/internal/raw_logging.h"
#include "absl/base/internal/spinlock.h"
#include "absl/base/internal/unscaledcycleclock.h"
......@@ -420,6 +422,18 @@ pid_t GetTID() {
#endif
// GetCachedTID() caches the thread ID in thread-local storage (which is a
// userspace construct) to avoid unnecessary system calls. Without this caching,
// it can take roughly 98ns, while it takes roughly 1ns with this caching.
pid_t GetCachedTID() {
#if ABSL_HAVE_THREAD_LOCAL
static thread_local pid_t thread_id = GetTID();
return thread_id;
#else
return GetTID();
#endif // ABSL_HAVE_THREAD_LOCAL
}
} // namespace base_internal
ABSL_NAMESPACE_END
} // namespace absl
......@@ -30,6 +30,7 @@
#include <cstdint>
#include "absl/base/config.h"
#include "absl/base/port.h"
namespace absl {
......@@ -59,6 +60,13 @@ using pid_t = uint32_t;
#endif
pid_t GetTID();
// Like GetTID(), but caches the result in thread-local storage in order
// to avoid unnecessary system calls. Note that there are some cases where
// one must call through to GetTID directly, which is why this exists as a
// separate function. For example, GetCachedTID() is not safe to call in
// an asynchronous signal-handling context nor right after a call to fork().
pid_t GetCachedTID();
} // namespace base_internal
ABSL_NAMESPACE_END
} // namespace absl
......
......@@ -15,6 +15,7 @@
#include "absl/container/btree_test.h"
#include <cstdint>
#include <limits>
#include <map>
#include <memory>
#include <stdexcept>
......@@ -1344,6 +1345,12 @@ class BtreeNodePeer {
constexpr static size_t GetNumValuesPerNode() {
return btree_node<typename Set::params_type>::kNodeValues;
}
template <typename Set>
constexpr static size_t GetMaxFieldType() {
return std::numeric_limits<
typename btree_node<typename Set::params_type>::field_type>::max();
}
};
namespace {
......
......@@ -429,13 +429,6 @@ struct map_slot_policy {
std::move(src->value));
}
}
template <class Allocator>
static void move(Allocator* alloc, slot_type* first, slot_type* last,
slot_type* result) {
for (slot_type *src = first, *dest = result; src != last; ++src, ++dest)
move(alloc, src, dest);
}
};
} // namespace container_internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment