proxygen
folly::LockedPtr< SynchronizedType, LockPolicy > Class Template Reference

#include <Synchronized.h>

Inheritance diagram for folly::LockedPtr< SynchronizedType, LockPolicy >:
folly::LockedPtrBase< SynchronizedType, SynchronizedType::MutexType, LockPolicy >

Public Types

using DataType = typename SynchronizedType::DataType
 
using MutexType = typename SynchronizedType::MutexType
 
using Synchronized = typename std::remove_const< SynchronizedType >::type
 
- Public Types inherited from folly::LockedPtrBase< SynchronizedType, SynchronizedType::MutexType, LockPolicy >
using MutexType = SynchronizedType::MutexType
 

Public Member Functions

 LockedPtr ()
 
 LockedPtr (SynchronizedType *parent)
 
template<class Rep , class Period >
 LockedPtr (SynchronizedType *parent, const std::chrono::duration< Rep, Period > &timeout)
 
 LockedPtr (LockedPtr &&rhs) noexcept=default
 
template<typename LockPolicyType , EnableIfSameUnlockPolicy< LockPolicyType > * = nullptr>
 LockedPtr (LockedPtr< SynchronizedType, LockPolicyType > &&other) noexcept
 
LockedPtroperator= (LockedPtr &&rhs) noexcept=default
 
template<typename LockPolicyType , EnableIfSameUnlockPolicy< LockPolicyType > * = nullptr>
LockedPtroperator= (LockedPtr< SynchronizedType, LockPolicyType > &&other) noexcept
 
 LockedPtr (const LockedPtr &rhs)=delete
 
LockedPtroperator= (const LockedPtr &rhs)=delete
 
 ~LockedPtr ()
 
bool isNull () const
 
 operator bool () const
 
CDataTypeoperator-> () const
 
CDataTypeoperator* () const
 
ScopedUnlocker< SynchronizedType, LockPolicy > scopedUnlock ()
 
template<typename SyncType = SynchronizedType, typename = typename std::enable_if< LockTraits<typename SyncType::MutexType>::is_upgrade>::type>
LockedPtr< SynchronizedType, LockPolicyFromUpgradeToExclusivemoveFromUpgradeToWrite ()
 
template<typename SyncType = SynchronizedType, typename = typename std::enable_if< LockTraits<typename SyncType::MutexType>::is_upgrade>::type>
LockedPtr< SynchronizedType, LockPolicyFromExclusiveToUpgrademoveFromWriteToUpgrade ()
 
template<typename SyncType = SynchronizedType, typename = typename std::enable_if< LockTraits<typename SyncType::MutexType>::is_upgrade>::type>
LockedPtr< SynchronizedType, LockPolicyFromUpgradeToSharedmoveFromUpgradeToRead ()
 
template<typename SyncType = SynchronizedType, typename = typename std::enable_if< LockTraits<typename SyncType::MutexType>::is_upgrade>::type>
LockedPtr< SynchronizedType, LockPolicyFromExclusiveToSharedmoveFromWriteToRead ()
 
- Public Member Functions inherited from folly::LockedPtrBase< SynchronizedType, SynchronizedType::MutexType, LockPolicy >
 ~LockedPtrBase ()
 
void unlock ()
 

Private Types

using Base = LockedPtrBase< SynchronizedType, typename SynchronizedType::MutexType, LockPolicy >
 
using UnlockerData = typename Base::UnlockerData
 
using CDataType = detail::SynchronizedDataType< SynchronizedType >
 
template<typename LockPolicyOther >
using EnableIfSameUnlockPolicy = std::enable_if_t< std::is_same< typename LockPolicy::UnlockPolicy, typename LockPolicyOther::UnlockPolicy >::value >
 

Friends

template<typename SynchronizedTypeOther , typename LockPolicyOther >
class LockedPtr
 
class ScopedUnlocker< SynchronizedType, LockPolicy >
 

Additional Inherited Members

- Protected Types inherited from folly::LockedPtrBase< SynchronizedType, SynchronizedType::MutexType, LockPolicy >
using UnlockerData = SynchronizedType *
 
- Protected Member Functions inherited from folly::LockedPtrBase< SynchronizedType, SynchronizedType::MutexType, LockPolicy >
 LockedPtrBase ()
 
 LockedPtrBase (SynchronizedType *parent)
 
 LockedPtrBase (SynchronizedType *parent, const std::chrono::duration< Rep, Period > &timeout)
 
 LockedPtrBase (LockedPtrBase &&rhs) noexcept
 
 LockedPtrBase (LockedPtrBase< SynchronizedType, SynchronizedType::MutexType, LockPolicyType > &&rhs) noexcept
 
LockedPtrBaseoperator= (LockedPtrBase &&rhs) noexcept
 
LockedPtrBaseoperator= (LockedPtrBase< SynchronizedType, SynchronizedType::MutexType, LockPolicyType > &&rhs) noexcept
 
void assignImpl (LockedPtrBase< SynchronizedType, SynchronizedType::MutexType, LockPolicyLhs > &lhs, LockedPtrBase< SynchronizedType, SynchronizedType::MutexType, LockPolicyRhs > &rhs) noexcept
 
UnlockerData releaseLock ()
 
void reacquireLock (UnlockerData &&data)
 
- Static Protected Member Functions inherited from folly::LockedPtrBase< SynchronizedType, SynchronizedType::MutexType, LockPolicy >
static SynchronizedType * getSynchronized (UnlockerData data)
 
- Protected Attributes inherited from folly::LockedPtrBase< SynchronizedType, SynchronizedType::MutexType, LockPolicy >
SynchronizedType * parent_
 

Detailed Description

template<class SynchronizedType, class LockPolicy>
class folly::LockedPtr< SynchronizedType, LockPolicy >

A LockedPtr keeps a Synchronized<T> object locked for the duration of LockedPtr's existence.

It provides access the datum's members directly by using operator->() and operator*().

The LockPolicy parameter controls whether or not the lock is acquired in exclusive or shared mode.

Definition at line 49 of file Synchronized.h.

Member Typedef Documentation

template<class SynchronizedType, class LockPolicy>
using folly::LockedPtr< SynchronizedType, LockPolicy >::Base = LockedPtrBase< SynchronizedType, typename SynchronizedType::MutexType, LockPolicy>
private

Definition at line 1295 of file Synchronized.h.

template<class SynchronizedType, class LockPolicy>
using folly::LockedPtr< SynchronizedType, LockPolicy >::CDataType = detail::SynchronizedDataType<SynchronizedType>
private

Definition at line 1298 of file Synchronized.h.

template<class SynchronizedType, class LockPolicy>
using folly::LockedPtr< SynchronizedType, LockPolicy >::DataType = typename SynchronizedType::DataType

Definition at line 1311 of file Synchronized.h.

template<class SynchronizedType, class LockPolicy>
template<typename LockPolicyOther >
using folly::LockedPtr< SynchronizedType, LockPolicy >::EnableIfSameUnlockPolicy = std::enable_if_t<std::is_same< typename LockPolicy::UnlockPolicy, typename LockPolicyOther::UnlockPolicy>::value>
private

Definition at line 1304 of file Synchronized.h.

template<class SynchronizedType, class LockPolicy>
using folly::LockedPtr< SynchronizedType, LockPolicy >::MutexType = typename SynchronizedType::MutexType

Definition at line 1312 of file Synchronized.h.

template<class SynchronizedType, class LockPolicy>
using folly::LockedPtr< SynchronizedType, LockPolicy >::Synchronized = typename std::remove_const<SynchronizedType>::type

Definition at line 1313 of file Synchronized.h.

template<class SynchronizedType, class LockPolicy>
using folly::LockedPtr< SynchronizedType, LockPolicy >::UnlockerData = typename Base::UnlockerData
private

Definition at line 1296 of file Synchronized.h.

Constructor & Destructor Documentation

template<class SynchronizedType, class LockPolicy>
folly::LockedPtr< SynchronizedType, LockPolicy >::LockedPtr ( )
inline

Creates an uninitialized LockedPtr.

Dereferencing an uninitialized LockedPtr is not allowed.

Definition at line 1321 of file Synchronized.h.

1321 {}
template<class SynchronizedType, class LockPolicy>
folly::LockedPtr< SynchronizedType, LockPolicy >::LockedPtr ( SynchronizedType *  parent)
inlineexplicit

Takes a Synchronized<T> and locks it.

Definition at line 1326 of file Synchronized.h.

1326 : Base(parent) {}
LockedPtrBase< SynchronizedType, typename SynchronizedType::MutexType, LockPolicy > Base
folly::Function< void()> parent
Definition: AtFork.cpp:34
template<class SynchronizedType, class LockPolicy>
template<class Rep , class Period >
folly::LockedPtr< SynchronizedType, LockPolicy >::LockedPtr ( SynchronizedType *  parent,
const std::chrono::duration< Rep, Period > &  timeout 
)
inline

Takes a Synchronized<T> and attempts to lock it, within the specified timeout.

Blocks until the lock is acquired or until the specified timeout expires. If the timeout expired without acquiring the lock, the LockedPtr will be null, and LockedPtr::isNull() will return true.

Definition at line 1337 of file Synchronized.h.

References folly::pushmi::__adl::noexcept(), and folly::detail::rhs.

1340  : Base(parent, timeout) {}
LockedPtrBase< SynchronizedType, typename SynchronizedType::MutexType, LockPolicy > Base
folly::Function< void()> parent
Definition: AtFork.cpp:34
template<class SynchronizedType, class LockPolicy>
folly::LockedPtr< SynchronizedType, LockPolicy >::LockedPtr ( LockedPtr< SynchronizedType, LockPolicy > &&  rhs)
defaultnoexcept

Move constructor.

template<class SynchronizedType, class LockPolicy>
template<typename LockPolicyType , EnableIfSameUnlockPolicy< LockPolicyType > * = nullptr>
folly::LockedPtr< SynchronizedType, LockPolicy >::LockedPtr ( LockedPtr< SynchronizedType, LockPolicyType > &&  other)
inlinenoexcept

Definition at line 1349 of file Synchronized.h.

References folly::gen::move, folly::pushmi::__adl::noexcept(), and folly::detail::rhs.

1350  : Base{std::move(other)} {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
LockedPtrBase< SynchronizedType, typename SynchronizedType::MutexType, LockPolicy > Base
template<class SynchronizedType, class LockPolicy>
folly::LockedPtr< SynchronizedType, LockPolicy >::LockedPtr ( const LockedPtr< SynchronizedType, LockPolicy > &  rhs)
delete
template<class SynchronizedType, class LockPolicy>
folly::LockedPtr< SynchronizedType, LockPolicy >::~LockedPtr ( )
inline

Destructor releases.

Definition at line 1374 of file Synchronized.h.

1374 {}

Member Function Documentation

template<class SynchronizedType, class LockPolicy>
bool folly::LockedPtr< SynchronizedType, LockPolicy >::isNull ( ) const
inline

Check if this LockedPtr is uninitialized, or points to valid locked data.

This method can be used to check if a timed-acquire operation succeeded. If an acquire operation times out it will result in a null LockedPtr.

A LockedPtr is always either null, or holds a lock to valid data. Methods such as scopedUnlock() reset the LockedPtr to null for the duration of the unlock.

Definition at line 1386 of file Synchronized.h.

1386  {
1387  return this->parent_ == nullptr;
1388  }
template<class SynchronizedType, class LockPolicy>
template<typename SyncType = SynchronizedType, typename = typename std::enable_if< LockTraits<typename SyncType::MutexType>::is_upgrade>::type>
LockedPtr<SynchronizedType, LockPolicyFromUpgradeToShared> folly::LockedPtr< SynchronizedType, LockPolicy >::moveFromUpgradeToRead ( )
inline

Move the locked ptr from an upgrade state to a shared state. The current lock is left in a null state.

Definition at line 1469 of file Synchronized.h.

References folly::exchange(), and type.

1469  {
1470  return LockedPtr<SynchronizedType, LockPolicyFromUpgradeToShared>(
1471  exchange(this->parent_, nullptr));
1472  }
T exchange(T &obj, U &&new_value)
Definition: Utility.h:120
template<class SynchronizedType, class LockPolicy>
template<typename SyncType = SynchronizedType, typename = typename std::enable_if< LockTraits<typename SyncType::MutexType>::is_upgrade>::type>
LockedPtr<SynchronizedType, LockPolicyFromUpgradeToExclusive> folly::LockedPtr< SynchronizedType, LockPolicy >::moveFromUpgradeToWrite ( )
inline

Move the locked ptr from an upgrade state to an exclusive state. The current lock is left in a null state.

Definition at line 1441 of file Synchronized.h.

References folly::exchange(), and type.

1441  {
1442  return LockedPtr<SynchronizedType, LockPolicyFromUpgradeToExclusive>(
1443  exchange(this->parent_, nullptr));
1444  }
T exchange(T &obj, U &&new_value)
Definition: Utility.h:120
template<class SynchronizedType, class LockPolicy>
template<typename SyncType = SynchronizedType, typename = typename std::enable_if< LockTraits<typename SyncType::MutexType>::is_upgrade>::type>
LockedPtr<SynchronizedType, LockPolicyFromExclusiveToShared> folly::LockedPtr< SynchronizedType, LockPolicy >::moveFromWriteToRead ( )
inline

Move the locked ptr from an exclusive state to a shared state. The current lock is left in a null state.

Definition at line 1483 of file Synchronized.h.

References testing::Args(), D, folly::exchange(), and M.

1483  {
1484  return LockedPtr<SynchronizedType, LockPolicyFromExclusiveToShared>(
1485  exchange(this->parent_, nullptr));
1486  }
T exchange(T &obj, U &&new_value)
Definition: Utility.h:120
template<class SynchronizedType, class LockPolicy>
template<typename SyncType = SynchronizedType, typename = typename std::enable_if< LockTraits<typename SyncType::MutexType>::is_upgrade>::type>
LockedPtr<SynchronizedType, LockPolicyFromExclusiveToUpgrade> folly::LockedPtr< SynchronizedType, LockPolicy >::moveFromWriteToUpgrade ( )
inline

Move the locked ptr from an exclusive state to an upgrade state. The current lock is left in a null state.

Definition at line 1455 of file Synchronized.h.

References folly::exchange(), and type.

1455  {
1456  return LockedPtr<SynchronizedType, LockPolicyFromExclusiveToUpgrade>(
1457  exchange(this->parent_, nullptr));
1458  }
T exchange(T &obj, U &&new_value)
Definition: Utility.h:120
template<class SynchronizedType, class LockPolicy>
folly::LockedPtr< SynchronizedType, LockPolicy >::operator bool ( ) const
inlineexplicit

Explicit boolean conversion.

Returns !isNull()

Definition at line 1395 of file Synchronized.h.

1395  {
1396  return this->parent_ != nullptr;
1397  }
template<class SynchronizedType, class LockPolicy>
CDataType& folly::LockedPtr< SynchronizedType, LockPolicy >::operator* ( ) const
inline

Access the locked data.

This method should only be used if the LockedPtr is valid.

Definition at line 1413 of file Synchronized.h.

1413  {
1414  return this->parent_->datum_;
1415  }
template<class SynchronizedType, class LockPolicy>
CDataType* folly::LockedPtr< SynchronizedType, LockPolicy >::operator-> ( ) const
inline

Access the locked data.

This method should only be used if the LockedPtr is valid.

Definition at line 1404 of file Synchronized.h.

1404  {
1405  return &this->parent_->datum_;
1406  }
template<class SynchronizedType, class LockPolicy>
LockedPtr& folly::LockedPtr< SynchronizedType, LockPolicy >::operator= ( LockedPtr< SynchronizedType, LockPolicy > &&  rhs)
defaultnoexcept

Move assignment operator.

template<class SynchronizedType, class LockPolicy>
template<typename LockPolicyType , EnableIfSameUnlockPolicy< LockPolicyType > * = nullptr>
LockedPtr& folly::LockedPtr< SynchronizedType, LockPolicy >::operator= ( LockedPtr< SynchronizedType, LockPolicyType > &&  other)
inlinenoexcept

Definition at line 1359 of file Synchronized.h.

References folly::gen::move, and folly::detail::rhs.

1360  {
1361  Base::operator=(std::move(other));
1362  return *this;
1363  }
LockedPtrBase & operator=(LockedPtrBase &&rhs) noexcept
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class SynchronizedType, class LockPolicy>
LockedPtr& folly::LockedPtr< SynchronizedType, LockPolicy >::operator= ( const LockedPtr< SynchronizedType, LockPolicy > &  rhs)
delete
template<class SynchronizedType, class LockPolicy>
ScopedUnlocker<SynchronizedType, LockPolicy> folly::LockedPtr< SynchronizedType, LockPolicy >::scopedUnlock ( )
inline

Temporarily unlock the LockedPtr, and reset it to null.

Returns an helper object that will re-lock and restore the LockedPtr when the helper is destroyed. The LockedPtr may not be dereferenced for as long as this helper object exists.

Definition at line 1424 of file Synchronized.h.

References type.

1424  {
1426  }
friend class ScopedUnlocker< SynchronizedType, LockPolicy >

Friends And Related Function Documentation

template<class SynchronizedType, class LockPolicy>
template<typename SynchronizedTypeOther , typename LockPolicyOther >
friend class LockedPtr
friend

Definition at line 1308 of file Synchronized.h.

template<class SynchronizedType, class LockPolicy>
friend class ScopedUnlocker< SynchronizedType, LockPolicy >
friend

Definition at line 1314 of file Synchronized.h.


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