proxygen
folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED > Class Template Reference

#include <Synchronized.h>

Inheritance diagram for folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED >:
folly::SynchronizedBase< Subclass, detail::MutexLevel::UPGRADE >

Public Types

using LockedPtr = ::folly::LockedPtr< Subclass, LockPolicyExclusive >
 
using ConstWLockedPtr = ::folly::LockedPtr< const Subclass, LockPolicyExclusive >
 
using ConstLockedPtr = ::folly::LockedPtr< const Subclass, LockPolicyShared >
 
using TryWLockedPtr = ::folly::LockedPtr< Subclass, LockPolicyTryExclusive >
 
using ConstTryWLockedPtr = ::folly::LockedPtr< const Subclass, LockPolicyTryExclusive >
 
using TryRLockedPtr = ::folly::LockedPtr< const Subclass, LockPolicyTryShared >
 

Public Member Functions

LockedPtr wlock ()
 
TryWLockedPtr tryWLock ()
 
ConstLockedPtr rlock () const
 
TryRLockedPtr tryRLock () const
 
template<class Rep , class Period >
LockedPtr wlock (const std::chrono::duration< Rep, Period > &timeout)
 
template<class Rep , class Period >
ConstLockedPtr rlock (const std::chrono::duration< Rep, Period > &timeout) const
 
template<class Function >
auto withWLock (Function &&function)
 
template<class Function >
auto withWLockPtr (Function &&function)
 
template<class Function >
auto withRLock (Function &&function) const
 
template<class Function >
auto withRLockPtr (Function &&function) const
 

Detailed Description

template<class Subclass>
class folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED >

SynchronizedBase specialization for shared mutex types.

This class provides wlock() and rlock() methods for acquiring the lock and accessing the data.

Definition at line 84 of file Synchronized.h.

Member Typedef Documentation

template<class Subclass >
using folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED >::ConstLockedPtr = ::folly::LockedPtr<const Subclass, LockPolicyShared>

Definition at line 89 of file Synchronized.h.

template<class Subclass >
using folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED >::ConstTryWLockedPtr = ::folly::LockedPtr<const Subclass, LockPolicyTryExclusive>

Definition at line 93 of file Synchronized.h.

template<class Subclass >
using folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED >::ConstWLockedPtr = ::folly::LockedPtr<const Subclass, LockPolicyExclusive>

Definition at line 88 of file Synchronized.h.

template<class Subclass >
using folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED >::LockedPtr = ::folly::LockedPtr<Subclass, LockPolicyExclusive>

Definition at line 86 of file Synchronized.h.

template<class Subclass >
using folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED >::TryRLockedPtr = ::folly::LockedPtr<const Subclass, LockPolicyTryShared>

Definition at line 94 of file Synchronized.h.

template<class Subclass >
using folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED >::TryWLockedPtr = ::folly::LockedPtr<Subclass, LockPolicyTryExclusive>

Definition at line 91 of file Synchronized.h.

Member Function Documentation

template<class Subclass >
ConstLockedPtr folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED >::rlock ( ) const
inline

Acquire a read lock, and return a ConstLockedPtr that can be used to safely access the datum.

Definition at line 122 of file Synchronized.h.

122  {
123  return ConstLockedPtr(static_cast<const Subclass*>(this));
124  }
::folly::LockedPtr< const Subclass, LockPolicyShared > ConstLockedPtr
Definition: Synchronized.h:89
template<class Subclass >
template<class Rep , class Period >
ConstLockedPtr folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED >::rlock ( const std::chrono::duration< Rep, Period > &  timeout) const
inline

Attempts to acquire the lock, or fails if the timeout elapses first. If acquisition is unsuccessful, the returned LockedPtr will be null.

(Use LockedPtr::operator bool() or LockedPtr::isNull() to check for validity.)

Definition at line 157 of file Synchronized.h.

158  {
159  return ConstLockedPtr(static_cast<const Subclass*>(this), timeout);
160  }
::folly::LockedPtr< const Subclass, LockPolicyShared > ConstLockedPtr
Definition: Synchronized.h:89
template<class Subclass >
TryRLockedPtr folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED >::tryRLock ( ) const
inline

Attempts to acquire the lock in shared mode. If acquisition is unsuccessful, the returned LockedPtr will be null.

(Use LockedPtr::operator bool() or LockedPtr::isNull() to check for validity.)

Definition at line 133 of file Synchronized.h.

133  {
134  return TryRLockedPtr{static_cast<const Subclass*>(this)};
135  }
::folly::LockedPtr< const Subclass, LockPolicyTryShared > TryRLockedPtr
Definition: Synchronized.h:94
template<class Subclass >
TryWLockedPtr folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED >::tryWLock ( )
inline

Attempts to acquire the lock in exclusive mode. If acquisition is unsuccessful, the returned LockedPtr will be null.

(Use LockedPtr::operator bool() or LockedPtr::isNull() to check for validity.)

Definition at line 114 of file Synchronized.h.

114  {
115  return TryWLockedPtr{static_cast<Subclass*>(this)};
116  }
::folly::LockedPtr< Subclass, LockPolicyTryExclusive > TryWLockedPtr
Definition: Synchronized.h:91
template<class Subclass >
template<class Function >
auto folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED >::withRLock ( Function &&  function) const
inline

Invoke a function while holding an the lock in shared mode.

A const reference to the datum will be passed into the function as its only argument.

Definition at line 202 of file Synchronized.h.

References folly::rlock().

202  {
203  return function(*rlock());
204  }
template<class Subclass >
template<class Function >
auto folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED >::withRLockPtr ( Function &&  function) const
inline

Definition at line 207 of file Synchronized.h.

References folly::rlock().

207  {
208  return function(rlock());
209  }
template<class Subclass >
template<class Function >
auto folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED >::withWLock ( Function &&  function)
inline

Invoke a function while holding the lock exclusively.

A reference to the datum will be passed into the function as its only argument.

This can be used with a lambda argument for easily defining small critical sections in the code. For example:

auto value = obj.withWLock([](auto& data) { data.doStuff(); return data.getValue(); });

Definition at line 177 of file Synchronized.h.

References folly::wlock().

177  {
178  return function(*wlock());
179  }
template<class Subclass >
template<class Function >
auto folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED >::withWLockPtr ( Function &&  function)
inline

Invoke a function while holding the lock exclusively.

This is similar to withWLock(), but the function will be passed a LockedPtr rather than a reference to the data itself.

This allows scopedUnlock() to be called on the LockedPtr argument if desired.

Definition at line 191 of file Synchronized.h.

References folly::wlock().

191  {
192  return function(wlock());
193  }
template<class Subclass >
LockedPtr folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED >::wlock ( )
inline

Acquire an exclusive lock, and return a LockedPtr that can be used to safely access the datum.

LockedPtr offers operator -> and * to provide access to the datum. The lock will be released when the LockedPtr is destroyed.

Definition at line 103 of file Synchronized.h.

103  {
104  return LockedPtr(static_cast<Subclass*>(this));
105  }
::folly::LockedPtr< Subclass, LockPolicyExclusive > LockedPtr
Definition: Synchronized.h:86
template<class Subclass >
template<class Rep , class Period >
LockedPtr folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED >::wlock ( const std::chrono::duration< Rep, Period > &  timeout)
inline

Attempts to acquire the lock, or fails if the timeout elapses first. If acquisition is unsuccessful, the returned LockedPtr will be null.

(Use LockedPtr::operator bool() or LockedPtr::isNull() to check for validity.)

Definition at line 145 of file Synchronized.h.

145  {
146  return LockedPtr(static_cast<Subclass*>(this), timeout);
147  }
::folly::LockedPtr< Subclass, LockPolicyExclusive > LockedPtr
Definition: Synchronized.h:86

The documentation for this class was generated from the following file: