From 0f2aacae3d558f5cf54751b170c4e50d5483cc29 Mon Sep 17 00:00:00 2001 From: Jinlong Zhou Date: Thu, 16 Jun 2016 13:26:54 -0700 Subject: [PATCH] Reverted commit D3270439 Summary: [temp] (14)/6: > A function template, member function of a class template, variable template, or static data member of a class template shall be defined in every translation unit in which it is implicitly instantiated (14.7.1) unless the corresponding specialization is explicitly instantiated (14.7.2) in some translation unit; no diagnostic is required. `-Wundefined-var-template` warns on any implicit instantiations that are needed but could not be performed because the definition is not available. In particular, for valid code, this warns on templates/temploids which have their definition and all relevant explicit instantiations tucked away in some source file (but for which no explicit instantiation declarations are provided in the relevant header file) - used a few times in folly. This seems a bad style, the static data member template should either be defined in the header file or should be explicitly instantiated in each .cpp file. Reviewed By: igorsugak Differential Revision: D3270439 fbshipit-source-id: e8cdb0452c2f6240a348b93cdbf9975813f27bfe --- folly/Fingerprint.h | 14 ++------- folly/SharedMutex.cpp | 9 +++--- folly/SharedMutex.h | 31 +++++------------- folly/detail/CacheLocality.cpp | 16 ++++++++-- folly/detail/CacheLocality.h | 45 ++++++++++----------------- folly/test/CacheLocalityBenchmark.cpp | 1 + folly/test/CacheLocalityTest.cpp | 1 + folly/test/DeterministicSchedule.cpp | 10 +++--- folly/test/SharedMutexTest.cpp | 5 +++ 9 files changed, 56 insertions(+), 76 deletions(-) diff --git a/folly/Fingerprint.h b/folly/Fingerprint.h index c7a20fb7..f1980ae2 100644 --- a/folly/Fingerprint.h +++ b/folly/Fingerprint.h @@ -51,20 +51,12 @@ namespace folly { namespace detail { - template struct FingerprintTable { - static const uint64_t poly[1 + (BITS - 1) / 64]; - static const uint64_t table[8][256][1 + (BITS - 1) / 64]; + static const uint64_t poly[1 + (BITS-1)/64]; + static const uint64_t table[8][256][1 + (BITS-1)/64]; }; - -template -const uint64_t FingerprintTable::poly[1 + (BITS - 1) / 64] = {}; - -template -const uint64_t FingerprintTable::table[8][256][1 + (BITS - 1) / 64] = {}; - -} // namespace detail +} // namespace detail /** * Compute the Rabin fingerprint. diff --git a/folly/SharedMutex.cpp b/folly/SharedMutex.cpp index 23266b7c..e7c5267e 100644 --- a/folly/SharedMutex.cpp +++ b/folly/SharedMutex.cpp @@ -16,8 +16,7 @@ #include "SharedMutex.h" -namespace folly { -// Explicitly instantiate SharedMutex here: -template class SharedMutexImpl; -template class SharedMutexImpl; -} +COMMON_CONCURRENCY_SHARED_MUTEX_DECLARE_STATIC_STORAGE( + folly::SharedMutexReadPriority); +COMMON_CONCURRENCY_SHARED_MUTEX_DECLARE_STATIC_STORAGE( + folly::SharedMutexWritePriority); diff --git a/folly/SharedMutex.h b/folly/SharedMutex.h index 2d71a884..15dc91e6 100644 --- a/folly/SharedMutex.h +++ b/folly/SharedMutex.h @@ -1429,33 +1429,16 @@ class SharedMutexImpl { } }; -template < - bool ReaderPriority, - typename Tag_, - template class Atom, - bool BlockImmediately> -typename SharedMutexImpl:: - DeferredReaderSlot - SharedMutexImpl:: - deferredReaders[kMaxDeferredReaders * kDeferredSeparationFactor] = - {}; - -template < - bool ReaderPriority, - typename Tag_, - template class Atom, - bool BlockImmediately> -FOLLY_TLS uint32_t - SharedMutexImpl:: - tls_lastTokenlessSlot = 0; +#define COMMON_CONCURRENCY_SHARED_MUTEX_DECLARE_STATIC_STORAGE(type) \ + template <> \ + type::DeferredReaderSlot \ + type::deferredReaders[type::kMaxDeferredReaders * \ + type::kDeferredSeparationFactor] = {}; \ + template <> \ + FOLLY_TLS uint32_t type::tls_lastTokenlessSlot = 0; typedef SharedMutexImpl SharedMutexReadPriority; typedef SharedMutexImpl SharedMutexWritePriority; typedef SharedMutexWritePriority SharedMutex; -// Prevent the compiler from instantiating these in other translation units. -// They are instantiated once in SharedMutex.cpp -extern template class SharedMutexImpl; -extern template class SharedMutexImpl; - } // namespace folly diff --git a/folly/detail/CacheLocality.cpp b/folly/detail/CacheLocality.cpp index c62e0ac8..e75120d6 100644 --- a/folly/detail/CacheLocality.cpp +++ b/folly/detail/CacheLocality.cpp @@ -28,6 +28,8 @@ #include #include +DECLARE_ACCESS_SPREADER_TYPE(std::atomic) + namespace folly { namespace detail { @@ -231,11 +233,21 @@ Getcpu::Func Getcpu::resolveVdsoFunc() { #ifdef FOLLY_TLS /////////////// SequentialThreadId -template struct SequentialThreadId; + +template <> +std::atomic SequentialThreadId::prevId(0); + +template <> +FOLLY_TLS size_t SequentialThreadId::currentId(0); #endif /////////////// AccessSpreader -template struct AccessSpreader; + +template <> +Getcpu::Func AccessSpreader::pickGetcpuFunc() { + auto best = Getcpu::resolveVdsoFunc(); + return best ? best : &FallbackGetcpuType::getcpu; +} } // namespace detail } // namespace folly diff --git a/folly/detail/CacheLocality.h b/folly/detail/CacheLocality.h index c9baf528..1ede43cb 100644 --- a/folly/detail/CacheLocality.h +++ b/folly/detail/CacheLocality.h @@ -161,16 +161,6 @@ struct SequentialThreadId { static FOLLY_TLS size_t currentId; }; - -template