Fix AtomicHashArray::defaultConfig SIOF.
authorYedidya Feldblum <yfeldblum@fb.com>
Fri, 14 Aug 2015 08:57:38 +0000 (01:57 -0700)
committerfacebook-github-bot-9 <folly-bot@fb.com>
Fri, 14 Aug 2015 09:20:29 +0000 (02:20 -0700)
Summary: [Folly] Fix AtomicHashArray::defaultConfig SIOF.

May fix https://github.com/facebook/folly/issues/300.

Reviewed By: @paulbiss

Differential Revision: D2343162

folly/AtomicHashArray-inl.h
folly/AtomicHashArray.h
folly/AtomicHashMap-inl.h
folly/AtomicHashMap.h

index 4997545ed9e1a97ecebbdbd6f185b837a1b66b46..80272d4a8c1aad1e5bf2a51ed0b533f624b5d247 100644 (file)
 
 namespace folly {
 
-template <class KeyT, class ValueT,
-          class HashFcn, class EqualFcn, class Allocator>
-const KeyT AtomicHashArray<KeyT, ValueT, HashFcn, EqualFcn, Allocator>::Config::
-kEmptyKey = (KeyT)-1;
-template <class KeyT, class ValueT,
-          class HashFcn, class EqualFcn, class Allocator>
-const KeyT AtomicHashArray<KeyT, ValueT, HashFcn, EqualFcn, Allocator>::Config::
-kLockedKey = (KeyT)-2;
-template <class KeyT, class ValueT,
-          class HashFcn, class EqualFcn, class Allocator>
-const KeyT AtomicHashArray<KeyT, ValueT, HashFcn, EqualFcn, Allocator>::Config::
-kErasedKey = (KeyT)-3;
-
 // AtomicHashArray private constructor --
 template <class KeyT, class ValueT,
           class HashFcn, class EqualFcn, class Allocator>
@@ -257,12 +244,6 @@ erase(KeyT key_in) {
   }
 }
 
-template <class KeyT, class ValueT,
-          class HashFcn, class EqualFcn, class Allocator>
-const typename AtomicHashArray<KeyT, ValueT,
-      HashFcn, EqualFcn, Allocator>::Config
-AtomicHashArray<KeyT, ValueT, HashFcn, EqualFcn, Allocator>::defaultConfig;
-
 template <class KeyT, class ValueT,
          class HashFcn, class EqualFcn, class Allocator>
 typename AtomicHashArray<KeyT, ValueT,
index 3479572dc53488a1b8c0e1bfee105b18029eef23..6da92b6596ec35b47f3b64feb745f1b9f4afd7bf 100644 (file)
@@ -128,23 +128,19 @@ class AtomicHashArray : boost::noncopyable {
     int    entryCountThreadCacheSize;
     size_t capacity; // if positive, overrides maxLoadFactor
 
-  private:
-    static const KeyT kEmptyKey;
-    static const KeyT kLockedKey;
-    static const KeyT kErasedKey;
-
   public:
-    Config() : emptyKey(kEmptyKey),
-               lockedKey(kLockedKey),
-               erasedKey(kErasedKey),
+    //  Cannot have constexpr ctor because some compilers rightly complain.
+    Config() : emptyKey((KeyT)-1),
+               lockedKey((KeyT)-2),
+               erasedKey((KeyT)-3),
                maxLoadFactor(0.8),
                growthFactor(-1),
                entryCountThreadCacheSize(1000),
                capacity(0) {}
   };
 
-  static const Config defaultConfig;
-  static SmartPtr create(size_t maxSize, const Config& = defaultConfig);
+  //  Cannot have pre-instantiated const Config instance because of SIOF.
+  static SmartPtr create(size_t maxSize, const Config& c = Config());
 
   iterator find(KeyT k) {
     return iterator(this, findInternal(k).idx);
index 4f7c6a12e91497ee573b07fb88d85413bfc18951..92c0a1507012da83bbfe76b4fe8e3960d557e1d6 100644 (file)
 
 namespace folly {
 
-template <class KeyT, class ValueT,
-          class HashFcn, class EqualFcn, class Allocator>
-const typename AtomicHashMap<KeyT, ValueT, HashFcn, EqualFcn, Allocator>::Config
-AtomicHashMap<KeyT, ValueT, HashFcn, EqualFcn, Allocator>::defaultConfig;
-
 // AtomicHashMap constructor -- Atomic wrapper that allows growth
 // This class has a lot of overhead (184 Bytes) so only use for big maps
 template <typename KeyT, typename ValueT,
index 52d2fb0d86f1ab9da1e0a13c89edae9b2021aaa1..fb35388732e85740377aa47102bfe17929fb8d4b 100644 (file)
@@ -191,8 +191,7 @@ class AtomicHashMap : boost::noncopyable {
   // The constructor takes a finalSizeEst which is the optimal
   // number of elements to maximize space utilization and performance,
   // and a Config object to specify more advanced options.
-  static const Config defaultConfig;
-  explicit AtomicHashMap(size_t finalSizeEst, const Config& = defaultConfig);
+  explicit AtomicHashMap(size_t finalSizeEst, const Config& c = Config());
 
   ~AtomicHashMap() {
     const int numMaps = numMapsAllocated_.load(std::memory_order_relaxed);