Skip to content

Commit

Permalink
Export of internal Abseil changes.
Browse files Browse the repository at this point in the history
--
821196cfb2a3b943ffdc4c9e75daec92d7ffb28b by Abseil Team <absl-team@google.com>:

Performance improvements

PiperOrigin-RevId: 212668992

--
704858e2e767016bad27d53eec01d9d48e546b23 by Abseil Team <absl-team@google.com>:

Low-level Portability enchancements for Abseil Mutex on WebAssembly.

Emscripten Pthreads do not use signals, so remove use of pthread_sigmask or
other async-signal-safe related handling code.

PiperOrigin-RevId: 212527958

--
be3e38cb4d493b755132d20c8c2d1a51e45d5449 by Jon Cohen <cohenjon@google.com>:

Internal change.

PiperOrigin-RevId: 212523797
GitOrigin-RevId: 821196cfb2a3b943ffdc4c9e75daec92d7ffb28b
Change-Id: I5694e23e4e09364a15dd6fc4e2e3f15e38835687
  • Loading branch information
Abseil Team authored and gennadiycivil committed Sep 13, 2018
1 parent 0245191 commit 8ff1374
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 171 deletions.
14 changes: 12 additions & 2 deletions absl/base/internal/low_level_alloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -401,16 +401,20 @@ bool LowLevelAlloc::DeleteArena(Arena *arena) {
ABSL_RAW_CHECK(munmap_result != 0,
"LowLevelAlloc::DeleteArena: VitualFree failed");
#else
#ifndef ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING
if ((arena->flags & LowLevelAlloc::kAsyncSignalSafe) == 0) {
munmap_result = munmap(region, size);
} else {
munmap_result = base_internal::DirectMunmap(region, size);
}
#else
munmap_result = munmap(region, size);
#endif // ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING
if (munmap_result != 0) {
ABSL_RAW_LOG(FATAL, "LowLevelAlloc::DeleteArena: munmap failed: %d",
errno);
}
#endif
#endif // _WIN32
}
section.Leave();
arena->~Arena();
Expand Down Expand Up @@ -545,17 +549,23 @@ static void *DoAllocWithArena(size_t request, LowLevelAlloc::Arena *arena) {
MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
ABSL_RAW_CHECK(new_pages != nullptr, "VirtualAlloc failed");
#else
#ifndef ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING
if ((arena->flags & LowLevelAlloc::kAsyncSignalSafe) != 0) {
new_pages = base_internal::DirectMmap(nullptr, new_pages_size,
PROT_WRITE|PROT_READ, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
} else {
new_pages = mmap(nullptr, new_pages_size, PROT_WRITE | PROT_READ,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
}
#else
new_pages = mmap(nullptr, new_pages_size, PROT_WRITE | PROT_READ,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
#endif // ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING
if (new_pages == MAP_FAILED) {
ABSL_RAW_LOG(FATAL, "mmap error: %d", errno);
}
#endif

#endif // _WIN32
arena->mu.Lock();
s = reinterpret_cast<AllocList *>(new_pages);
s->header.size = new_pages_size;
Expand Down
7 changes: 5 additions & 2 deletions absl/base/internal/low_level_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@
#define ABSL_LOW_LEVEL_ALLOC_MISSING 1
#endif

// Using LowLevelAlloc with kAsyncSignalSafe isn't supported on Windows.
// Using LowLevelAlloc with kAsyncSignalSafe isn't supported on Windows or
// asm.js / WebAssembly.
// See https://kripken.github.io/emscripten-site/docs/porting/pthreads.html
// for more information.
#ifdef ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING
#error ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING cannot be directly set
#elif defined(_WIN32)
#elif defined(_WIN32) || defined(__asmjs__) || defined(__wasm__)
#define ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING 1
#endif

Expand Down
10 changes: 10 additions & 0 deletions absl/base/internal/thread_identity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ void SetCurrentThreadIdentity(
// NOTE: Not async-safe. But can be open-coded.
absl::call_once(init_thread_identity_key_once, AllocateThreadIdentityKey,
reclaimer);

#ifdef __EMSCRIPTEN__
// Emscripten PThread implementation does not support signals.
// See https://kripken.github.io/emscripten-site/docs/porting/pthreads.html
// for more information.
pthread_setspecific(thread_identity_pthread_key,
reinterpret_cast<void*>(identity));
#else
// We must mask signals around the call to setspecific as with current glibc,
// a concurrent getspecific (needed for GetCurrentThreadIdentityIfPresent())
// may zero our value.
Expand All @@ -81,6 +89,8 @@ void SetCurrentThreadIdentity(
pthread_setspecific(thread_identity_pthread_key,
reinterpret_cast<void*>(identity));
pthread_sigmask(SIG_SETMASK, &curr_signals, nullptr);
#endif // !__EMSCRIPTEN__

#elif ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_TLS
// NOTE: Not async-safe. But can be open-coded.
absl::call_once(init_thread_identity_key_once, AllocateThreadIdentityKey,
Expand Down
1 change: 0 additions & 1 deletion absl/memory/memory_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ TEST(Make_UniqueTest, NotAmbiguousWithStdMakeUnique) {
}

#if 0
// TODO(billydonahue): Make a proper NC test.
// These tests shouldn't compile.
TEST(MakeUniqueTestNC, AcceptMoveOnlyLvalue) {
auto m = MoveOnly();
Expand Down
80 changes: 29 additions & 51 deletions absl/strings/internal/str_format/arg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class ConvertedIntInfo {
// Note: 'o' conversions do not have a base indicator, it's just that
// the '#' flag is specified to modify the precision for 'o' conversions.
string_view BaseIndicator(const ConvertedIntInfo &info,
const ConversionSpec &conv) {
const ConversionSpec conv) {
bool alt = conv.flags().alt;
int radix = conv.conv().radix();
if (conv.conv().id() == ConversionChar::p)
Expand All @@ -127,7 +127,7 @@ string_view BaseIndicator(const ConvertedIntInfo &info,
return {};
}

string_view SignColumn(bool neg, const ConversionSpec &conv) {
string_view SignColumn(bool neg, const ConversionSpec conv) {
if (conv.conv().is_signed()) {
if (neg) return "-";
if (conv.flags().show_pos) return "+";
Expand All @@ -136,7 +136,7 @@ string_view SignColumn(bool neg, const ConversionSpec &conv) {
return {};
}

bool ConvertCharImpl(unsigned char v, const ConversionSpec &conv,
bool ConvertCharImpl(unsigned char v, const ConversionSpec conv,
FormatSinkImpl *sink) {
size_t fill = 0;
if (conv.width() >= 0) fill = conv.width();
Expand All @@ -148,7 +148,7 @@ bool ConvertCharImpl(unsigned char v, const ConversionSpec &conv,
}

bool ConvertIntImplInner(const ConvertedIntInfo &info,
const ConversionSpec &conv, FormatSinkImpl *sink) {
const ConversionSpec conv, FormatSinkImpl *sink) {
// Print as a sequence of Substrings:
// [left_spaces][sign][base_indicator][zeroes][formatted][right_spaces]
size_t fill = 0;
Expand Down Expand Up @@ -202,8 +202,7 @@ bool ConvertIntImplInner(const ConvertedIntInfo &info,
}

template <typename T>
bool ConvertIntImplInner(T v, const ConversionSpec &conv,
FormatSinkImpl *sink) {
bool ConvertIntImplInner(T v, const ConversionSpec conv, FormatSinkImpl *sink) {
ConvertedIntInfo info(v, conv.conv());
if (conv.flags().basic && conv.conv().id() != ConversionChar::p) {
if (info.is_neg()) sink->Append(1, '-');
Expand All @@ -218,7 +217,7 @@ bool ConvertIntImplInner(T v, const ConversionSpec &conv,
}

template <typename T>
bool ConvertIntArg(T v, const ConversionSpec &conv, FormatSinkImpl *sink) {
bool ConvertIntArg(T v, const ConversionSpec conv, FormatSinkImpl *sink) {
if (conv.conv().is_float()) {
return FormatConvertImpl(static_cast<double>(v), conv, sink).value;
}
Expand All @@ -234,11 +233,11 @@ bool ConvertIntArg(T v, const ConversionSpec &conv, FormatSinkImpl *sink) {
}

template <typename T>
bool ConvertFloatArg(T v, const ConversionSpec &conv, FormatSinkImpl *sink) {
bool ConvertFloatArg(T v, const ConversionSpec conv, FormatSinkImpl *sink) {
return conv.conv().is_float() && ConvertFloatImpl(v, conv, sink);
}

inline bool ConvertStringArg(string_view v, const ConversionSpec &conv,
inline bool ConvertStringArg(string_view v, const ConversionSpec conv,
FormatSinkImpl *sink) {
if (conv.conv().id() != ConversionChar::s)
return false;
Expand All @@ -254,19 +253,19 @@ inline bool ConvertStringArg(string_view v, const ConversionSpec &conv,

// ==================== Strings ====================
ConvertResult<Conv::s> FormatConvertImpl(const std::string &v,
const ConversionSpec &conv,
const ConversionSpec conv,
FormatSinkImpl *sink) {
return {ConvertStringArg(v, conv, sink)};
}

ConvertResult<Conv::s> FormatConvertImpl(string_view v,
const ConversionSpec &conv,
const ConversionSpec conv,
FormatSinkImpl *sink) {
return {ConvertStringArg(v, conv, sink)};
}

ConvertResult<Conv::s | Conv::p> FormatConvertImpl(const char *v,
const ConversionSpec &conv,
const ConversionSpec conv,
FormatSinkImpl *sink) {
if (conv.conv().id() == ConversionChar::p)
return {FormatConvertImpl(VoidPtr(v), conv, sink).value};
Expand All @@ -283,7 +282,7 @@ ConvertResult<Conv::s | Conv::p> FormatConvertImpl(const char *v,
}

// ==================== Raw pointers ====================
ConvertResult<Conv::p> FormatConvertImpl(VoidPtr v, const ConversionSpec &conv,
ConvertResult<Conv::p> FormatConvertImpl(VoidPtr v, const ConversionSpec conv,
FormatSinkImpl *sink) {
if (conv.conv().id() != ConversionChar::p)
return {false};
Expand All @@ -295,104 +294,83 @@ ConvertResult<Conv::p> FormatConvertImpl(VoidPtr v, const ConversionSpec &conv,
}

// ==================== Floats ====================
FloatingConvertResult FormatConvertImpl(float v, const ConversionSpec &conv,
FloatingConvertResult FormatConvertImpl(float v, const ConversionSpec conv,
FormatSinkImpl *sink) {
return {ConvertFloatArg(v, conv, sink)};
}
FloatingConvertResult FormatConvertImpl(double v, const ConversionSpec &conv,
FloatingConvertResult FormatConvertImpl(double v, const ConversionSpec conv,
FormatSinkImpl *sink) {
return {ConvertFloatArg(v, conv, sink)};
}
FloatingConvertResult FormatConvertImpl(long double v,
const ConversionSpec &conv,
const ConversionSpec conv,
FormatSinkImpl *sink) {
return {ConvertFloatArg(v, conv, sink)};
}

// ==================== Chars ====================
IntegralConvertResult FormatConvertImpl(char v, const ConversionSpec &conv,
IntegralConvertResult FormatConvertImpl(char v, const ConversionSpec conv,
FormatSinkImpl *sink) {
return {ConvertIntArg(v, conv, sink)};
}
IntegralConvertResult FormatConvertImpl(signed char v,
const ConversionSpec &conv,
const ConversionSpec conv,
FormatSinkImpl *sink) {
return {ConvertIntArg(v, conv, sink)};
}
IntegralConvertResult FormatConvertImpl(unsigned char v,
const ConversionSpec &conv,
const ConversionSpec conv,
FormatSinkImpl *sink) {
return {ConvertIntArg(v, conv, sink)};
}

// ==================== Ints ====================
IntegralConvertResult FormatConvertImpl(short v, // NOLINT
const ConversionSpec &conv,
const ConversionSpec conv,
FormatSinkImpl *sink) {
return {ConvertIntArg(v, conv, sink)};
}
IntegralConvertResult FormatConvertImpl(unsigned short v, // NOLINT
const ConversionSpec &conv,
const ConversionSpec conv,
FormatSinkImpl *sink) {
return {ConvertIntArg(v, conv, sink)};
}
IntegralConvertResult FormatConvertImpl(int v, const ConversionSpec &conv,
IntegralConvertResult FormatConvertImpl(int v, const ConversionSpec conv,
FormatSinkImpl *sink) {
return {ConvertIntArg(v, conv, sink)};
}
IntegralConvertResult FormatConvertImpl(unsigned v, const ConversionSpec &conv,
IntegralConvertResult FormatConvertImpl(unsigned v, const ConversionSpec conv,
FormatSinkImpl *sink) {
return {ConvertIntArg(v, conv, sink)};
}
IntegralConvertResult FormatConvertImpl(long v, // NOLINT
const ConversionSpec &conv,
const ConversionSpec conv,
FormatSinkImpl *sink) {
return {ConvertIntArg(v, conv, sink)};
}
IntegralConvertResult FormatConvertImpl(unsigned long v, // NOLINT
const ConversionSpec &conv,
const ConversionSpec conv,
FormatSinkImpl *sink) {
return {ConvertIntArg(v, conv, sink)};
}
IntegralConvertResult FormatConvertImpl(long long v, // NOLINT
const ConversionSpec &conv,
const ConversionSpec conv,
FormatSinkImpl *sink) {
return {ConvertIntArg(v, conv, sink)};
}
IntegralConvertResult FormatConvertImpl(unsigned long long v, // NOLINT
const ConversionSpec &conv,
const ConversionSpec conv,
FormatSinkImpl *sink) {
return {ConvertIntArg(v, conv, sink)};
}
IntegralConvertResult FormatConvertImpl(absl::uint128 v,
const ConversionSpec &conv,
const ConversionSpec conv,
FormatSinkImpl *sink) {
return {ConvertIntArg(v, conv, sink)};
}

template struct FormatArgImpl::TypedVTable<str_format_internal::VoidPtr>;

template struct FormatArgImpl::TypedVTable<bool>;
template struct FormatArgImpl::TypedVTable<char>;
template struct FormatArgImpl::TypedVTable<signed char>;
template struct FormatArgImpl::TypedVTable<unsigned char>;
template struct FormatArgImpl::TypedVTable<short>; // NOLINT
template struct FormatArgImpl::TypedVTable<unsigned short>; // NOLINT
template struct FormatArgImpl::TypedVTable<int>;
template struct FormatArgImpl::TypedVTable<unsigned>;
template struct FormatArgImpl::TypedVTable<long>; // NOLINT
template struct FormatArgImpl::TypedVTable<unsigned long>; // NOLINT
template struct FormatArgImpl::TypedVTable<long long>; // NOLINT
template struct FormatArgImpl::TypedVTable<unsigned long long>; // NOLINT
template struct FormatArgImpl::TypedVTable<absl::uint128>;

template struct FormatArgImpl::TypedVTable<float>;
template struct FormatArgImpl::TypedVTable<double>;
template struct FormatArgImpl::TypedVTable<long double>;

template struct FormatArgImpl::TypedVTable<const char *>;
template struct FormatArgImpl::TypedVTable<std::string>;
template struct FormatArgImpl::TypedVTable<string_view>;
ABSL_INTERNAL_FORMAT_DISPATCH_OVERLOADS_EXPAND_();


} // namespace str_format_internal

Expand Down
Loading

0 comments on commit 8ff1374

Please sign in to comment.