proxygen
folly::LockedPtrBase< SynchronizedType, std::mutex, LockPolicy > Class Template Reference

#include <Synchronized.h>

Public Types

using MutexType = std::mutex
 

Public Member Functions

 ~LockedPtrBase ()
 
 LockedPtrBase (LockedPtrBase &&rhs) noexcept
 
LockedPtrBaseoperator= (LockedPtrBase &&rhs) noexcept
 
template<typename LockPolicyType >
 LockedPtrBase (LockedPtrBase< SynchronizedType, std::mutex, LockPolicyType > &&other) noexcept
 
template<typename LockPolicyType >
LockedPtrBaseoperator= (LockedPtrBase< SynchronizedType, std::mutex, LockPolicyType > &&rhs) noexcept
 
template<typename LockPolicyLhs , typename LockPolicyRhs >
void assignImpl (LockedPtrBase< SynchronizedType, std::mutex, LockPolicyLhs > &lhs, LockedPtrBase< SynchronizedType, std::mutex, LockPolicyRhs > &rhs) noexcept
 
std::unique_lock< std::mutex > & getUniqueLock ()
 
void unlock ()
 

Protected Types

using UnlockerData = std::pair< std::unique_lock< std::mutex >, SynchronizedType * >
 

Protected Member Functions

 LockedPtrBase ()
 
 LockedPtrBase (SynchronizedType *parent)
 
UnlockerData releaseLock ()
 
void reacquireLock (UnlockerData &&data)
 

Static Protected Member Functions

static SynchronizedType * getSynchronized (const UnlockerData &data)
 

Protected Attributes

std::unique_lock< std::mutexlock_
 
SynchronizedType * parent_ = nullptr
 

Friends

class folly::ScopedUnlocker< SynchronizedType, LockPolicy >
 
template<typename S , typename L >
class folly::LockedPtr
 
template<typename S , typename M , typename L >
class LockedPtrBase
 

Detailed Description

template<class SynchronizedType, class LockPolicy>
class folly::LockedPtrBase< SynchronizedType, std::mutex, LockPolicy >

LockedPtrBase specialization for use with std::mutex.

When std::mutex is used we use a std::unique_lock to hold the mutex. This makes it possible to use std::condition_variable with a Synchronized<T, std::mutex>.

Definition at line 1119 of file Synchronized.h.

Member Typedef Documentation

template<class SynchronizedType , class LockPolicy >
using folly::LockedPtrBase< SynchronizedType, std::mutex, LockPolicy >::MutexType = std::mutex

Definition at line 1121 of file Synchronized.h.

template<class SynchronizedType , class LockPolicy >
using folly::LockedPtrBase< SynchronizedType, std::mutex, LockPolicy >::UnlockerData = std::pair<std::unique_lock<std::mutex>, SynchronizedType*>
protected

Definition at line 1218 of file Synchronized.h.

Constructor & Destructor Documentation

template<class SynchronizedType , class LockPolicy >
folly::LockedPtrBase< SynchronizedType, std::mutex, LockPolicy >::~LockedPtrBase ( )
inline

Destructor releases.

Definition at line 1135 of file Synchronized.h.

1135  {
1136  // The std::unique_lock will automatically release the lock when it is
1137  // destroyed, so we don't need to do anything extra here.
1138  }
template<class SynchronizedType , class LockPolicy >
folly::LockedPtrBase< SynchronizedType, std::mutex, LockPolicy >::LockedPtrBase ( LockedPtrBase< SynchronizedType, std::mutex, LockPolicy > &&  rhs)
inlinenoexcept

Definition at line 1140 of file Synchronized.h.

References folly::exchange(), folly::gen::move, and folly::detail::rhs.

1141  : lock_{std::move(rhs.lock_)}, parent_{exchange(rhs.parent_, nullptr)} {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
FOLLY_PUSH_WARNING RHS rhs
Definition: Traits.h:649
T exchange(T &obj, U &&new_value)
Definition: Utility.h:120
template<class SynchronizedType , class LockPolicy >
template<typename LockPolicyType >
folly::LockedPtrBase< SynchronizedType, std::mutex, LockPolicy >::LockedPtrBase ( LockedPtrBase< SynchronizedType, std::mutex, LockPolicyType > &&  other)
inlinenoexcept

Templated move construct and assignment operators

These allow converting LockedPtr types that have the same unlocking policy to each other.

Definition at line 1154 of file Synchronized.h.

References folly::exchange(), and folly::gen::move.

1156  : lock_{std::move(other.lock_)},
1157  parent_{exchange(other.parent_, nullptr)} {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
T exchange(T &obj, U &&new_value)
Definition: Utility.h:120
template<class SynchronizedType , class LockPolicy >
folly::LockedPtrBase< SynchronizedType, std::mutex, LockPolicy >::LockedPtrBase ( )
inlineprotected

Definition at line 1207 of file Synchronized.h.

1207 {}
template<class SynchronizedType , class LockPolicy >
folly::LockedPtrBase< SynchronizedType, std::mutex, LockPolicy >::LockedPtrBase ( SynchronizedType *  parent)
inlineexplicitprotected

Definition at line 1208 of file Synchronized.h.

References folly::lock(), and parent.

1209  : lock_{parent->mutex_, std::adopt_lock}, parent_{parent} {
1210  DCHECK(parent);
1211  if (!LockPolicy::lock(parent_->mutex_)) {
1212  parent_ = nullptr;
1213  lock_.release();
1214  }
1215  }
void lock(LockableOne &one, LockableTwo &two, Lockables &...lockables)
folly::Function< void()> parent
Definition: AtFork.cpp:34

Member Function Documentation

template<class SynchronizedType , class LockPolicy >
template<typename LockPolicyLhs , typename LockPolicyRhs >
void folly::LockedPtrBase< SynchronizedType, std::mutex, LockPolicy >::assignImpl ( LockedPtrBase< SynchronizedType, std::mutex, LockPolicyLhs > &  lhs,
LockedPtrBase< SynchronizedType, std::mutex, LockPolicyRhs > &  rhs 
)
inlinenoexcept

Implementation for the assignment operator

Definition at line 1170 of file Synchronized.h.

References folly::exchange(), folly::gen::move, and folly::detail::rhs.

1173  {
1174  lhs.lock_ = std::move(rhs.lock_);
1175  lhs.parent_ = exchange(rhs.parent_, nullptr);
1176  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
FOLLY_PUSH_WARNING RHS rhs
Definition: Traits.h:649
T exchange(T &obj, U &&new_value)
Definition: Utility.h:120
template<class SynchronizedType , class LockPolicy >
static SynchronizedType* folly::LockedPtrBase< SynchronizedType, std::mutex, LockPolicy >::getSynchronized ( const UnlockerData data)
inlinestaticprotected

Definition at line 1220 of file Synchronized.h.

1220  {
1221  return data.second;
1222  }
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
template<class SynchronizedType , class LockPolicy >
std::unique_lock<std::mutex>& folly::LockedPtrBase< SynchronizedType, std::mutex, LockPolicy >::getUniqueLock ( )
inline

Get a reference to the std::unique_lock.

This is provided so that callers can use Synchronized<T, std::mutex> with a std::condition_variable.

While this API could be used to bypass the normal Synchronized APIs and manually interact with the underlying unique_lock, this is strongly discouraged.

Definition at line 1188 of file Synchronized.h.

1188  {
1189  return lock_;
1190  }
template<class SynchronizedType , class LockPolicy >
LockedPtrBase& folly::LockedPtrBase< SynchronizedType, std::mutex, LockPolicy >::operator= ( LockedPtrBase< SynchronizedType, std::mutex, LockPolicy > &&  rhs)
inlinenoexcept

Definition at line 1142 of file Synchronized.h.

References folly::detail::rhs.

1142  {
1143  assignImpl(*this, rhs);
1144  return *this;
1145  }
void assignImpl(LockedPtrBase< SynchronizedType, std::mutex, LockPolicyLhs > &lhs, LockedPtrBase< SynchronizedType, std::mutex, LockPolicyRhs > &rhs) noexcept
FOLLY_PUSH_WARNING RHS rhs
Definition: Traits.h:649
template<class SynchronizedType , class LockPolicy >
template<typename LockPolicyType >
LockedPtrBase& folly::LockedPtrBase< SynchronizedType, std::mutex, LockPolicy >::operator= ( LockedPtrBase< SynchronizedType, std::mutex, LockPolicyType > &&  rhs)
inlinenoexcept

Definition at line 1159 of file Synchronized.h.

References folly::detail::rhs.

1161  {
1162  assignImpl(*this, rhs);
1163  return *this;
1164  }
void assignImpl(LockedPtrBase< SynchronizedType, std::mutex, LockPolicyLhs > &lhs, LockedPtrBase< SynchronizedType, std::mutex, LockPolicyRhs > &rhs) noexcept
FOLLY_PUSH_WARNING RHS rhs
Definition: Traits.h:649
template<class SynchronizedType , class LockPolicy >
void folly::LockedPtrBase< SynchronizedType, std::mutex, LockPolicy >::reacquireLock ( UnlockerData &&  data)
inlineprotected

Definition at line 1231 of file Synchronized.h.

References folly::data(), and folly::gen::move.

1231  {
1232  lock_ = std::move(data.first);
1233  lock_.lock();
1234  parent_ = data.second;
1235  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
template<class SynchronizedType , class LockPolicy >
UnlockerData folly::LockedPtrBase< SynchronizedType, std::mutex, LockPolicy >::releaseLock ( )
inlineprotected

Definition at line 1224 of file Synchronized.h.

References folly::data(), and folly::gen::move.

1224  {
1225  DCHECK(parent_ != nullptr);
1227  parent_ = nullptr;
1228  data.first.unlock();
1229  return data;
1230  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
std::pair< std::unique_lock< std::mutex >, SynchronizedType * > UnlockerData
template<class SynchronizedType , class LockPolicy >
void folly::LockedPtrBase< SynchronizedType, std::mutex, LockPolicy >::unlock ( )
inline

Unlock the synchronized data.

The LockedPtr can no longer be dereferenced after unlock() has been called. isValid() will return false on an unlocked LockedPtr.

unlock() can only be called on a LockedPtr that is valid.

Definition at line 1200 of file Synchronized.h.

1200  {
1201  DCHECK(parent_ != nullptr);
1202  lock_.unlock();
1203  parent_ = nullptr;
1204  }

Friends And Related Function Documentation

template<class SynchronizedType , class LockPolicy >
template<typename S , typename L >
friend class folly::LockedPtr
friend

Friend all instantiations of LockedPtr and LockedPtrBase

Definition at line 1128 of file Synchronized.h.

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

Definition at line 1122 of file Synchronized.h.

template<class SynchronizedType , class LockPolicy >
template<typename S , typename M , typename L >
friend class LockedPtrBase
friend

Definition at line 1130 of file Synchronized.h.

Member Data Documentation

template<class SynchronizedType , class LockPolicy >
std::unique_lock<std::mutex> folly::LockedPtrBase< SynchronizedType, std::mutex, LockPolicy >::lock_
protected

Definition at line 1239 of file Synchronized.h.

template<class SynchronizedType , class LockPolicy >
SynchronizedType* folly::LockedPtrBase< SynchronizedType, std::mutex, LockPolicy >::parent_ = nullptr
protected

Definition at line 1240 of file Synchronized.h.


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