Flat combining: Add lock holder with deferred option. Minor fixes.
[folly.git] / folly / experimental / flat_combining / test / FlatCombiningTest.cpp
index ff745b265e6c1ca1559b9d8b58a952f3feea98d7..570a6ef8bd4efccfc558cb50fab8e0be362f92b3 100644 (file)
@@ -19,6 +19,8 @@
 #include <folly/portability/GTest.h>
 #include <glog/logging.h>
 
+#include <mutex>
+
 using namespace folly::test;
 
 constexpr int LINES = 5;
@@ -34,6 +36,22 @@ struct Params {
 
 class FlatCombiningTest : public ::testing::TestWithParam<Params> {};
 
+TEST(FlatCombiningTest, lock_holder) {
+  folly::FcSimpleExample<> ex(10);
+  {
+    std::unique_lock<std::mutex> l;
+    ex.holdLock(l);
+    CHECK(l.owns_lock());
+  }
+  {
+    std::unique_lock<std::mutex> l;
+    ex.holdLock(l, std::defer_lock);
+    CHECK(l.try_lock());
+  }
+  CHECK(ex.tryExclusive());
+  ex.releaseExclusive();
+}
+
 TEST_P(FlatCombiningTest, combining) {
   Params p = GetParam();
   for (auto n : nthr) {