summaryrefslogtreecommitdiff
path: root/absl/time/internal/cctz
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2019-08-15 10:06:39 -0700
committerGravatar vslashg <gfalcon@google.com>2019-08-15 14:36:45 -0400
commitaae8143cf9aa611f70d7ea9b95b8b8b383b2271a (patch)
tree131d9bf69d90050cc21bdb5c35bca797c58dd5c6 /absl/time/internal/cctz
parentd9aa92d7fb324314f9df487ac23d32a25650b742 (diff)
Export of internal Abseil changes
-- f28b989d5161230c6561e923b458c797a96bcf90 by Greg Falcon <gfalcon@google.com>: Import of CCTZ from GitHub. PiperOrigin-RevId: 263586488 -- 8259484025b7de45358719fc6182a48cac8044c6 by Andy Soffer <asoffer@google.com>: Internal changes and combine namespaces into a single namespace. PiperOrigin-RevId: 263560576 -- 8d19f41661984a600d1f8bbfeb8a30fcb4dee7d6 by Mark Barolak <mbar@google.com>: Inside of absl::string_view::copy, use absl::string_view::traits_type::copy instead of std:copy to do the actual work. This both follows the C++ standard more closely and avoids avoid MSVC unchecked iterator warnings. PiperOrigin-RevId: 263430502 -- c06bf74236e12c7c1c97bfcbbc9d29bd65d6b36c by Andy Soffer <asoffer@google.com>: Remove force-inlining attributes. Benchmarking results indicate that they are creating meaningful performance differences. PiperOrigin-RevId: 263364896 -- ec4fa6eac958a9521456201b138784f55d3b17bc by Abseil Team <absl-team@google.com>: Make BM_Fill benchmarks more representative. PiperOrigin-RevId: 263349482 -- 4ae280b4eb31d9cb58e847eb670473340f7778c1 by Derek Mauro <dmauro@google.com>: Fix new -Wdeprecated-copy warning in gcc9 PiperOrigin-RevId: 263348118 -- d238a92f452a5c35686f9c71596fdd1fe62090a2 by Matt Calabrese <calabrese@google.com>: The std::is_trivially_xxx fail on versions of GCC up until 7.4 due to faulty underlying intrinsics, but our emulation succeeds. Update our traits to not compare against the standard library implementation in these versions. PiperOrigin-RevId: 263209457 GitOrigin-RevId: f28b989d5161230c6561e923b458c797a96bcf90 Change-Id: I4c41db5928ba71e243aeace4420e06d1a2df0b5b
Diffstat (limited to 'absl/time/internal/cctz')
-rw-r--r--absl/time/internal/cctz/src/time_zone_impl.cc13
1 files changed, 9 insertions, 4 deletions
diff --git a/absl/time/internal/cctz/src/time_zone_impl.cc b/absl/time/internal/cctz/src/time_zone_impl.cc
index 3cbc6746..a26151d3 100644
--- a/absl/time/internal/cctz/src/time_zone_impl.cc
+++ b/absl/time/internal/cctz/src/time_zone_impl.cc
@@ -33,7 +33,12 @@ using TimeZoneImplByName =
TimeZoneImplByName* time_zone_map = nullptr;
// Mutual exclusion for time_zone_map.
-std::mutex time_zone_mutex;
+std::mutex& TimeZoneMutex() {
+ // This mutex is intentionally "leaked" to avoid the static deinitialization
+ // order fiasco (std::mutex's destructor is not trivial on many platforms).
+ static std::mutex* time_zone_mutex = new std::mutex;
+ return *time_zone_mutex;
+}
} // namespace
@@ -54,7 +59,7 @@ bool time_zone::Impl::LoadTimeZone(const std::string& name, time_zone* tz) {
// Then check, under a shared lock, whether the time zone has already
// been loaded. This is the common path. TODO: Move to shared_mutex.
{
- std::lock_guard<std::mutex> lock(time_zone_mutex);
+ std::lock_guard<std::mutex> lock(TimeZoneMutex());
if (time_zone_map != nullptr) {
TimeZoneImplByName::const_iterator itr = time_zone_map->find(name);
if (itr != time_zone_map->end()) {
@@ -65,7 +70,7 @@ bool time_zone::Impl::LoadTimeZone(const std::string& name, time_zone* tz) {
}
// Now check again, under an exclusive lock.
- std::lock_guard<std::mutex> lock(time_zone_mutex);
+ std::lock_guard<std::mutex> lock(TimeZoneMutex());
if (time_zone_map == nullptr) time_zone_map = new TimeZoneImplByName;
const Impl*& impl = (*time_zone_map)[name];
if (impl == nullptr) {
@@ -84,7 +89,7 @@ bool time_zone::Impl::LoadTimeZone(const std::string& name, time_zone* tz) {
}
void time_zone::Impl::ClearTimeZoneMapTestOnly() {
- std::lock_guard<std::mutex> lock(time_zone_mutex);
+ std::lock_guard<std::mutex> lock(TimeZoneMutex());
if (time_zone_map != nullptr) {
// Existing time_zone::Impl* entries are in the wild, so we simply
// leak them. Future requests will result in reloading the data.