Add very basic compatibility with folly locks for synchronized
authorCaren Thomas <carenthomas@fb.com>
Fri, 17 Jun 2016 18:24:54 +0000 (11:24 -0700)
committerFacebook Github Bot 5 <facebook-github-bot-5-bot@fb.com>
Fri, 17 Jun 2016 18:38:24 +0000 (11:38 -0700)
Summary: Add folly locks to the HasLockUnlock struct so that they can be used inside Synchronized. acquireReadWrite() and releaseReadWrite() functions are added to each lock class so that their .lock and .unlock methods are accessible by Synchronized. These changes allow an extremely basic level of compatibility for the purpose of running benchmarks and so compatibility with dual_locking, etc. have not been tested.

Reviewed By: simpkins

Differential Revision: D3434621

fbshipit-source-id: d55cffbb1eccaf23645384b9a41f85c5df593ffe

folly/SpinLock.h
folly/test/SynchronizedTest.cpp

index 6d10df4ad4e032aab207d52068a5ffbd9bc59a08..5ab446056fc781b9a9551d0862f5a05667c9be75 100644 (file)
@@ -32,6 +32,8 @@
 
 #pragma once
 
+#include <type_traits>
+
 #include <folly/detail/SpinLockImpl.h>
 
 namespace folly {
@@ -62,4 +64,11 @@ class SpinLockGuardImpl : private boost::noncopyable {
 
 typedef SpinLockGuardImpl<SpinLock> SpinLockGuard;
 
+namespace detail {
+template <class T>
+struct HasLockUnlock;
+
+template <>
+struct HasLockUnlock<folly::SpinLock> : public std::true_type {};
+}
 }
index dd97d28cbdfb7250bd473486477a586ef80bd4f0..375b0c165cc09e533eaf76d00c918b1b487f7f59 100644 (file)
 // Test bed for folly/Synchronized.h
 
 #include <folly/Portability.h>
-#include <folly/Synchronized.h>
 #include <folly/RWSpinLock.h>
 #include <folly/SharedMutex.h>
+#include <folly/SpinLock.h>
+#include <folly/Synchronized.h>
 #include <folly/test/SynchronizedTestLib.h>
 #include <gtest/gtest.h>
 
@@ -46,6 +47,7 @@ using SynchronizedTestTypes = testing::Types
   , boost::recursive_timed_mutex
 #endif
   , boost::shared_mutex
+  , folly::SpinLock
 #ifdef RW_SPINLOCK_USE_X86_INTRINSIC_
   , folly::RWTicketSpinLock32
   , folly::RWTicketSpinLock64