X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Ftest%2FAtomicLinkedListTest.cpp;h=80cf452eba855f674f338fc6a05aa03a729be6ca;hb=b71a1b76b3dd7d63bc1d27ed292ddb604fdd9388;hp=62f3dc60492fdd71d0758cdefdf42af523741e98;hpb=71f01fb8f37708b54e32d99aa9c2200744a7ba78;p=folly.git diff --git a/folly/test/AtomicLinkedListTest.cpp b/folly/test/AtomicLinkedListTest.cpp index 62f3dc60..80cf452e 100644 --- a/folly/test/AtomicLinkedListTest.cpp +++ b/folly/test/AtomicLinkedListTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ +#include #include -#include - #include +#include class TestIntrusiveObject { public: @@ -74,6 +74,23 @@ TEST(AtomicIntrusiveLinkedList, Basic) { TestIntrusiveObject::List movedList = std::move(list); } +TEST(AtomicIntrusiveLinkedList, ReverseSweep) { + TestIntrusiveObject a(1), b(2), c(3); + TestIntrusiveObject::List list; + list.insertHead(&a); + list.insertHead(&b); + list.insertHead(&c); + size_t next_expected_id = 3; + list.reverseSweep([&](TestIntrusiveObject* obj) { + EXPECT_EQ(next_expected_id--, obj->id()); + }); + EXPECT_TRUE(list.empty()); + // Test that we can still insert + list.insertHead(&a); + EXPECT_FALSE(list.empty()); + list.reverseSweep([](TestIntrusiveObject*) {}); +} + TEST(AtomicIntrusiveLinkedList, Move) { TestIntrusiveObject a(1), b(2); @@ -104,8 +121,8 @@ TEST(AtomicIntrusiveLinkedList, Move) { } TEST(AtomicIntrusiveLinkedList, Stress) { - constexpr size_t kNumThreads = 32; - constexpr size_t kNumElements = 100000; + static constexpr size_t kNumThreads = 32; + static constexpr size_t kNumElements = 100000; std::vector elements; for (size_t i = 0; i < kNumThreads * kNumElements; ++i) { @@ -116,12 +133,11 @@ TEST(AtomicIntrusiveLinkedList, Stress) { std::vector threads; for (size_t threadId = 0; threadId < kNumThreads; ++threadId) { - threads.emplace_back( - [threadId, kNumThreads, kNumElements, &list, &elements]() { - for (size_t id = 0; id < kNumElements; ++id) { - list.insertHead(&elements[threadId + kNumThreads * id]); - } - }); + threads.emplace_back([threadId, &list, &elements] { + for (size_t id = 0; id < kNumElements; ++id) { + list.insertHead(&elements[threadId + kNumThreads * id]); + } + }); } std::vector ids; @@ -152,7 +168,8 @@ TEST(AtomicIntrusiveLinkedList, Stress) { class TestObject { public: - TestObject(size_t id__, std::shared_ptr ptr) : id_(id__), ptr_(ptr) {} + TestObject(size_t id__, const std::shared_ptr& ptr) + : id_(id__), ptr_(ptr) {} size_t id() { return id_;