From: Yedidya Feldblum Date: Wed, 5 Aug 2015 18:48:13 +0000 (-0700) Subject: Use static const keys in AtomicHashArray::Config. X-Git-Tag: v0.53.0~6 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d807e4c12d51b00183cc2fcc13d75fb3ec0e412c;p=folly.git Use static const keys in AtomicHashArray::Config. 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 --- diff --git a/folly/AtomicHashArray-inl.h b/folly/AtomicHashArray-inl.h index 6ab54850..4997545e 100644 --- a/folly/AtomicHashArray-inl.h +++ b/folly/AtomicHashArray-inl.h @@ -23,6 +23,19 @@ namespace folly { +template +const KeyT AtomicHashArray::Config:: +kEmptyKey = (KeyT)-1; +template +const KeyT AtomicHashArray::Config:: +kLockedKey = (KeyT)-2; +template +const KeyT AtomicHashArray::Config:: +kErasedKey = (KeyT)-3; + // AtomicHashArray private constructor -- template diff --git a/folly/AtomicHashArray.h b/folly/AtomicHashArray.h index 7f12f862..1142eda9 100644 --- a/folly/AtomicHashArray.h +++ b/folly/AtomicHashArray.h @@ -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), diff --git a/folly/AtomicLinkedList.h b/folly/AtomicLinkedList.h index eca8de16..f24746a5 100644 --- a/folly/AtomicLinkedList.h +++ b/folly/AtomicLinkedList.h @@ -63,7 +63,7 @@ class AtomicLinkedList { * Note: list must be empty on destruction. */ ~AtomicLinkedList() { - assert(head_ == nullptr); + assert(empty()); } bool empty() const { diff --git a/folly/test/AtomicHashArrayTest.cpp b/folly/test/AtomicHashArrayTest.cpp index 2b2f4f8e..c1eaf6d9 100644 --- a/folly/test/AtomicHashArrayTest.cpp +++ b/folly/test/AtomicHashArrayTest.cpp @@ -191,3 +191,7 @@ TEST(Aha, InsertErase_i64_str) { testMap(); testMap>(); } + +TEST(Aha, Create_cstr_i64) { + auto obj = AtomicHashArray::create(12); +}