Use static const keys in AtomicHashArray::Config.
authorYedidya Feldblum <yfeldblum@fb.com>
Wed, 5 Aug 2015 18:48:13 +0000 (11:48 -0700)
committerfacebook-github-bot-9 <folly-bot@fb.com>
Wed, 5 Aug 2015 19:22:21 +0000 (12:22 -0700)
Summary: [Folly] Use static const keys in AtomicHashArray::Config.

From https://github.com/facebook/folly/pull/264/, MSVC may have a hard time with certain expressions. D2284130 factored them out as `static constexpr` members, but Clang had a hard time with that in HPHP. This adds a test case that triggers the same failure to the Folly build. Not quite sure how this impacts MSVC though.

Reviewed By: @Gownta

Differential Revision: D2304346

folly/AtomicHashArray-inl.h
folly/AtomicHashArray.h
folly/AtomicLinkedList.h
folly/test/AtomicHashArrayTest.cpp

index 6ab54850beec6c5acec22d40679255e86abf4471..4997545ed9e1a97ecebbdbd6f185b837a1b66b46 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>
index 7f12f862ca1af68e0fc5d5b0de24af5ad6e0886b..1142eda95566da353218916362e0e5aacbadaecd 100644 (file)
@@ -128,9 +128,15 @@ class AtomicHashArray : boost::noncopyable {
     int    entryCountThreadCacheSize;
     size_t capacity; // if positive, overrides maxLoadFactor
 
-    constexpr Config() : emptyKey((KeyT)-1),
-                         lockedKey((KeyT)-2),
-                         erasedKey((KeyT)-3),
+  private:
+    static const KeyT kEmptyKey;
+    static const KeyT kLockedKey;
+    static const KeyT kErasedKey;
+
+  public:
+    constexpr Config() : emptyKey(kEmptyKey),
+                         lockedKey(kLockedKey),
+                         erasedKey(kErasedKey),
                          maxLoadFactor(0.8),
                          growthFactor(-1),
                          entryCountThreadCacheSize(1000),
index eca8de16d9b32450cdab81876ae1c3834c6c9efe..f24746a5d1f6f8e0f7c234f75f5dfd2d1a99853a 100644 (file)
@@ -63,7 +63,7 @@ class AtomicLinkedList {
    * Note: list must be empty on destruction.
    */
   ~AtomicLinkedList() {
-    assert(head_ == nullptr);
+    assert(empty());
   }
 
   bool empty() const {
index 2b2f4f8e93fbd88cd15b89bfd8a87a355765cebd..c1eaf6d91a69780024aede5b05099eac70240445 100644 (file)
@@ -191,3 +191,7 @@ TEST(Aha, InsertErase_i64_str) {
   testMap<int64_t, string>();
   testMap<int64_t, string, MmapAllocator<char>>();
 }
+
+TEST(Aha, Create_cstr_i64) {
+  auto obj = AtomicHashArray<const char*, int64_t>::create(12);
+}