You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2018/04/29 19:36:16 UTC
[47/51] [partial] marmotta git commit: * Replace gtest with upstream
version,
including LICENSE header. * Include absl library for faster and safer string
operations. * Update license headers where needed. * Removed custom code
replaced by absl.
http://git-wip-us.apache.org/repos/asf/marmotta/blob/0eb556da/libraries/ostrich/backend/3rdparty/abseil/absl/base/call_once_test.cc
----------------------------------------------------------------------
diff --git a/libraries/ostrich/backend/3rdparty/abseil/absl/base/call_once_test.cc b/libraries/ostrich/backend/3rdparty/abseil/absl/base/call_once_test.cc
new file mode 100644
index 0000000..cd58ee1
--- /dev/null
+++ b/libraries/ostrich/backend/3rdparty/abseil/absl/base/call_once_test.cc
@@ -0,0 +1,102 @@
+// 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.
+
+#include "absl/base/call_once.h"
+
+#include <thread>
+#include <vector>
+
+#include "gtest/gtest.h"
+#include "absl/base/thread_annotations.h"
+#include "absl/synchronization/mutex.h"
+
+namespace absl {
+namespace {
+
+absl::once_flag once;
+Mutex counters_mu;
+
+int running_thread_count GUARDED_BY(counters_mu) = 0;
+int call_once_invoke_count GUARDED_BY(counters_mu) = 0;
+int call_once_finished_count GUARDED_BY(counters_mu) = 0;
+int call_once_return_count GUARDED_BY(counters_mu) = 0;
+bool done_blocking GUARDED_BY(counters_mu) = false;
+
+// Function to be called from absl::call_once. Waits for a notification.
+void WaitAndIncrement() {
+ counters_mu.Lock();
+ ++call_once_invoke_count;
+ counters_mu.Unlock();
+
+ counters_mu.LockWhen(Condition(&done_blocking));
+ ++call_once_finished_count;
+ counters_mu.Unlock();
+}
+
+void ThreadBody() {
+ counters_mu.Lock();
+ ++running_thread_count;
+ counters_mu.Unlock();
+
+ absl::call_once(once, WaitAndIncrement);
+
+ counters_mu.Lock();
+ ++call_once_return_count;
+ counters_mu.Unlock();
+}
+
+// Returns true if all threads are set up for the test.
+bool ThreadsAreSetup(void*) EXCLUSIVE_LOCKS_REQUIRED(counters_mu) {
+ // All ten threads must be running, and WaitAndIncrement should be blocked.
+ return running_thread_count == 10 && call_once_invoke_count == 1;
+}
+
+TEST(CallOnceTest, ExecutionCount) {
+ std::vector<std::thread> threads;
+
+ // Start 10 threads all calling call_once on the same once_flag.
+ for (int i = 0; i < 10; ++i) {
+ threads.emplace_back(ThreadBody);
+ }
+
+
+ // Wait until all ten threads have started, and WaitAndIncrement has been
+ // invoked.
+ counters_mu.LockWhen(Condition(ThreadsAreSetup, nullptr));
+
+ // WaitAndIncrement should have been invoked by exactly one call_once()
+ // instance. That thread should be blocking on a notification, and all other
+ // call_once instances should be blocking as well.
+ EXPECT_EQ(call_once_invoke_count, 1);
+ EXPECT_EQ(call_once_finished_count, 0);
+ EXPECT_EQ(call_once_return_count, 0);
+
+ // Allow WaitAndIncrement to finish executing. Once it does, the other
+ // call_once waiters will be unblocked.
+ done_blocking = true;
+ counters_mu.Unlock();
+
+ for (std::thread& thread : threads) {
+ thread.join();
+ }
+
+ counters_mu.Lock();
+ EXPECT_EQ(call_once_invoke_count, 1);
+ EXPECT_EQ(call_once_finished_count, 1);
+ EXPECT_EQ(call_once_return_count, 10);
+ counters_mu.Unlock();
+}
+
+} // namespace
+} // namespace absl
http://git-wip-us.apache.org/repos/asf/marmotta/blob/0eb556da/libraries/ostrich/backend/3rdparty/abseil/absl/base/casts.h
----------------------------------------------------------------------
diff --git a/libraries/ostrich/backend/3rdparty/abseil/absl/base/casts.h b/libraries/ostrich/backend/3rdparty/abseil/absl/base/casts.h
new file mode 100644
index 0000000..8bd5264
--- /dev/null
+++ b/libraries/ostrich/backend/3rdparty/abseil/absl/base/casts.h
@@ -0,0 +1,140 @@
+//
+// 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.
+//
+// -----------------------------------------------------------------------------
+// File: casts.h
+// -----------------------------------------------------------------------------
+//
+// This header file defines casting templates to fit use cases not covered by
+// the standard casts provided in the C++ standard. As with all cast operations,
+// use these with caution and only if alternatives do not exist.
+
+#ifndef ABSL_BASE_CASTS_H_
+#define ABSL_BASE_CASTS_H_
+
+#include <cstring>
+#include <type_traits>
+
+#include "absl/base/internal/identity.h"
+
+namespace absl {
+
+// implicit_cast()
+//
+// Performs an implicit conversion between types following the language
+// rules for implicit conversion; if an implicit conversion is otherwise
+// allowed by the language in the given context, this function performs such an
+// implicit conversion.
+//
+// Example:
+//
+// // If the context allows implicit conversion:
+// From from;
+// To to = from;
+//
+// // Such code can be replaced by:
+// implicit_cast<To>(from);
+//
+// An `implicit_cast()` may also be used to annotate numeric type conversions
+// that, although safe, may produce compiler warnings (such as `long` to `int`).
+// Additionally, an `implicit_cast()` is also useful within return statements to
+// indicate a specific implicit conversion is being undertaken.
+//
+// Example:
+//
+// return implicit_cast<double>(size_in_bytes) / capacity_;
+//
+// Annotating code with `implicit_cast()` allows you to explicitly select
+// particular overloads and template instantiations, while providing a safer
+// cast than `reinterpret_cast()` or `static_cast()`.
+//
+// Additionally, an `implicit_cast()` can be used to allow upcasting within a
+// type hierarchy where incorrect use of `static_cast()` could accidentally
+// allow downcasting.
+//
+// Finally, an `implicit_cast()` can be used to perform implicit conversions
+// from unrelated types that otherwise couldn't be implicitly cast directly;
+// C++ will normally only implicitly cast "one step" in such conversions.
+//
+// That is, if C is a type which can be implicitly converted to B, with B being
+// a type that can be implicitly converted to A, an `implicit_cast()` can be
+// used to convert C to B (which the compiler can then implicitly convert to A
+// using language rules).
+//
+// Example:
+//
+// // Assume an object C is convertible to B, which is implicitly convertible
+// // to A
+// A a = implicit_cast<B>(C);
+//
+// Such implicit cast chaining may be useful within template logic.
+template <typename To>
+inline To implicit_cast(typename absl::internal::identity_t<To> to) {
+ return to;
+}
+
+// bit_cast()
+//
+// Performs a bitwise cast on a type without changing the underlying bit
+// representation of that type's value. The two types must be of the same size
+// and both types must be trivially copyable. As with most casts, use with
+// caution. A `bit_cast()` might be needed when you need to temporarily treat a
+// type as some other type, such as in the following cases:
+//
+// * Serialization (casting temporarily to `char *` for those purposes is
+// always allowed by the C++ standard)
+// * Managing the individual bits of a type within mathematical operations
+// that are not normally accessible through that type
+// * Casting non-pointer types to pointer types (casting the other way is
+// allowed by `reinterpret_cast()` but round-trips cannot occur the other
+// way).
+//
+// Example:
+//
+// float f = 3.14159265358979;
+// int i = bit_cast<int32_t>(f);
+// // i = 0x40490fdb
+//
+// Casting non-pointer types to pointer types and then dereferencing them
+// traditionally produces undefined behavior.
+//
+// Example:
+//
+// // WRONG
+// float f = 3.14159265358979; // WRONG
+// int i = * reinterpret_cast<int*>(&f); // WRONG
+//
+// The address-casting method produces undefined behavior according to the ISO
+// C++ specification section [basic.lval]. Roughly, this section says: if an
+// object in memory has one type, and a program accesses it with a different
+// type, the result is undefined behavior for most values of "different type".
+//
+// Such casting results in type punning: holding an object in memory of one type
+// and reading its bits back using a different type. A `bit_cast()` avoids this
+// issue by implementing its casts using `memcpy()`, which avoids introducing
+// this undefined behavior.
+template <typename Dest, typename Source>
+inline Dest bit_cast(const Source& source) {
+ static_assert(sizeof(Dest) == sizeof(Source),
+ "Source and destination types should have equal sizes.");
+
+ Dest dest;
+ memcpy(&dest, &source, sizeof(dest));
+ return dest;
+}
+
+} // namespace absl
+
+#endif // ABSL_BASE_CASTS_H_
http://git-wip-us.apache.org/repos/asf/marmotta/blob/0eb556da/libraries/ostrich/backend/3rdparty/abseil/absl/base/config.h
----------------------------------------------------------------------
diff --git a/libraries/ostrich/backend/3rdparty/abseil/absl/base/config.h b/libraries/ostrich/backend/3rdparty/abseil/absl/base/config.h
new file mode 100644
index 0000000..2f5f159
--- /dev/null
+++ b/libraries/ostrich/backend/3rdparty/abseil/absl/base/config.h
@@ -0,0 +1,427 @@
+//
+// 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.
+//
+// -----------------------------------------------------------------------------
+// File: config.h
+// -----------------------------------------------------------------------------
+//
+// This header file defines a set of macros for checking the presence of
+// important compiler and platform features. Such macros can be used to
+// produce portable code by parameterizing compilation based on the presence or
+// lack of a given feature.
+//
+// We define a "feature" as some interface we wish to program to: for example,
+// a library function or system call. A value of `1` indicates support for
+// that feature; any other value indicates the feature support is undefined.
+//
+// Example:
+//
+// Suppose a programmer wants to write a program that uses the 'mmap()' system
+// call. The Abseil macro for that feature (`ABSL_HAVE_MMAP`) allows you to
+// selectively include the `mmap.h` header and bracket code using that feature
+// in the macro:
+//
+// #include "absl/base/config.h"
+//
+// #ifdef ABSL_HAVE_MMAP
+// #include "sys/mman.h"
+// #endif //ABSL_HAVE_MMAP
+//
+// ...
+// #ifdef ABSL_HAVE_MMAP
+// void *ptr = mmap(...);
+// ...
+// #endif // ABSL_HAVE_MMAP
+
+#ifndef ABSL_BASE_CONFIG_H_
+#define ABSL_BASE_CONFIG_H_
+
+// Included for the __GLIBC__ macro (or similar macros on other systems).
+#include <limits.h>
+
+#ifdef __cplusplus
+// Included for __GLIBCXX__, _LIBCPP_VERSION
+#include <cstddef>
+#endif // __cplusplus
+
+#if defined(__APPLE__)
+// Included for TARGET_OS_IPHONE, __IPHONE_OS_VERSION_MIN_REQUIRED,
+// __IPHONE_8_0.
+#include <Availability.h>
+#include <TargetConditionals.h>
+#endif
+
+#include "absl/base/policy_checks.h"
+
+// -----------------------------------------------------------------------------
+// Compiler Feature Checks
+// -----------------------------------------------------------------------------
+
+// ABSL_HAVE_BUILTIN()
+//
+// Checks whether the compiler supports a Clang Feature Checking Macro, and if
+// so, checks whether it supports the provided builtin function "x" where x
+// is one of the functions noted in
+// https://clang.llvm.org/docs/LanguageExtensions.html
+//
+// Note: Use this macro to avoid an extra level of #ifdef __has_builtin check.
+// http://releases.llvm.org/3.3/tools/clang/docs/LanguageExtensions.html
+#ifdef __has_builtin
+#define ABSL_HAVE_BUILTIN(x) __has_builtin(x)
+#else
+#define ABSL_HAVE_BUILTIN(x) 0
+#endif
+
+// ABSL_HAVE_TLS is defined to 1 when __thread should be supported.
+// We assume __thread is supported on Linux when compiled with Clang or compiled
+// against libstdc++ with _GLIBCXX_HAVE_TLS defined.
+#ifdef ABSL_HAVE_TLS
+#error ABSL_HAVE_TLS cannot be directly set
+#elif defined(__linux__) && (defined(__clang__) || defined(_GLIBCXX_HAVE_TLS))
+#define ABSL_HAVE_TLS 1
+#endif
+
+// ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
+//
+// Checks whether `std::is_trivially_destructible<T>` is supported.
+//
+// Notes: All supported compilers using libc++ support this feature, as does
+// gcc >= 4.8.1 using libstdc++, and Visual Studio.
+#ifdef ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
+#error ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE cannot be directly set
+#elif defined(_LIBCPP_VERSION) || \
+ (!defined(__clang__) && defined(__GNUC__) && defined(__GLIBCXX__) && \
+ (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))) || \
+ defined(_MSC_VER)
+#define ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 1
+#endif
+
+// ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE
+//
+// Checks whether `std::is_trivially_default_constructible<T>` and
+// `std::is_trivially_copy_constructible<T>` are supported.
+
+// ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE
+//
+// Checks whether `std::is_trivially_copy_assignable<T>` is supported.
+
+// Notes: Clang with libc++ supports these features, as does gcc >= 5.1 with
+// either libc++ or libstdc++, and Visual Studio.
+#if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE)
+#error ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE cannot be directly set
+#elif defined(ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE)
+#error ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE cannot directly set
+#elif (defined(__clang__) && defined(_LIBCPP_VERSION)) || \
+ (!defined(__clang__) && defined(__GNUC__) && \
+ (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && \
+ (defined(_LIBCPP_VERSION) || defined(__GLIBCXX__))) || \
+ defined(_MSC_VER)
+#define ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE 1
+#define ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 1
+#endif
+
+// ABSL_HAVE_THREAD_LOCAL
+//
+// Checks whether C++11's `thread_local` storage duration specifier is
+// supported.
+#ifdef ABSL_HAVE_THREAD_LOCAL
+#error ABSL_HAVE_THREAD_LOCAL cannot be directly set
+#elif defined(__APPLE__)
+// Notes: Xcode's clang did not support `thread_local` until version
+// 8, and even then not for all iOS < 9.0. Also, Xcode 9.3 started disallowing
+// `thread_local` for 32-bit iOS simulator targeting iOS 9.x.
+// `__has_feature` is only supported by Clang so it has be inside
+// `defined(__APPLE__)` check.
+#if __has_feature(cxx_thread_local)
+#define ABSL_HAVE_THREAD_LOCAL 1
+#endif
+#else // !defined(__APPLE__)
+#define ABSL_HAVE_THREAD_LOCAL 1
+#endif
+
+// There are platforms for which TLS should not be used even though the compiler
+// makes it seem like it's supported (Android NDK < r12b for example).
+// This is primarily because of linker problems and toolchain misconfiguration:
+// Abseil does not intend to support this indefinitely. Currently, the newest
+// toolchain that we intend to support that requires this behavior is the
+// r11 NDK - allowing for a 5 year support window on that means this option
+// is likely to be removed around June of 2021.
+// TLS isn't supported until NDK r12b per
+// https://developer.android.com/ndk/downloads/revision_history.html
+// Since NDK r16, `__NDK_MAJOR__` and `__NDK_MINOR__` are defined in
+// <android/ndk-version.h>. For NDK < r16, users should define these macros,
+// e.g. `-D__NDK_MAJOR__=11 -D__NKD_MINOR__=0` for NDK r11.
+#if defined(__ANDROID__) && defined(__clang__)
+#if __has_include(<android/ndk-version.h>)
+#include <android/ndk-version.h>
+#endif // __has_include(<android/ndk-version.h>)
+#if defined(__ANDROID__) && defined(__clang__) && defined(__NDK_MAJOR__) && \
+ defined(__NDK_MINOR__) && \
+ ((__NDK_MAJOR__ < 12) || ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1)))
+#undef ABSL_HAVE_TLS
+#undef ABSL_HAVE_THREAD_LOCAL
+#endif
+#endif // defined(__ANDROID__) && defined(__clang__)
+
+// ABSL_HAVE_INTRINSIC_INT128
+//
+// Checks whether the __int128 compiler extension for a 128-bit integral type is
+// supported.
+//
+// Note: __SIZEOF_INT128__ is defined by Clang and GCC when __int128 is
+// supported, but we avoid using it in certain cases:
+// * On Clang:
+// * Building using Clang for Windows, where the Clang runtime library has
+// 128-bit support only on LP64 architectures, but Windows is LLP64.
+// * Building for aarch64, where __int128 exists but has exhibits a sporadic
+// compiler crashing bug.
+// * On Nvidia's nvcc:
+// * nvcc also defines __GNUC__ and __SIZEOF_INT128__, but not all versions
+// actually support __int128.
+#ifdef ABSL_HAVE_INTRINSIC_INT128
+#error ABSL_HAVE_INTRINSIC_INT128 cannot be directly set
+#elif defined(__SIZEOF_INT128__)
+#if (defined(__clang__) && !defined(_WIN32) && !defined(__aarch64__)) || \
+ (defined(__CUDACC__) && __CUDACC_VER_MAJOR__ >= 9) || \
+ (defined(__GNUC__) && !defined(__clang__) && !defined(__CUDACC__))
+#define ABSL_HAVE_INTRINSIC_INT128 1
+#elif defined(__CUDACC__)
+// __CUDACC_VER__ is a full version number before CUDA 9, and is defined to a
+// std::string explaining that it has been removed starting with CUDA 9. We use
+// nested #ifs because there is no short-circuiting in the preprocessor.
+// NOTE: `__CUDACC__` could be undefined while `__CUDACC_VER__` is defined.
+#if __CUDACC_VER__ >= 70000
+#define ABSL_HAVE_INTRINSIC_INT128 1
+#endif // __CUDACC_VER__ >= 70000
+#endif // defined(__CUDACC__)
+#endif // ABSL_HAVE_INTRINSIC_INT128
+
+// ABSL_HAVE_EXCEPTIONS
+//
+// Checks whether the compiler both supports and enables exceptions. Many
+// compilers support a "no exceptions" mode that disables exceptions.
+//
+// Generally, when ABSL_HAVE_EXCEPTIONS is not defined:
+//
+// * Code using `throw` and `try` may not compile.
+// * The `noexcept` specifier will still compile and behave as normal.
+// * The `noexcept` operator may still return `false`.
+//
+// For further details, consult the compiler's documentation.
+#ifdef ABSL_HAVE_EXCEPTIONS
+#error ABSL_HAVE_EXCEPTIONS cannot be directly set.
+
+#elif defined(__clang__)
+// TODO(calabrese)
+// Switch to using __cpp_exceptions when we no longer support versions < 3.6.
+// For details on this check, see:
+// http://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html#the-exceptions-macro
+#if defined(__EXCEPTIONS) && __has_feature(cxx_exceptions)
+#define ABSL_HAVE_EXCEPTIONS 1
+#endif // defined(__EXCEPTIONS) && __has_feature(cxx_exceptions)
+
+// Handle remaining special cases and default to exceptions being supported.
+#elif !(defined(__GNUC__) && (__GNUC__ < 5) && !defined(__EXCEPTIONS)) && \
+ !(defined(__GNUC__) && (__GNUC__ >= 5) && !defined(__cpp_exceptions)) && \
+ !(defined(_MSC_VER) && !defined(_CPPUNWIND))
+#define ABSL_HAVE_EXCEPTIONS 1
+#endif
+
+// -----------------------------------------------------------------------------
+// Platform Feature Checks
+// -----------------------------------------------------------------------------
+
+// Currently supported operating systems and associated preprocessor
+// symbols:
+//
+// Linux and Linux-derived __linux__
+// Android __ANDROID__ (implies __linux__)
+// Linux (non-Android) __linux__ && !__ANDROID__
+// Darwin (Mac OS X and iOS) __APPLE__
+// Akaros (http://akaros.org) __ros__
+// Windows _WIN32
+// NaCL __native_client__
+// AsmJS __asmjs__
+// WebAssembly __wasm__
+// Fuchsia __Fuchsia__
+//
+// Note that since Android defines both __ANDROID__ and __linux__, one
+// may probe for either Linux or Android by simply testing for __linux__.
+
+// ABSL_HAVE_MMAP
+//
+// Checks whether the platform has an mmap(2) implementation as defined in
+// POSIX.1-2001.
+#ifdef ABSL_HAVE_MMAP
+#error ABSL_HAVE_MMAP cannot be directly set
+#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
+ defined(__ros__) || defined(__native_client__) || defined(__asmjs__) || \
+ defined(__wasm__) || defined(__Fuchsia__)
+#define ABSL_HAVE_MMAP 1
+#endif
+
+// ABSL_HAVE_PTHREAD_GETSCHEDPARAM
+//
+// Checks whether the platform implements the pthread_(get|set)schedparam(3)
+// functions as defined in POSIX.1-2001.
+#ifdef ABSL_HAVE_PTHREAD_GETSCHEDPARAM
+#error ABSL_HAVE_PTHREAD_GETSCHEDPARAM cannot be directly set
+#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
+ defined(__ros__)
+#define ABSL_HAVE_PTHREAD_GETSCHEDPARAM 1
+#endif
+
+// ABSL_HAVE_SCHED_YIELD
+//
+// Checks whether the platform implements sched_yield(2) as defined in
+// POSIX.1-2001.
+#ifdef ABSL_HAVE_SCHED_YIELD
+#error ABSL_HAVE_SCHED_YIELD cannot be directly set
+#elif defined(__linux__) || defined(__ros__) || defined(__native_client__)
+#define ABSL_HAVE_SCHED_YIELD 1
+#endif
+
+// ABSL_HAVE_SEMAPHORE_H
+//
+// Checks whether the platform supports the <semaphore.h> header and sem_open(3)
+// family of functions as standardized in POSIX.1-2001.
+//
+// Note: While Apple provides <semaphore.h> for both iOS and macOS, it is
+// explicitly deprecated and will cause build failures if enabled for those
+// platforms. We side-step the issue by not defining it here for Apple
+// platforms.
+#ifdef ABSL_HAVE_SEMAPHORE_H
+#error ABSL_HAVE_SEMAPHORE_H cannot be directly set
+#elif defined(__linux__) || defined(__ros__)
+#define ABSL_HAVE_SEMAPHORE_H 1
+#endif
+
+// ABSL_HAVE_ALARM
+//
+// Checks whether the platform supports the <signal.h> header and alarm(2)
+// function as standardized in POSIX.1-2001.
+#ifdef ABSL_HAVE_ALARM
+#error ABSL_HAVE_ALARM cannot be directly set
+#elif defined(__GOOGLE_GRTE_VERSION__)
+// feature tests for Google's GRTE
+#define ABSL_HAVE_ALARM 1
+#elif defined(__GLIBC__)
+// feature test for glibc
+#define ABSL_HAVE_ALARM 1
+#elif defined(_MSC_VER)
+// feature tests for Microsoft's library
+#elif defined(__native_client__)
+#else
+// other standard libraries
+#define ABSL_HAVE_ALARM 1
+#endif
+
+// ABSL_IS_LITTLE_ENDIAN
+// ABSL_IS_BIG_ENDIAN
+//
+// Checks the endianness of the platform.
+//
+// Notes: uses the built in endian macros provided by GCC (since 4.6) and
+// Clang (since 3.2); see
+// https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html.
+// Otherwise, if _WIN32, assume little endian. Otherwise, bail with an error.
+#if defined(ABSL_IS_BIG_ENDIAN)
+#error "ABSL_IS_BIG_ENDIAN cannot be directly set."
+#endif
+#if defined(ABSL_IS_LITTLE_ENDIAN)
+#error "ABSL_IS_LITTLE_ENDIAN cannot be directly set."
+#endif
+
+#if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
+ __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#define ABSL_IS_LITTLE_ENDIAN 1
+#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
+ __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#define ABSL_IS_BIG_ENDIAN 1
+#elif defined(_WIN32)
+#define ABSL_IS_LITTLE_ENDIAN 1
+#else
+#error "absl endian detection needs to be set up for your compiler"
+#endif
+
+// ABSL_HAVE_STD_ANY
+//
+// Checks whether C++17 std::any is available by checking whether <any> exists.
+#ifdef ABSL_HAVE_STD_ANY
+#error "ABSL_HAVE_STD_ANY cannot be directly set."
+#endif
+
+#ifdef __has_include
+#if __has_include(<any>) && __cplusplus >= 201703L
+#define ABSL_HAVE_STD_ANY 1
+#endif
+#endif
+
+// ABSL_HAVE_STD_OPTIONAL
+//
+// Checks whether C++17 std::optional is available.
+#ifdef ABSL_HAVE_STD_OPTIONAL
+#error "ABSL_HAVE_STD_OPTIONAL cannot be directly set."
+#endif
+
+#ifdef __has_include
+#if __has_include(<optional>) && __cplusplus >= 201703L
+#define ABSL_HAVE_STD_OPTIONAL 1
+#endif
+#endif
+
+// ABSL_HAVE_STD_VARIANT
+//
+// Checks whether C++17 std::variant is available.
+#ifdef ABSL_HAVE_STD_VARIANT
+#error "ABSL_HAVE_STD_VARIANT cannot be directly set."
+#endif
+
+#ifdef __has_include
+#if __has_include(<variant>) && __cplusplus >= 201703L
+#define ABSL_HAVE_STD_VARIANT 1
+#endif
+#endif
+
+// ABSL_HAVE_STD_STRING_VIEW
+//
+// Checks whether C++17 std::string_view is available.
+#ifdef ABSL_HAVE_STD_STRING_VIEW
+#error "ABSL_HAVE_STD_STRING_VIEW cannot be directly set."
+#endif
+
+#ifdef __has_include
+#if __has_include(<string_view>) && __cplusplus >= 201703L
+#define ABSL_HAVE_STD_STRING_VIEW 1
+#endif
+#endif
+
+// For MSVC, `__has_include` is supported in VS 2017 15.3, which is later than
+// the support for <optional>, <any>, <string_view>, <variant>. So we use
+// _MSC_VER to check whether we have VS 2017 RTM (when <optional>, <any>,
+// <string_view>, <variant> 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_VARIANT 1
+// #define ABSL_HAVE_STD_STRING_VIEW 1
+#endif
+
+#endif // ABSL_BASE_CONFIG_H_
http://git-wip-us.apache.org/repos/asf/marmotta/blob/0eb556da/libraries/ostrich/backend/3rdparty/abseil/absl/base/config_test.cc
----------------------------------------------------------------------
diff --git a/libraries/ostrich/backend/3rdparty/abseil/absl/base/config_test.cc b/libraries/ostrich/backend/3rdparty/abseil/absl/base/config_test.cc
new file mode 100644
index 0000000..c839712
--- /dev/null
+++ b/libraries/ostrich/backend/3rdparty/abseil/absl/base/config_test.cc
@@ -0,0 +1,60 @@
+// 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.
+
+#include "absl/base/config.h"
+
+#include <cstdint>
+
+#include "gtest/gtest.h"
+#include "absl/synchronization/internal/thread_pool.h"
+
+namespace {
+
+TEST(ConfigTest, Endianness) {
+ union {
+ uint32_t value;
+ uint8_t data[sizeof(uint32_t)];
+ } number;
+ number.data[0] = 0x00;
+ number.data[1] = 0x01;
+ number.data[2] = 0x02;
+ number.data[3] = 0x03;
+#if defined(ABSL_IS_LITTLE_ENDIAN) && defined(ABSL_IS_BIG_ENDIAN)
+#error Both ABSL_IS_LITTLE_ENDIAN and ABSL_IS_BIG_ENDIAN are defined
+#elif defined(ABSL_IS_LITTLE_ENDIAN)
+ EXPECT_EQ(UINT32_C(0x03020100), number.value);
+#elif defined(ABSL_IS_BIG_ENDIAN)
+ EXPECT_EQ(UINT32_C(0x00010203), number.value);
+#else
+#error Unknown endianness
+#endif
+}
+
+#if defined(ABSL_HAVE_THREAD_LOCAL)
+TEST(ConfigTest, ThreadLocal) {
+ static thread_local int mine_mine_mine = 16;
+ EXPECT_EQ(16, mine_mine_mine);
+ {
+ absl::synchronization_internal::ThreadPool pool(1);
+ pool.Schedule([&] {
+ EXPECT_EQ(16, mine_mine_mine);
+ mine_mine_mine = 32;
+ EXPECT_EQ(32, mine_mine_mine);
+ });
+ }
+ EXPECT_EQ(16, mine_mine_mine);
+}
+#endif
+
+} // namespace
http://git-wip-us.apache.org/repos/asf/marmotta/blob/0eb556da/libraries/ostrich/backend/3rdparty/abseil/absl/base/dynamic_annotations.cc
----------------------------------------------------------------------
diff --git a/libraries/ostrich/backend/3rdparty/abseil/absl/base/dynamic_annotations.cc b/libraries/ostrich/backend/3rdparty/abseil/absl/base/dynamic_annotations.cc
new file mode 100644
index 0000000..08c27e5
--- /dev/null
+++ b/libraries/ostrich/backend/3rdparty/abseil/absl/base/dynamic_annotations.cc
@@ -0,0 +1,129 @@
+// 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.
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "absl/base/dynamic_annotations.h"
+
+#ifndef __has_feature
+#define __has_feature(x) 0
+#endif
+
+/* 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
+
+/* Each function is empty and called (via a macro) only in debug mode.
+ The arguments are captured by dynamic tools at runtime. */
+
+#if DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0 && !defined(__native_client__)
+
+#if __has_feature(memory_sanitizer)
+#include <sanitizer/msan_interface.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void AnnotateRWLockCreate(const char *, int,
+ const volatile void *){}
+void AnnotateRWLockDestroy(const char *, int,
+ const volatile void *){}
+void AnnotateRWLockAcquired(const char *, int,
+ const volatile void *, long){}
+void AnnotateRWLockReleased(const char *, int,
+ const volatile void *, long){}
+void AnnotateBenignRace(const char *, int,
+ const volatile void *,
+ const char *){}
+void AnnotateBenignRaceSized(const char *, int,
+ const volatile void *,
+ size_t,
+ const char *) {}
+void AnnotateThreadName(const char *, int,
+ const char *){}
+void AnnotateIgnoreReadsBegin(const char *, int){}
+void AnnotateIgnoreReadsEnd(const char *, int){}
+void AnnotateIgnoreWritesBegin(const char *, int){}
+void AnnotateIgnoreWritesEnd(const char *, int){}
+void AnnotateEnableRaceDetection(const char *, int, int){}
+void AnnotateMemoryIsInitialized(const char *, int,
+ const volatile void *mem, size_t size) {
+#if __has_feature(memory_sanitizer)
+ __msan_unpoison(mem, size);
+#else
+ (void)mem;
+ (void)size;
+#endif
+}
+
+void AnnotateMemoryIsUninitialized(const char *, int,
+ const volatile void *mem, size_t size) {
+#if __has_feature(memory_sanitizer)
+ __msan_allocated_memory(mem, size);
+#else
+ (void)mem;
+ (void)size;
+#endif
+}
+
+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;
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+#endif /* DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0 */
http://git-wip-us.apache.org/repos/asf/marmotta/blob/0eb556da/libraries/ostrich/backend/3rdparty/abseil/absl/base/dynamic_annotations.h
----------------------------------------------------------------------
diff --git a/libraries/ostrich/backend/3rdparty/abseil/absl/base/dynamic_annotations.h b/libraries/ostrich/backend/3rdparty/abseil/absl/base/dynamic_annotations.h
new file mode 100644
index 0000000..3b6d6ef
--- /dev/null
+++ b/libraries/ostrich/backend/3rdparty/abseil/absl/base/dynamic_annotations.h
@@ -0,0 +1,409 @@
+/*
+ * 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 defines dynamic annotations for use with dynamic analysis
+ tool such as valgrind, PIN, etc.
+
+ Dynamic annotation is a source code annotation that affects
+ the generated code (that is, the annotation is not a comment).
+ Each such annotation is attached to a particular
+ instruction and/or to a particular object (address) in the program.
+
+ The annotations that should be used by users are macros in all upper-case
+ (e.g., ANNOTATE_THREAD_NAME).
+
+ Actual implementation of these macros may differ depending on the
+ dynamic analysis tool being used.
+
+ This file supports the following configurations:
+ - Dynamic Annotations enabled (with static thread-safety warnings disabled).
+ In this case, macros expand to functions implemented by Thread Sanitizer,
+ when building with TSan. When not provided an external implementation,
+ dynamic_annotations.cc provides no-op implementations.
+
+ - Static Clang thread-safety warnings enabled.
+ When building with a Clang compiler that supports thread-safety warnings,
+ a subset of annotations can be statically-checked at compile-time. We
+ expand these macros to static-inline functions that can be analyzed for
+ thread-safety, but afterwards elided when building the final binary.
+
+ - All annotations are disabled.
+ If neither Dynamic Annotations nor Clang thread-safety warnings are
+ enabled, then all annotation-macros expand to empty. */
+
+#ifndef ABSL_BASE_DYNAMIC_ANNOTATIONS_H_
+#define ABSL_BASE_DYNAMIC_ANNOTATIONS_H_
+
+#ifndef DYNAMIC_ANNOTATIONS_ENABLED
+# define DYNAMIC_ANNOTATIONS_ENABLED 0
+#endif
+
+#if defined(__native_client__)
+ #include "nacl/dynamic_annotations.h"
+
+ // Stub out the macros missing from the NaCl version.
+ #ifndef ANNOTATE_CONTIGUOUS_CONTAINER
+ #define ANNOTATE_CONTIGUOUS_CONTAINER(beg, end, old_mid, new_mid)
+ #endif
+ #ifndef ANNOTATE_RWLOCK_CREATE_STATIC
+ #define ANNOTATE_RWLOCK_CREATE_STATIC(lock)
+ #endif
+ #ifndef ADDRESS_SANITIZER_REDZONE
+ #define ADDRESS_SANITIZER_REDZONE(name)
+ #endif
+ #ifndef ANNOTATE_MEMORY_IS_UNINITIALIZED
+ #define ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size)
+ #endif
+
+#else /* !__native_client__ */
+
+#if DYNAMIC_ANNOTATIONS_ENABLED != 0
+
+ /* -------------------------------------------------------------
+ Annotations that suppress errors. It is usually better to express the
+ program's synchronization using the other annotations, but these can
+ be used when all else fails. */
+
+ /* Report that we may have a benign race at "pointer", with size
+ "sizeof(*(pointer))". "pointer" must be a non-void* pointer. Insert at the
+ point where "pointer" has been allocated, preferably close to the point
+ where the race happens. See also ANNOTATE_BENIGN_RACE_STATIC. */
+ #define ANNOTATE_BENIGN_RACE(pointer, description) \
+ AnnotateBenignRaceSized(__FILE__, __LINE__, pointer, \
+ sizeof(*(pointer)), description)
+
+ /* Same as ANNOTATE_BENIGN_RACE(address, description), but applies to
+ the memory range [address, address+size). */
+ #define ANNOTATE_BENIGN_RACE_SIZED(address, size, description) \
+ AnnotateBenignRaceSized(__FILE__, __LINE__, address, size, description)
+
+ /* Enable (enable!=0) or disable (enable==0) race detection for all threads.
+ This annotation could be useful if you want to skip expensive race analysis
+ during some period of program execution, e.g. during initialization. */
+ #define ANNOTATE_ENABLE_RACE_DETECTION(enable) \
+ AnnotateEnableRaceDetection(__FILE__, __LINE__, enable)
+
+ /* -------------------------------------------------------------
+ Annotations useful for debugging. */
+
+ /* Report the current thread name to a race detector. */
+ #define ANNOTATE_THREAD_NAME(name) \
+ AnnotateThreadName(__FILE__, __LINE__, name)
+
+ /* -------------------------------------------------------------
+ Annotations useful when implementing locks. They are not
+ normally needed by modules that merely use locks.
+ The "lock" argument is a pointer to the lock object. */
+
+ /* Report that a lock has been created at address "lock". */
+ #define ANNOTATE_RWLOCK_CREATE(lock) \
+ AnnotateRWLockCreate(__FILE__, __LINE__, lock)
+
+ /* Report that a linker initialized lock has been created at address "lock".
+ */
+#ifdef THREAD_SANITIZER
+ #define ANNOTATE_RWLOCK_CREATE_STATIC(lock) \
+ AnnotateRWLockCreateStatic(__FILE__, __LINE__, lock)
+#else
+ #define ANNOTATE_RWLOCK_CREATE_STATIC(lock) ANNOTATE_RWLOCK_CREATE(lock)
+#endif
+
+ /* Report that the lock at address "lock" is about to be destroyed. */
+ #define ANNOTATE_RWLOCK_DESTROY(lock) \
+ AnnotateRWLockDestroy(__FILE__, __LINE__, lock)
+
+ /* Report that the lock at address "lock" has been acquired.
+ is_w=1 for writer lock, is_w=0 for reader lock. */
+ #define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) \
+ AnnotateRWLockAcquired(__FILE__, __LINE__, lock, is_w)
+
+ /* Report that the lock at address "lock" is about to be released. */
+ #define ANNOTATE_RWLOCK_RELEASED(lock, is_w) \
+ AnnotateRWLockReleased(__FILE__, __LINE__, lock, is_w)
+
+#else /* DYNAMIC_ANNOTATIONS_ENABLED == 0 */
+
+ #define ANNOTATE_RWLOCK_CREATE(lock) /* empty */
+ #define ANNOTATE_RWLOCK_CREATE_STATIC(lock) /* empty */
+ #define ANNOTATE_RWLOCK_DESTROY(lock) /* empty */
+ #define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) /* empty */
+ #define ANNOTATE_RWLOCK_RELEASED(lock, is_w) /* empty */
+ #define ANNOTATE_BENIGN_RACE(address, description) /* empty */
+ #define ANNOTATE_BENIGN_RACE_SIZED(address, size, description) /* empty */
+ #define ANNOTATE_THREAD_NAME(name) /* empty */
+ #define ANNOTATE_ENABLE_RACE_DETECTION(enable) /* empty */
+
+#endif /* DYNAMIC_ANNOTATIONS_ENABLED */
+
+/* These annotations are also made available to LLVM's Memory Sanitizer */
+#if DYNAMIC_ANNOTATIONS_ENABLED == 1 || defined(MEMORY_SANITIZER)
+ #define ANNOTATE_MEMORY_IS_INITIALIZED(address, size) \
+ AnnotateMemoryIsInitialized(__FILE__, __LINE__, address, size)
+
+ #define ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size) \
+ AnnotateMemoryIsUninitialized(__FILE__, __LINE__, address, size)
+#else
+ #define ANNOTATE_MEMORY_IS_INITIALIZED(address, size) /* empty */
+ #define ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size) /* empty */
+#endif /* DYNAMIC_ANNOTATIONS_ENABLED || MEMORY_SANITIZER */
+/* TODO(delesley) -- Replace __CLANG_SUPPORT_DYN_ANNOTATION__ with the
+ appropriate feature ID. */
+#if defined(__clang__) && (!defined(SWIG)) \
+ && defined(__CLANG_SUPPORT_DYN_ANNOTATION__)
+
+ #if DYNAMIC_ANNOTATIONS_ENABLED == 0
+ #define ANNOTALYSIS_ENABLED
+ #endif
+
+ /* When running in opt-mode, GCC will issue a warning, if these attributes are
+ compiled. Only include them when compiling using Clang. */
+ #define ATTRIBUTE_IGNORE_READS_BEGIN \
+ __attribute((exclusive_lock_function("*")))
+ #define ATTRIBUTE_IGNORE_READS_END \
+ __attribute((unlock_function("*")))
+#else
+ #define ATTRIBUTE_IGNORE_READS_BEGIN /* empty */
+ #define ATTRIBUTE_IGNORE_READS_END /* empty */
+#endif /* defined(__clang__) && ... */
+
+#if (DYNAMIC_ANNOTATIONS_ENABLED != 0) || defined(ANNOTALYSIS_ENABLED)
+ #define ANNOTATIONS_ENABLED
+#endif
+
+#if (DYNAMIC_ANNOTATIONS_ENABLED != 0)
+
+ /* Request the analysis tool to ignore all reads in the current thread
+ until ANNOTATE_IGNORE_READS_END is called.
+ Useful to ignore intentional racey reads, while still checking
+ other reads and all writes.
+ See also ANNOTATE_UNPROTECTED_READ. */
+ #define ANNOTATE_IGNORE_READS_BEGIN() \
+ AnnotateIgnoreReadsBegin(__FILE__, __LINE__)
+
+ /* Stop ignoring reads. */
+ #define ANNOTATE_IGNORE_READS_END() \
+ AnnotateIgnoreReadsEnd(__FILE__, __LINE__)
+
+ /* Similar to ANNOTATE_IGNORE_READS_BEGIN, but ignore writes instead. */
+ #define ANNOTATE_IGNORE_WRITES_BEGIN() \
+ AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
+
+ /* Stop ignoring writes. */
+ #define ANNOTATE_IGNORE_WRITES_END() \
+ AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
+
+/* Clang provides limited support for static thread-safety analysis
+ through a feature called Annotalysis. We configure macro-definitions
+ according to whether Annotalysis support is available. */
+#elif defined(ANNOTALYSIS_ENABLED)
+
+ #define ANNOTATE_IGNORE_READS_BEGIN() \
+ StaticAnnotateIgnoreReadsBegin(__FILE__, __LINE__)
+
+ #define ANNOTATE_IGNORE_READS_END() \
+ StaticAnnotateIgnoreReadsEnd(__FILE__, __LINE__)
+
+ #define ANNOTATE_IGNORE_WRITES_BEGIN() \
+ StaticAnnotateIgnoreWritesBegin(__FILE__, __LINE__)
+
+ #define ANNOTATE_IGNORE_WRITES_END() \
+ StaticAnnotateIgnoreWritesEnd(__FILE__, __LINE__)
+
+#else
+ #define ANNOTATE_IGNORE_READS_BEGIN() /* empty */
+ #define ANNOTATE_IGNORE_READS_END() /* empty */
+ #define ANNOTATE_IGNORE_WRITES_BEGIN() /* empty */
+ #define ANNOTATE_IGNORE_WRITES_END() /* empty */
+#endif
+
+/* Implement the ANNOTATE_IGNORE_READS_AND_WRITES_* annotations using the more
+ primitive annotations defined above. */
+#if defined(ANNOTATIONS_ENABLED)
+
+ /* Start ignoring all memory accesses (both reads and writes). */
+ #define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \
+ do { \
+ ANNOTATE_IGNORE_READS_BEGIN(); \
+ ANNOTATE_IGNORE_WRITES_BEGIN(); \
+ }while (0)
+
+ /* Stop ignoring both reads and writes. */
+ #define ANNOTATE_IGNORE_READS_AND_WRITES_END() \
+ do { \
+ ANNOTATE_IGNORE_WRITES_END(); \
+ ANNOTATE_IGNORE_READS_END(); \
+ }while (0)
+
+#else
+ #define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() /* empty */
+ #define ANNOTATE_IGNORE_READS_AND_WRITES_END() /* empty */
+#endif
+
+/* Use the macros above rather than using these functions directly. */
+#include <stddef.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+void AnnotateRWLockCreate(const char *file, int line,
+ const volatile void *lock);
+void AnnotateRWLockCreateStatic(const char *file, int line,
+ const volatile void *lock);
+void AnnotateRWLockDestroy(const char *file, int line,
+ const volatile void *lock);
+void AnnotateRWLockAcquired(const char *file, int line,
+ const volatile void *lock, long is_w); /* NOLINT */
+void AnnotateRWLockReleased(const char *file, int line,
+ const volatile void *lock, long is_w); /* NOLINT */
+void AnnotateBenignRace(const char *file, int line,
+ const volatile void *address,
+ const char *description);
+void AnnotateBenignRaceSized(const char *file, int line,
+ const volatile void *address,
+ size_t size,
+ const char *description);
+void AnnotateThreadName(const char *file, int line,
+ const char *name);
+void AnnotateEnableRaceDetection(const char *file, int line, int enable);
+void AnnotateMemoryIsInitialized(const char *file, int line,
+ const volatile void *mem, size_t size);
+void AnnotateMemoryIsUninitialized(const char *file, int line,
+ const volatile void *mem, size_t size);
+
+/* Annotations expand to these functions, when Dynamic Annotations are enabled.
+ These functions are either implemented as no-op calls, if no Sanitizer is
+ attached, or provided with externally-linked implementations by a library
+ like ThreadSanitizer. */
+void AnnotateIgnoreReadsBegin(const char *file, int line)
+ ATTRIBUTE_IGNORE_READS_BEGIN;
+void AnnotateIgnoreReadsEnd(const char *file, int line)
+ ATTRIBUTE_IGNORE_READS_END;
+void AnnotateIgnoreWritesBegin(const char *file, int line);
+void AnnotateIgnoreWritesEnd(const char *file, int line);
+
+#if defined(ANNOTALYSIS_ENABLED)
+/* When Annotalysis is enabled without Dynamic Annotations, the use of
+ static-inline functions allows the annotations to be read at compile-time,
+ while still letting the compiler elide the functions from the final build.
+
+ TODO(delesley) -- The exclusive lock here ignores writes as well, but
+ allows IGNORE_READS_AND_WRITES to work properly. */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+static inline void StaticAnnotateIgnoreReadsBegin(const char *file, int line)
+ ATTRIBUTE_IGNORE_READS_BEGIN { (void)file; (void)line; }
+static inline void StaticAnnotateIgnoreReadsEnd(const char *file, int line)
+ ATTRIBUTE_IGNORE_READS_END { (void)file; (void)line; }
+static inline void StaticAnnotateIgnoreWritesBegin(
+ const char *file, int line) { (void)file; (void)line; }
+static inline void StaticAnnotateIgnoreWritesEnd(
+ const char *file, int line) { (void)file; (void)line; }
+#pragma GCC diagnostic pop
+#endif
+
+/* 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);
+
+#ifdef __cplusplus
+}
+#endif
+
+/* ANNOTATE_UNPROTECTED_READ is the preferred way to annotate racey reads.
+
+ Instead of doing
+ ANNOTATE_IGNORE_READS_BEGIN();
+ ... = x;
+ ANNOTATE_IGNORE_READS_END();
+ one can use
+ ... = ANNOTATE_UNPROTECTED_READ(x); */
+#if defined(__cplusplus) && defined(ANNOTATIONS_ENABLED)
+template <typename T>
+inline T ANNOTATE_UNPROTECTED_READ(const volatile T &x) { /* NOLINT */
+ ANNOTATE_IGNORE_READS_BEGIN();
+ T res = x;
+ ANNOTATE_IGNORE_READS_END();
+ return res;
+ }
+#else
+ #define ANNOTATE_UNPROTECTED_READ(x) (x)
+#endif
+
+#if DYNAMIC_ANNOTATIONS_ENABLED != 0 && defined(__cplusplus)
+ /* Apply ANNOTATE_BENIGN_RACE_SIZED to a static variable. */
+ #define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \
+ namespace { \
+ class static_var ## _annotator { \
+ public: \
+ static_var ## _annotator() { \
+ ANNOTATE_BENIGN_RACE_SIZED(&static_var, \
+ sizeof(static_var), \
+ # static_var ": " description); \
+ } \
+ }; \
+ static static_var ## _annotator the ## static_var ## _annotator;\
+ } // namespace
+#else /* DYNAMIC_ANNOTATIONS_ENABLED == 0 */
+ #define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) /* empty */
+#endif /* DYNAMIC_ANNOTATIONS_ENABLED */
+
+#ifdef ADDRESS_SANITIZER
+/* Describe the current state of a contiguous container such as e.g.
+ * std::vector or std::string. For more details see
+ * sanitizer/common_interface_defs.h, which is provided by the compiler. */
+#include <sanitizer/common_interface_defs.h>
+#define ANNOTATE_CONTIGUOUS_CONTAINER(beg, end, old_mid, new_mid) \
+ __sanitizer_annotate_contiguous_container(beg, end, old_mid, new_mid)
+#define ADDRESS_SANITIZER_REDZONE(name) \
+ struct { char x[8] __attribute__ ((aligned (8))); } name
+#else
+#define ANNOTATE_CONTIGUOUS_CONTAINER(beg, end, old_mid, new_mid)
+#define ADDRESS_SANITIZER_REDZONE(name)
+#endif // ADDRESS_SANITIZER
+
+/* Undefine the macros intended only in this file. */
+#undef ANNOTALYSIS_ENABLED
+#undef ANNOTATIONS_ENABLED
+#undef ATTRIBUTE_IGNORE_READS_BEGIN
+#undef ATTRIBUTE_IGNORE_READS_END
+
+#endif /* !__native_client__ */
+
+#endif /* ABSL_BASE_DYNAMIC_ANNOTATIONS_H_ */
http://git-wip-us.apache.org/repos/asf/marmotta/blob/0eb556da/libraries/ostrich/backend/3rdparty/abseil/absl/base/exception_safety_testing_test.cc
----------------------------------------------------------------------
diff --git a/libraries/ostrich/backend/3rdparty/abseil/absl/base/exception_safety_testing_test.cc b/libraries/ostrich/backend/3rdparty/abseil/absl/base/exception_safety_testing_test.cc
new file mode 100644
index 0000000..ab029e1
--- /dev/null
+++ b/libraries/ostrich/backend/3rdparty/abseil/absl/base/exception_safety_testing_test.cc
@@ -0,0 +1,842 @@
+// 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.
+
+#include "absl/base/internal/exception_safety_testing.h"
+
+#include <cstddef>
+#include <exception>
+#include <iostream>
+#include <list>
+#include <type_traits>
+#include <vector>
+
+#include "gtest/gtest-spi.h"
+#include "gtest/gtest.h"
+#include "absl/memory/memory.h"
+
+namespace absl {
+namespace {
+using ::absl::exceptions_internal::SetCountdown;
+using ::absl::exceptions_internal::TestException;
+using ::absl::exceptions_internal::UnsetCountdown;
+
+// EXPECT_NO_THROW can't inspect the thrown inspection in general.
+template <typename F>
+void ExpectNoThrow(const F& f) {
+ try {
+ f();
+ } catch (TestException e) {
+ ADD_FAILURE() << "Unexpected exception thrown from " << e.what();
+ }
+}
+
+TEST(ThrowingValueTest, Throws) {
+ SetCountdown();
+ EXPECT_THROW(ThrowingValue<> bomb, TestException);
+
+ // It's not guaranteed that every operator only throws *once*. The default
+ // ctor only throws once, though, so use it to make sure we only throw when
+ // the countdown hits 0
+ SetCountdown(2);
+ ExpectNoThrow([]() { ThrowingValue<> bomb; });
+ ExpectNoThrow([]() { ThrowingValue<> bomb; });
+ EXPECT_THROW(ThrowingValue<> bomb, TestException);
+
+ UnsetCountdown();
+}
+
+// Tests that an operation throws when the countdown is at 0, doesn't throw when
+// the countdown doesn't hit 0, and doesn't modify the state of the
+// ThrowingValue if it throws
+template <typename F>
+void TestOp(const F& f) {
+ ExpectNoThrow(f);
+
+ SetCountdown();
+ EXPECT_THROW(f(), TestException);
+ UnsetCountdown();
+}
+
+TEST(ThrowingValueTest, ThrowingCtors) {
+ ThrowingValue<> bomb;
+
+ TestOp([]() { ThrowingValue<> bomb(1); });
+ TestOp([&]() { ThrowingValue<> bomb1 = bomb; });
+ TestOp([&]() { ThrowingValue<> bomb1 = std::move(bomb); });
+}
+
+TEST(ThrowingValueTest, ThrowingAssignment) {
+ ThrowingValue<> bomb, bomb1;
+
+ TestOp([&]() { bomb = bomb1; });
+ TestOp([&]() { bomb = std::move(bomb1); });
+}
+
+TEST(ThrowingValueTest, ThrowingComparisons) {
+ ThrowingValue<> bomb1, bomb2;
+ TestOp([&]() { return bomb1 == bomb2; });
+ TestOp([&]() { return bomb1 != bomb2; });
+ TestOp([&]() { return bomb1 < bomb2; });
+ TestOp([&]() { return bomb1 <= bomb2; });
+ TestOp([&]() { return bomb1 > bomb2; });
+ TestOp([&]() { return bomb1 >= bomb2; });
+}
+
+TEST(ThrowingValueTest, ThrowingArithmeticOps) {
+ ThrowingValue<> bomb1(1), bomb2(2);
+
+ TestOp([&bomb1]() { +bomb1; });
+ TestOp([&bomb1]() { -bomb1; });
+ TestOp([&bomb1]() { ++bomb1; });
+ TestOp([&bomb1]() { bomb1++; });
+ TestOp([&bomb1]() { --bomb1; });
+ TestOp([&bomb1]() { bomb1--; });
+
+ TestOp([&]() { bomb1 + bomb2; });
+ TestOp([&]() { bomb1 - bomb2; });
+ TestOp([&]() { bomb1* bomb2; });
+ TestOp([&]() { bomb1 / bomb2; });
+ TestOp([&]() { bomb1 << 1; });
+ TestOp([&]() { bomb1 >> 1; });
+}
+
+TEST(ThrowingValueTest, ThrowingLogicalOps) {
+ ThrowingValue<> bomb1, bomb2;
+
+ TestOp([&bomb1]() { !bomb1; });
+ TestOp([&]() { bomb1&& bomb2; });
+ TestOp([&]() { bomb1 || bomb2; });
+}
+
+TEST(ThrowingValueTest, ThrowingBitwiseOps) {
+ ThrowingValue<> bomb1, bomb2;
+
+ TestOp([&bomb1]() { ~bomb1; });
+ TestOp([&]() { bomb1& bomb2; });
+ TestOp([&]() { bomb1 | bomb2; });
+ TestOp([&]() { bomb1 ^ bomb2; });
+}
+
+TEST(ThrowingValueTest, ThrowingCompoundAssignmentOps) {
+ ThrowingValue<> bomb1(1), bomb2(2);
+
+ TestOp([&]() { bomb1 += bomb2; });
+ TestOp([&]() { bomb1 -= bomb2; });
+ TestOp([&]() { bomb1 *= bomb2; });
+ TestOp([&]() { bomb1 /= bomb2; });
+ TestOp([&]() { bomb1 %= bomb2; });
+ TestOp([&]() { bomb1 &= bomb2; });
+ TestOp([&]() { bomb1 |= bomb2; });
+ TestOp([&]() { bomb1 ^= bomb2; });
+ TestOp([&]() { bomb1 *= bomb2; });
+}
+
+TEST(ThrowingValueTest, ThrowingStreamOps) {
+ ThrowingValue<> bomb;
+
+ TestOp([&]() { std::cin >> bomb; });
+ TestOp([&]() { std::cout << bomb; });
+}
+
+template <typename F>
+void TestAllocatingOp(const F& f) {
+ ExpectNoThrow(f);
+
+ SetCountdown();
+ EXPECT_THROW(f(), exceptions_internal::TestBadAllocException);
+ UnsetCountdown();
+}
+
+TEST(ThrowingValueTest, ThrowingAllocatingOps) {
+ // make_unique calls unqualified operator new, so these exercise the
+ // ThrowingValue overloads.
+ TestAllocatingOp([]() { return absl::make_unique<ThrowingValue<>>(1); });
+ TestAllocatingOp([]() { return absl::make_unique<ThrowingValue<>[]>(2); });
+}
+
+TEST(ThrowingValueTest, NonThrowingMoveCtor) {
+ ThrowingValue<NoThrow::kMoveCtor> nothrow_ctor;
+
+ SetCountdown();
+ ExpectNoThrow([¬hrow_ctor]() {
+ ThrowingValue<NoThrow::kMoveCtor> nothrow1 = std::move(nothrow_ctor);
+ });
+ UnsetCountdown();
+}
+
+TEST(ThrowingValueTest, NonThrowingMoveAssign) {
+ ThrowingValue<NoThrow::kMoveAssign> nothrow_assign1, nothrow_assign2;
+
+ SetCountdown();
+ ExpectNoThrow([¬hrow_assign1, ¬hrow_assign2]() {
+ nothrow_assign1 = std::move(nothrow_assign2);
+ });
+ UnsetCountdown();
+}
+
+TEST(ThrowingValueTest, ThrowingSwap) {
+ ThrowingValue<> bomb1, bomb2;
+ TestOp([&]() { std::swap(bomb1, bomb2); });
+
+ ThrowingValue<NoThrow::kMoveCtor> bomb3, bomb4;
+ TestOp([&]() { std::swap(bomb3, bomb4); });
+
+ ThrowingValue<NoThrow::kMoveAssign> bomb5, bomb6;
+ TestOp([&]() { std::swap(bomb5, bomb6); });
+}
+
+TEST(ThrowingValueTest, NonThrowingSwap) {
+ ThrowingValue<NoThrow::kMoveAssign | NoThrow::kMoveCtor> bomb1, bomb2;
+ ExpectNoThrow([&]() { std::swap(bomb1, bomb2); });
+}
+
+TEST(ThrowingValueTest, NonThrowingAllocation) {
+ ThrowingValue<NoThrow::kAllocation>* allocated;
+ ThrowingValue<NoThrow::kAllocation>* array;
+
+ ExpectNoThrow([&allocated]() {
+ allocated = new ThrowingValue<NoThrow::kAllocation>(1);
+ delete allocated;
+ });
+ ExpectNoThrow([&array]() {
+ array = new ThrowingValue<NoThrow::kAllocation>[2];
+ delete[] array;
+ });
+}
+
+TEST(ThrowingValueTest, NonThrowingDelete) {
+ auto* allocated = new ThrowingValue<>(1);
+ auto* array = new ThrowingValue<>[2];
+
+ SetCountdown();
+ ExpectNoThrow([allocated]() { delete allocated; });
+ SetCountdown();
+ ExpectNoThrow([array]() { delete[] array; });
+
+ UnsetCountdown();
+}
+
+using Storage =
+ absl::aligned_storage_t<sizeof(ThrowingValue<>), alignof(ThrowingValue<>)>;
+
+TEST(ThrowingValueTest, NonThrowingPlacementDelete) {
+ constexpr int kArrayLen = 2;
+ // We intentionally create extra space to store the tag allocated by placement
+ // new[].
+ constexpr int kStorageLen = 4;
+
+ Storage buf;
+ Storage array_buf[kStorageLen];
+ auto* placed = new (&buf) ThrowingValue<>(1);
+ auto placed_array = new (&array_buf) ThrowingValue<>[kArrayLen];
+
+ SetCountdown();
+ ExpectNoThrow([placed, &buf]() {
+ placed->~ThrowingValue<>();
+ ThrowingValue<>::operator delete(placed, &buf);
+ });
+
+ SetCountdown();
+ ExpectNoThrow([&, placed_array]() {
+ for (int i = 0; i < kArrayLen; ++i) placed_array[i].~ThrowingValue<>();
+ ThrowingValue<>::operator delete[](placed_array, &array_buf);
+ });
+
+ UnsetCountdown();
+}
+
+TEST(ThrowingValueTest, NonThrowingDestructor) {
+ auto* allocated = new ThrowingValue<>();
+
+ SetCountdown();
+ ExpectNoThrow([allocated]() { delete allocated; });
+ UnsetCountdown();
+}
+
+TEST(ThrowingBoolTest, ThrowingBool) {
+ ThrowingBool t = true;
+
+ // Test that it's contextually convertible to bool
+ if (t) { // NOLINT(whitespace/empty_if_body)
+ }
+ EXPECT_TRUE(t);
+
+ TestOp([&]() { (void)!t; });
+}
+
+TEST(ThrowingAllocatorTest, MemoryManagement) {
+ // Just exercise the memory management capabilities under LSan to make sure we
+ // don't leak.
+ ThrowingAllocator<int> int_alloc;
+ int* ip = int_alloc.allocate(1);
+ int_alloc.deallocate(ip, 1);
+ int* i_array = int_alloc.allocate(2);
+ int_alloc.deallocate(i_array, 2);
+
+ ThrowingAllocator<ThrowingValue<>> ef_alloc;
+ ThrowingValue<>* efp = ef_alloc.allocate(1);
+ ef_alloc.deallocate(efp, 1);
+ ThrowingValue<>* ef_array = ef_alloc.allocate(2);
+ ef_alloc.deallocate(ef_array, 2);
+}
+
+TEST(ThrowingAllocatorTest, CallsGlobalNew) {
+ ThrowingAllocator<ThrowingValue<>, NoThrow::kNoThrow> nothrow_alloc;
+ ThrowingValue<>* ptr;
+
+ SetCountdown();
+ // This will only throw if ThrowingValue::new is called.
+ ExpectNoThrow([&]() { ptr = nothrow_alloc.allocate(1); });
+ nothrow_alloc.deallocate(ptr, 1);
+
+ UnsetCountdown();
+}
+
+TEST(ThrowingAllocatorTest, ThrowingConstructors) {
+ ThrowingAllocator<int> int_alloc;
+ int* ip = nullptr;
+
+ SetCountdown();
+ EXPECT_THROW(ip = int_alloc.allocate(1), TestException);
+ ExpectNoThrow([&]() { ip = int_alloc.allocate(1); });
+
+ *ip = 1;
+ SetCountdown();
+ EXPECT_THROW(int_alloc.construct(ip, 2), TestException);
+ EXPECT_EQ(*ip, 1);
+ int_alloc.deallocate(ip, 1);
+
+ UnsetCountdown();
+}
+
+TEST(ThrowingAllocatorTest, NonThrowingConstruction) {
+ {
+ ThrowingAllocator<int, NoThrow::kNoThrow> int_alloc;
+ int* ip = nullptr;
+
+ SetCountdown();
+ ExpectNoThrow([&]() { ip = int_alloc.allocate(1); });
+
+ SetCountdown();
+ ExpectNoThrow([&]() { int_alloc.construct(ip, 2); });
+
+ EXPECT_EQ(*ip, 2);
+ int_alloc.deallocate(ip, 1);
+
+ UnsetCountdown();
+ }
+
+ {
+ ThrowingAllocator<int> int_alloc;
+ int* ip = nullptr;
+ ExpectNoThrow([&]() { ip = int_alloc.allocate(1); });
+ ExpectNoThrow([&]() { int_alloc.construct(ip, 2); });
+ EXPECT_EQ(*ip, 2);
+ int_alloc.deallocate(ip, 1);
+ }
+
+ {
+ ThrowingAllocator<ThrowingValue<NoThrow::kIntCtor>, NoThrow::kNoThrow>
+ ef_alloc;
+ ThrowingValue<NoThrow::kIntCtor>* efp;
+
+ SetCountdown();
+ ExpectNoThrow([&]() { efp = ef_alloc.allocate(1); });
+
+ SetCountdown();
+ ExpectNoThrow([&]() { ef_alloc.construct(efp, 2); });
+
+ EXPECT_EQ(efp->Get(), 2);
+ ef_alloc.destroy(efp);
+ ef_alloc.deallocate(efp, 1);
+
+ UnsetCountdown();
+ }
+
+ {
+ ThrowingAllocator<int> a;
+
+ SetCountdown();
+ ExpectNoThrow([&]() { ThrowingAllocator<double> a1 = a; });
+
+ SetCountdown();
+ ExpectNoThrow([&]() { ThrowingAllocator<double> a1 = std::move(a); });
+
+ UnsetCountdown();
+ }
+}
+
+TEST(ThrowingAllocatorTest, ThrowingAllocatorConstruction) {
+ ThrowingAllocator<int> a;
+ TestOp([]() { ThrowingAllocator<int> a; });
+ TestOp([&]() { a.select_on_container_copy_construction(); });
+}
+
+TEST(ThrowingAllocatorTest, State) {
+ ThrowingAllocator<int> a1, a2;
+ EXPECT_NE(a1, a2);
+
+ auto a3 = a1;
+ EXPECT_EQ(a3, a1);
+ int* ip = a1.allocate(1);
+ EXPECT_EQ(a3, a1);
+ a3.deallocate(ip, 1);
+ EXPECT_EQ(a3, a1);
+}
+
+TEST(ThrowingAllocatorTest, InVector) {
+ std::vector<ThrowingValue<>, ThrowingAllocator<ThrowingValue<>>> v;
+ for (int i = 0; i < 20; ++i) v.push_back({});
+ for (int i = 0; i < 20; ++i) v.pop_back();
+}
+
+TEST(ThrowingAllocatorTest, InList) {
+ std::list<ThrowingValue<>, ThrowingAllocator<ThrowingValue<>>> l;
+ for (int i = 0; i < 20; ++i) l.push_back({});
+ for (int i = 0; i < 20; ++i) l.pop_back();
+ for (int i = 0; i < 20; ++i) l.push_front({});
+ for (int i = 0; i < 20; ++i) l.pop_front();
+}
+
+template <typename TesterInstance, typename = void>
+struct NullaryTestValidator : public std::false_type {};
+
+template <typename TesterInstance>
+struct NullaryTestValidator<
+ TesterInstance,
+ absl::void_t<decltype(std::declval<TesterInstance>().Test())>>
+ : public std::true_type {};
+
+template <typename TesterInstance>
+bool HasNullaryTest(const TesterInstance&) {
+ return NullaryTestValidator<TesterInstance>::value;
+}
+
+void DummyOp(void*) {}
+
+template <typename TesterInstance, typename = void>
+struct UnaryTestValidator : public std::false_type {};
+
+template <typename TesterInstance>
+struct UnaryTestValidator<
+ TesterInstance,
+ absl::void_t<decltype(std::declval<TesterInstance>().Test(DummyOp))>>
+ : public std::true_type {};
+
+template <typename TesterInstance>
+bool HasUnaryTest(const TesterInstance&) {
+ return UnaryTestValidator<TesterInstance>::value;
+}
+
+TEST(ExceptionSafetyTesterTest, IncompleteTypesAreNotTestable) {
+ using T = exceptions_internal::UninitializedT;
+ auto op = [](T* t) {};
+ auto inv = [](T*) { return testing::AssertionSuccess(); };
+ auto fac = []() { return absl::make_unique<T>(); };
+
+ // Test that providing operation and inveriants still does not allow for the
+ // the invocation of .Test() and .Test(op) because it lacks a factory
+ auto without_fac =
+ absl::MakeExceptionSafetyTester().WithOperation(op).WithInvariants(
+ inv, absl::strong_guarantee);
+ EXPECT_FALSE(HasNullaryTest(without_fac));
+ EXPECT_FALSE(HasUnaryTest(without_fac));
+
+ // Test that providing invariants and factory allows the invocation of
+ // .Test(op) but does not allow for .Test() because it lacks an operation
+ auto without_op = absl::MakeExceptionSafetyTester()
+ .WithInvariants(inv, absl::strong_guarantee)
+ .WithFactory(fac);
+ EXPECT_FALSE(HasNullaryTest(without_op));
+ EXPECT_TRUE(HasUnaryTest(without_op));
+
+ // Test that providing operation and factory still does not allow for the
+ // the invocation of .Test() and .Test(op) because it lacks invariants
+ auto without_inv =
+ absl::MakeExceptionSafetyTester().WithOperation(op).WithFactory(fac);
+ EXPECT_FALSE(HasNullaryTest(without_inv));
+ EXPECT_FALSE(HasUnaryTest(without_inv));
+}
+
+struct ExampleStruct {};
+
+std::unique_ptr<ExampleStruct> ExampleFunctionFactory() {
+ return absl::make_unique<ExampleStruct>();
+}
+
+void ExampleFunctionOperation(ExampleStruct*) {}
+
+testing::AssertionResult ExampleFunctionInvariant(ExampleStruct*) {
+ return testing::AssertionSuccess();
+}
+
+struct {
+ std::unique_ptr<ExampleStruct> operator()() const {
+ return ExampleFunctionFactory();
+ }
+} example_struct_factory;
+
+struct {
+ void operator()(ExampleStruct*) const {}
+} example_struct_operation;
+
+struct {
+ testing::AssertionResult operator()(ExampleStruct* example_struct) const {
+ return ExampleFunctionInvariant(example_struct);
+ }
+} example_struct_invariant;
+
+auto example_lambda_factory = []() { return ExampleFunctionFactory(); };
+
+auto example_lambda_operation = [](ExampleStruct*) {};
+
+auto example_lambda_invariant = [](ExampleStruct* example_struct) {
+ return ExampleFunctionInvariant(example_struct);
+};
+
+// Testing that function references, pointers, structs with operator() and
+// lambdas can all be used with ExceptionSafetyTester
+TEST(ExceptionSafetyTesterTest, MixedFunctionTypes) {
+ // function reference
+ EXPECT_TRUE(absl::MakeExceptionSafetyTester()
+ .WithFactory(ExampleFunctionFactory)
+ .WithOperation(ExampleFunctionOperation)
+ .WithInvariants(ExampleFunctionInvariant)
+ .Test());
+
+ // function pointer
+ EXPECT_TRUE(absl::MakeExceptionSafetyTester()
+ .WithFactory(&ExampleFunctionFactory)
+ .WithOperation(&ExampleFunctionOperation)
+ .WithInvariants(&ExampleFunctionInvariant)
+ .Test());
+
+ // struct
+ EXPECT_TRUE(absl::MakeExceptionSafetyTester()
+ .WithFactory(example_struct_factory)
+ .WithOperation(example_struct_operation)
+ .WithInvariants(example_struct_invariant)
+ .Test());
+
+ // lambda
+ EXPECT_TRUE(absl::MakeExceptionSafetyTester()
+ .WithFactory(example_lambda_factory)
+ .WithOperation(example_lambda_operation)
+ .WithInvariants(example_lambda_invariant)
+ .Test());
+}
+
+struct NonNegative {
+ bool operator==(const NonNegative& other) const { return i == other.i; }
+ int i;
+};
+
+testing::AssertionResult CheckNonNegativeInvariants(NonNegative* g) {
+ if (g->i >= 0) {
+ return testing::AssertionSuccess();
+ }
+ return testing::AssertionFailure()
+ << "i should be non-negative but is " << g->i;
+}
+
+struct {
+ template <typename T>
+ void operator()(T* t) const {
+ (*t)();
+ }
+} invoker;
+
+auto tester =
+ absl::MakeExceptionSafetyTester().WithOperation(invoker).WithInvariants(
+ CheckNonNegativeInvariants);
+auto strong_tester = tester.WithInvariants(absl::strong_guarantee);
+
+struct FailsBasicGuarantee : public NonNegative {
+ void operator()() {
+ --i;
+ ThrowingValue<> bomb;
+ ++i;
+ }
+};
+
+TEST(ExceptionCheckTest, BasicGuaranteeFailure) {
+ EXPECT_FALSE(tester.WithInitialValue(FailsBasicGuarantee{}).Test());
+}
+
+struct FollowsBasicGuarantee : public NonNegative {
+ void operator()() {
+ ++i;
+ ThrowingValue<> bomb;
+ }
+};
+
+TEST(ExceptionCheckTest, BasicGuarantee) {
+ EXPECT_TRUE(tester.WithInitialValue(FollowsBasicGuarantee{}).Test());
+}
+
+TEST(ExceptionCheckTest, StrongGuaranteeFailure) {
+ EXPECT_FALSE(strong_tester.WithInitialValue(FailsBasicGuarantee{}).Test());
+ EXPECT_FALSE(strong_tester.WithInitialValue(FollowsBasicGuarantee{}).Test());
+}
+
+struct BasicGuaranteeWithExtraInvariants : public NonNegative {
+ // After operator(), i is incremented. If operator() throws, i is set to 9999
+ void operator()() {
+ int old_i = i;
+ i = kExceptionSentinel;
+ ThrowingValue<> bomb;
+ i = ++old_i;
+ }
+
+ static constexpr int kExceptionSentinel = 9999;
+};
+constexpr int BasicGuaranteeWithExtraInvariants::kExceptionSentinel;
+
+TEST(ExceptionCheckTest, BasicGuaranteeWithInvariants) {
+ auto tester_with_val =
+ tester.WithInitialValue(BasicGuaranteeWithExtraInvariants{});
+ EXPECT_TRUE(tester_with_val.Test());
+ EXPECT_TRUE(
+ tester_with_val
+ .WithInvariants([](BasicGuaranteeWithExtraInvariants* w) {
+ if (w->i == BasicGuaranteeWithExtraInvariants::kExceptionSentinel) {
+ return testing::AssertionSuccess();
+ }
+ return testing::AssertionFailure()
+ << "i should be "
+ << BasicGuaranteeWithExtraInvariants::kExceptionSentinel
+ << ", but is " << w->i;
+ })
+ .Test());
+}
+
+struct FollowsStrongGuarantee : public NonNegative {
+ void operator()() { ThrowingValue<> bomb; }
+};
+
+TEST(ExceptionCheckTest, StrongGuarantee) {
+ EXPECT_TRUE(tester.WithInitialValue(FollowsStrongGuarantee{}).Test());
+ EXPECT_TRUE(strong_tester.WithInitialValue(FollowsStrongGuarantee{}).Test());
+}
+
+struct HasReset : public NonNegative {
+ void operator()() {
+ i = -1;
+ ThrowingValue<> bomb;
+ i = 1;
+ }
+
+ void reset() { i = 0; }
+};
+
+testing::AssertionResult CheckHasResetInvariants(HasReset* h) {
+ h->reset();
+ return testing::AssertionResult(h->i == 0);
+}
+
+TEST(ExceptionCheckTest, ModifyingChecker) {
+ auto set_to_1000 = [](FollowsBasicGuarantee* g) {
+ g->i = 1000;
+ return testing::AssertionSuccess();
+ };
+ auto is_1000 = [](FollowsBasicGuarantee* g) {
+ return testing::AssertionResult(g->i == 1000);
+ };
+ auto increment = [](FollowsStrongGuarantee* g) {
+ ++g->i;
+ return testing::AssertionSuccess();
+ };
+
+ EXPECT_FALSE(tester.WithInitialValue(FollowsBasicGuarantee{})
+ .WithInvariants(set_to_1000, is_1000)
+ .Test());
+ EXPECT_TRUE(strong_tester.WithInitialValue(FollowsStrongGuarantee{})
+ .WithInvariants(increment)
+ .Test());
+ EXPECT_TRUE(absl::MakeExceptionSafetyTester()
+ .WithInitialValue(HasReset{})
+ .WithInvariants(CheckHasResetInvariants)
+ .Test(invoker));
+}
+
+struct NonCopyable : public NonNegative {
+ NonCopyable(const NonCopyable&) = delete;
+ NonCopyable() : NonNegative{0} {}
+
+ void operator()() { ThrowingValue<> bomb; }
+};
+
+TEST(ExceptionCheckTest, NonCopyable) {
+ auto factory = []() { return absl::make_unique<NonCopyable>(); };
+ EXPECT_TRUE(tester.WithFactory(factory).Test());
+ EXPECT_TRUE(strong_tester.WithFactory(factory).Test());
+}
+
+struct NonEqualityComparable : public NonNegative {
+ void operator()() { ThrowingValue<> bomb; }
+
+ void ModifyOnThrow() {
+ ++i;
+ ThrowingValue<> bomb;
+ static_cast<void>(bomb);
+ --i;
+ }
+};
+
+TEST(ExceptionCheckTest, NonEqualityComparable) {
+ auto nec_is_strong = [](NonEqualityComparable* nec) {
+ return testing::AssertionResult(nec->i == NonEqualityComparable().i);
+ };
+ auto strong_nec_tester = tester.WithInitialValue(NonEqualityComparable{})
+ .WithInvariants(nec_is_strong);
+
+ EXPECT_TRUE(strong_nec_tester.Test());
+ EXPECT_FALSE(strong_nec_tester.Test(
+ [](NonEqualityComparable* n) { n->ModifyOnThrow(); }));
+}
+
+template <typename T>
+struct ExhaustivenessTester {
+ void operator()() {
+ successes |= 1;
+ T b1;
+ static_cast<void>(b1);
+ successes |= (1 << 1);
+ T b2;
+ static_cast<void>(b2);
+ successes |= (1 << 2);
+ T b3;
+ static_cast<void>(b3);
+ successes |= (1 << 3);
+ }
+
+ bool operator==(const ExhaustivenessTester<ThrowingValue<>>&) const {
+ return true;
+ }
+
+ static unsigned char successes;
+};
+
+struct {
+ template <typename T>
+ testing::AssertionResult operator()(ExhaustivenessTester<T>*) const {
+ return testing::AssertionSuccess();
+ }
+} CheckExhaustivenessTesterInvariants;
+
+template <typename T>
+unsigned char ExhaustivenessTester<T>::successes = 0;
+
+TEST(ExceptionCheckTest, Exhaustiveness) {
+ auto exhaust_tester = absl::MakeExceptionSafetyTester()
+ .WithInvariants(CheckExhaustivenessTesterInvariants)
+ .WithOperation(invoker);
+
+ EXPECT_TRUE(
+ exhaust_tester.WithInitialValue(ExhaustivenessTester<int>{}).Test());
+ EXPECT_EQ(ExhaustivenessTester<int>::successes, 0xF);
+
+ EXPECT_TRUE(
+ exhaust_tester.WithInitialValue(ExhaustivenessTester<ThrowingValue<>>{})
+ .WithInvariants(absl::strong_guarantee)
+ .Test());
+ EXPECT_EQ(ExhaustivenessTester<ThrowingValue<>>::successes, 0xF);
+}
+
+struct LeaksIfCtorThrows : private exceptions_internal::TrackedObject {
+ LeaksIfCtorThrows() : TrackedObject(ABSL_PRETTY_FUNCTION) {
+ ++counter;
+ ThrowingValue<> v;
+ static_cast<void>(v);
+ --counter;
+ }
+ LeaksIfCtorThrows(const LeaksIfCtorThrows&) noexcept
+ : TrackedObject(ABSL_PRETTY_FUNCTION) {}
+ static int counter;
+};
+int LeaksIfCtorThrows::counter = 0;
+
+TEST(ExceptionCheckTest, TestLeakyCtor) {
+ absl::TestThrowingCtor<LeaksIfCtorThrows>();
+ EXPECT_EQ(LeaksIfCtorThrows::counter, 1);
+ LeaksIfCtorThrows::counter = 0;
+}
+
+struct Tracked : private exceptions_internal::TrackedObject {
+ Tracked() : TrackedObject(ABSL_PRETTY_FUNCTION) {}
+};
+
+TEST(ConstructorTrackerTest, CreatedBefore) {
+ Tracked a, b, c;
+ exceptions_internal::ConstructorTracker ct(exceptions_internal::countdown);
+}
+
+TEST(ConstructorTrackerTest, CreatedAfter) {
+ exceptions_internal::ConstructorTracker ct(exceptions_internal::countdown);
+ Tracked a, b, c;
+}
+
+TEST(ConstructorTrackerTest, NotDestroyedAfter) {
+ absl::aligned_storage_t<sizeof(Tracked), alignof(Tracked)> storage;
+ EXPECT_NONFATAL_FAILURE(
+ {
+ exceptions_internal::ConstructorTracker ct(
+ exceptions_internal::countdown);
+ new (&storage) Tracked;
+ },
+ "not destroyed");
+
+ // Manual destruction of the Tracked instance is not required because
+ // ~ConstructorTracker() handles that automatically when a leak is found
+}
+
+TEST(ConstructorTrackerTest, DestroyedTwice) {
+ EXPECT_NONFATAL_FAILURE(
+ {
+ Tracked t;
+ t.~Tracked();
+ },
+ "destroyed improperly");
+}
+
+TEST(ConstructorTrackerTest, ConstructedTwice) {
+ absl::aligned_storage_t<sizeof(Tracked), alignof(Tracked)> storage;
+ EXPECT_NONFATAL_FAILURE(
+ {
+ new (&storage) Tracked;
+ new (&storage) Tracked;
+ },
+ "re-constructed");
+ reinterpret_cast<Tracked*>(&storage)->~Tracked();
+}
+
+TEST(ThrowingValueTraitsTest, RelationalOperators) {
+ ThrowingValue<> a, b;
+ EXPECT_TRUE((std::is_convertible<decltype(a == b), bool>::value));
+ EXPECT_TRUE((std::is_convertible<decltype(a != b), bool>::value));
+ EXPECT_TRUE((std::is_convertible<decltype(a < b), bool>::value));
+ EXPECT_TRUE((std::is_convertible<decltype(a <= b), bool>::value));
+ EXPECT_TRUE((std::is_convertible<decltype(a > b), bool>::value));
+ EXPECT_TRUE((std::is_convertible<decltype(a >= b), bool>::value));
+}
+
+TEST(ThrowingAllocatorTraitsTest, Assignablility) {
+ EXPECT_TRUE(std::is_move_assignable<ThrowingAllocator<int>>::value);
+ EXPECT_TRUE(std::is_copy_assignable<ThrowingAllocator<int>>::value);
+ EXPECT_TRUE(std::is_nothrow_move_assignable<ThrowingAllocator<int>>::value);
+ EXPECT_TRUE(std::is_nothrow_copy_assignable<ThrowingAllocator<int>>::value);
+}
+
+} // namespace
+} // namespace absl
http://git-wip-us.apache.org/repos/asf/marmotta/blob/0eb556da/libraries/ostrich/backend/3rdparty/abseil/absl/base/inline_variable_test.cc
----------------------------------------------------------------------
diff --git a/libraries/ostrich/backend/3rdparty/abseil/absl/base/inline_variable_test.cc b/libraries/ostrich/backend/3rdparty/abseil/absl/base/inline_variable_test.cc
new file mode 100644
index 0000000..5499189
--- /dev/null
+++ b/libraries/ostrich/backend/3rdparty/abseil/absl/base/inline_variable_test.cc
@@ -0,0 +1,62 @@
+// 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.
+
+#include <type_traits>
+
+#include "absl/base/internal/inline_variable.h"
+#include "absl/base/internal/inline_variable_testing.h"
+
+#include "gtest/gtest.h"
+
+namespace absl {
+namespace inline_variable_testing_internal {
+namespace {
+
+TEST(InlineVariableTest, Constexpr) {
+ static_assert(inline_variable_foo.value == 5, "");
+ static_assert(other_inline_variable_foo.value == 5, "");
+ static_assert(inline_variable_int == 5, "");
+ static_assert(other_inline_variable_int == 5, "");
+}
+
+TEST(InlineVariableTest, DefaultConstructedIdentityEquality) {
+ EXPECT_EQ(get_foo_a().value, 5);
+ EXPECT_EQ(get_foo_b().value, 5);
+ EXPECT_EQ(&get_foo_a(), &get_foo_b());
+}
+
+TEST(InlineVariableTest, DefaultConstructedIdentityInequality) {
+ EXPECT_NE(&inline_variable_foo, &other_inline_variable_foo);
+}
+
+TEST(InlineVariableTest, InitializedIdentityEquality) {
+ EXPECT_EQ(get_int_a(), 5);
+ EXPECT_EQ(get_int_b(), 5);
+ EXPECT_EQ(&get_int_a(), &get_int_b());
+}
+
+TEST(InlineVariableTest, InitializedIdentityInequality) {
+ EXPECT_NE(&inline_variable_int, &other_inline_variable_int);
+}
+
+TEST(InlineVariableTest, FunPtrType) {
+ static_assert(
+ std::is_same<void(*)(),
+ std::decay<decltype(inline_variable_fun_ptr)>::type>::value,
+ "");
+}
+
+} // namespace
+} // namespace inline_variable_testing_internal
+} // namespace absl
http://git-wip-us.apache.org/repos/asf/marmotta/blob/0eb556da/libraries/ostrich/backend/3rdparty/abseil/absl/base/inline_variable_test_a.cc
----------------------------------------------------------------------
diff --git a/libraries/ostrich/backend/3rdparty/abseil/absl/base/inline_variable_test_a.cc b/libraries/ostrich/backend/3rdparty/abseil/absl/base/inline_variable_test_a.cc
new file mode 100644
index 0000000..a3bf3b6
--- /dev/null
+++ b/libraries/ostrich/backend/3rdparty/abseil/absl/base/inline_variable_test_a.cc
@@ -0,0 +1,25 @@
+// 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.
+
+#include "absl/base/internal/inline_variable_testing.h"
+
+namespace absl {
+namespace inline_variable_testing_internal {
+
+const Foo& get_foo_a() { return inline_variable_foo; }
+
+const int& get_int_a() { return inline_variable_int; }
+
+} // namespace inline_variable_testing_internal
+} // namespace absl
http://git-wip-us.apache.org/repos/asf/marmotta/blob/0eb556da/libraries/ostrich/backend/3rdparty/abseil/absl/base/inline_variable_test_b.cc
----------------------------------------------------------------------
diff --git a/libraries/ostrich/backend/3rdparty/abseil/absl/base/inline_variable_test_b.cc b/libraries/ostrich/backend/3rdparty/abseil/absl/base/inline_variable_test_b.cc
new file mode 100644
index 0000000..b4b9393
--- /dev/null
+++ b/libraries/ostrich/backend/3rdparty/abseil/absl/base/inline_variable_test_b.cc
@@ -0,0 +1,25 @@
+// 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.
+
+#include "absl/base/internal/inline_variable_testing.h"
+
+namespace absl {
+namespace inline_variable_testing_internal {
+
+const Foo& get_foo_b() { return inline_variable_foo; }
+
+const int& get_int_b() { return inline_variable_int; }
+
+} // namespace inline_variable_testing_internal
+} // namespace absl
http://git-wip-us.apache.org/repos/asf/marmotta/blob/0eb556da/libraries/ostrich/backend/3rdparty/abseil/absl/base/internal/atomic_hook.h
----------------------------------------------------------------------
diff --git a/libraries/ostrich/backend/3rdparty/abseil/absl/base/internal/atomic_hook.h b/libraries/ostrich/backend/3rdparty/abseil/absl/base/internal/atomic_hook.h
new file mode 100644
index 0000000..47d4013
--- /dev/null
+++ b/libraries/ostrich/backend/3rdparty/abseil/absl/base/internal/atomic_hook.h
@@ -0,0 +1,150 @@
+// 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.
+//
+
+#ifndef ABSL_BASE_INTERNAL_ATOMIC_HOOK_H_
+#define ABSL_BASE_INTERNAL_ATOMIC_HOOK_H_
+
+#include <atomic>
+#include <cassert>
+#include <cstdint>
+#include <utility>
+
+namespace absl {
+namespace base_internal {
+
+template <typename T>
+class AtomicHook;
+
+// AtomicHook is a helper class, templatized on a raw function pointer type, for
+// implementing Abseil customization hooks. It is a callable object that
+// dispatches to the registered hook, or performs a no-op (and returns a default
+// constructed object) if no hook has been registered.
+//
+// Reads and writes guarantee memory_order_acquire/memory_order_release
+// semantics.
+template <typename ReturnType, typename... Args>
+class AtomicHook<ReturnType (*)(Args...)> {
+ public:
+ using FnPtr = ReturnType (*)(Args...);
+
+ constexpr AtomicHook() : hook_(kInitialValue) {}
+
+ // Stores the provided function pointer as the value for this hook.
+ //
+ // This is intended to be called once. Multiple calls are legal only if the
+ // same function pointer is provided for each call. The store is implemented
+ // as a memory_order_release operation, and read accesses are implemented as
+ // memory_order_acquire.
+ void Store(FnPtr fn) {
+ bool success = DoStore(fn);
+ static_cast<void>(success);
+ assert(success);
+ }
+
+ // Invokes the registered callback. If no callback has yet been registered, a
+ // default-constructed object of the appropriate type is returned instead.
+ template <typename... CallArgs>
+ ReturnType operator()(CallArgs&&... args) const {
+ return DoLoad()(std::forward<CallArgs>(args)...);
+ }
+
+ // Returns the registered callback, or nullptr if none has been registered.
+ // Useful if client code needs to conditionalize behavior based on whether a
+ // callback was registered.
+ //
+ // Note that atomic_hook.Load()() and atomic_hook() have different semantics:
+ // operator()() will perform a no-op if no callback was registered, while
+ // Load()() will dereference a null function pointer. Prefer operator()() to
+ // Load()() unless you must conditionalize behavior on whether a hook was
+ // registered.
+ FnPtr Load() const {
+ FnPtr ptr = DoLoad();
+ return (ptr == DummyFunction) ? nullptr : ptr;
+ }
+
+ private:
+ static ReturnType DummyFunction(Args...) {
+ return ReturnType();
+ }
+
+ // Current versions of MSVC (as of September 2017) have a broken
+ // implementation of std::atomic<T*>: Its constructor attempts to do the
+ // equivalent of a reinterpret_cast in a constexpr context, which is not
+ // allowed.
+ //
+ // This causes an issue when building with LLVM under Windows. To avoid this,
+ // we use a less-efficient, intptr_t-based implementation on Windows.
+
+#ifdef _MSC_FULL_VER
+#define ABSL_HAVE_WORKING_ATOMIC_POINTER 0
+#else
+#define ABSL_HAVE_WORKING_ATOMIC_POINTER 1
+#endif
+
+#if ABSL_HAVE_WORKING_ATOMIC_POINTER
+ static constexpr FnPtr kInitialValue = &DummyFunction;
+
+ // Return the stored value, or DummyFunction if no value has been stored.
+ FnPtr DoLoad() const { return hook_.load(std::memory_order_acquire); }
+
+ // Store the given value. Returns false if a different value was already
+ // stored to this object.
+ bool DoStore(FnPtr fn) {
+ assert(fn);
+ FnPtr expected = DummyFunction;
+ hook_.compare_exchange_strong(expected, fn, std::memory_order_acq_rel,
+ std::memory_order_acquire);
+ const bool store_succeeded = (expected == DummyFunction);
+ const bool same_value_already_stored = (expected == fn);
+ return store_succeeded || same_value_already_stored;
+ }
+
+ std::atomic<FnPtr> hook_;
+#else // !ABSL_HAVE_WORKING_ATOMIC_POINTER
+ // Use a sentinel value unlikely to be the address of an actual function.
+ static constexpr intptr_t kInitialValue = 0;
+
+ static_assert(sizeof(intptr_t) >= sizeof(FnPtr),
+ "intptr_t can't contain a function pointer");
+
+ FnPtr DoLoad() const {
+ const intptr_t value = hook_.load(std::memory_order_acquire);
+ if (value == 0) {
+ return DummyFunction;
+ }
+ return reinterpret_cast<FnPtr>(value);
+ }
+
+ bool DoStore(FnPtr fn) {
+ assert(fn);
+ const auto value = reinterpret_cast<intptr_t>(fn);
+ intptr_t expected = 0;
+ hook_.compare_exchange_strong(expected, value, std::memory_order_acq_rel,
+ std::memory_order_acquire);
+ const bool store_succeeded = (expected == 0);
+ const bool same_value_already_stored = (expected == value);
+ return store_succeeded || same_value_already_stored;
+ }
+
+ std::atomic<intptr_t> hook_;
+#endif
+};
+
+#undef ABSL_HAVE_WORKING_ATOMIC_POINTER
+
+} // namespace base_internal
+} // namespace absl
+
+#endif // ABSL_BASE_INTERNAL_ATOMIC_HOOK_H_