codemod setMaxNumMessagesInQueue to setMaxNumPendingConnectionsPerWorker
[folly.git] / folly / SharedMutex.h
index 37b39765dc1eb1231ce62fbe370da267ecd29b1e..ebe8d794c385b4ead4cae7e99835f3aea6e96bbb 100644 (file)
@@ -237,7 +237,7 @@ class SharedMutexImpl {
   class UpgradeHolder;
   class WriteHolder;
 
-  SharedMutexImpl() : state_(0) {}
+  constexpr SharedMutexImpl() : state_(0) {}
 
   SharedMutexImpl(const SharedMutexImpl&) = delete;
   SharedMutexImpl(SharedMutexImpl&&) = delete;
@@ -676,10 +676,13 @@ class SharedMutexImpl {
   // guarantees we won't have inter-L1 contention.  We give ourselves
   // a factor of 2 on the core count, which should hold us for a couple
   // processor generations.  deferredReaders[] is 2048 bytes currently.
+ public:
   static constexpr uint32_t kMaxDeferredReaders = 64;
   static constexpr uint32_t kDeferredSearchDistance = 2;
   static constexpr uint32_t kDeferredSeparationFactor = 4;
 
+ private:
+
   static_assert(!(kMaxDeferredReaders & (kMaxDeferredReaders - 1)),
                 "kMaxDeferredReaders must be a power of 2");
   static_assert(!(kDeferredSearchDistance & (kDeferredSearchDistance - 1)),
@@ -710,10 +713,13 @@ class SharedMutexImpl {
   // If any of those elements points to a SharedMutexImpl, then it
   // should be considered that there is a shared lock on that instance.
   // See kTokenless.
+ public:
   typedef Atom<uintptr_t> DeferredReaderSlot;
-  static DeferredReaderSlot deferredReaders
+
+ private:
+  FOLLY_ALIGN_TO_AVOID_FALSE_SHARING static DeferredReaderSlot deferredReaders
       [kMaxDeferredReaders *
-       kDeferredSeparationFactor] FOLLY_ALIGN_TO_AVOID_FALSE_SHARING;
+       kDeferredSeparationFactor];
 
   // Performs an exclusive lock, waiting for state_ & waitMask to be
   // zero first
@@ -1373,6 +1379,12 @@ class SharedMutexImpl {
   friend void acquireReadWrite(SharedMutexImpl& lock) { lock.lock(); }
   friend void releaseRead(SharedMutexImpl& lock) { lock.unlock_shared(); }
   friend void releaseReadWrite(SharedMutexImpl& lock) { lock.unlock(); }
+  friend bool acquireRead(SharedMutexImpl& lock, unsigned int ms) {
+    return lock.try_lock_shared_for(std::chrono::milliseconds(ms));
+  }
+  friend bool acquireReadWrite(SharedMutexImpl& lock, unsigned int ms) {
+    return lock.try_lock_for(std::chrono::milliseconds(ms));
+  }
 };
 
 #define COMMON_CONCURRENCY_SHARED_MUTEX_DECLARE_STATIC_STORAGE(type) \