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

#include <Synchronized.h>

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

Public Types

using UpgradeLockedPtr = ::folly::LockedPtr< Subclass, LockPolicyUpgrade >
 
using ConstUpgradeLockedPtr = ::folly::LockedPtr< const Subclass, LockPolicyUpgrade >
 
using TryUpgradeLockedPtr = ::folly::LockedPtr< Subclass, LockPolicyTryUpgrade >
 
using ConstTryUpgradeLockedPtr = ::folly::LockedPtr< const Subclass, LockPolicyTryUpgrade >
 
- Public Types inherited from folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED >
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

UpgradeLockedPtr ulock ()
 
TryUpgradeLockedPtr tryULock ()
 
template<class Rep , class Period >
UpgradeLockedPtr ulock (const std::chrono::duration< Rep, Period > &timeout)
 
template<class Function >
auto withULock (Function &&function)
 
template<class Function >
auto withULockPtr (Function &&function)
 
- Public Member Functions inherited from folly::SynchronizedBase< Subclass, detail::MutexLevel::SHARED >
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::UPGRADE >

SynchronizedBase specialization for upgrade mutex types.

This class provides all the functionality provided by the SynchronizedBase specialization for shared mutexes and a ulock() method that returns an upgradable lock RAII proxy

Definition at line 220 of file Synchronized.h.

Member Typedef Documentation

Definition at line 230 of file Synchronized.h.

template<class Subclass >
using folly::SynchronizedBase< Subclass, detail::MutexLevel::UPGRADE >::ConstUpgradeLockedPtr = ::folly::LockedPtr<const Subclass, LockPolicyUpgrade>

Definition at line 225 of file Synchronized.h.

Definition at line 228 of file Synchronized.h.

template<class Subclass >
using folly::SynchronizedBase< Subclass, detail::MutexLevel::UPGRADE >::UpgradeLockedPtr = ::folly::LockedPtr<Subclass, LockPolicyUpgrade>

Definition at line 223 of file Synchronized.h.

Member Function Documentation

template<class Subclass >
TryUpgradeLockedPtr folly::SynchronizedBase< Subclass, detail::MutexLevel::UPGRADE >::tryULock ( )
inline

Attempts to acquire the lock in upgrade 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 249 of file Synchronized.h.

249  {
250  return TryUpgradeLockedPtr{static_cast<Subclass*>(this)};
251  }
::folly::LockedPtr< Subclass, LockPolicyTryUpgrade > TryUpgradeLockedPtr
Definition: Synchronized.h:228
template<class Subclass >
UpgradeLockedPtr folly::SynchronizedBase< Subclass, detail::MutexLevel::UPGRADE >::ulock ( )
inline

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

And the const version

Definition at line 238 of file Synchronized.h.

238  {
239  return UpgradeLockedPtr(static_cast<Subclass*>(this));
240  }
::folly::LockedPtr< Subclass, LockPolicyUpgrade > UpgradeLockedPtr
Definition: Synchronized.h:223
template<class Subclass >
template<class Rep , class Period >
UpgradeLockedPtr folly::SynchronizedBase< Subclass, detail::MutexLevel::UPGRADE >::ulock ( const std::chrono::duration< Rep, Period > &  timeout)
inline

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

And the const version

Definition at line 260 of file Synchronized.h.

260  {
261  return UpgradeLockedPtr(static_cast<Subclass*>(this), timeout);
262  }
::folly::LockedPtr< Subclass, LockPolicyUpgrade > UpgradeLockedPtr
Definition: Synchronized.h:223
template<class Subclass >
template<class Function >
auto folly::SynchronizedBase< Subclass, detail::MutexLevel::UPGRADE >::withULock ( Function &&  function)
inline

Invoke a function while holding the lock.

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.withULock([](auto& data) { data.doStuff(); return data.getValue(); });

This is probably not the function you want. If the intent is to read the data object and determine whether you should upgrade to a write lock then the withULockPtr() method should be called instead, since it gives access to the LockedPtr proxy (which can be upgraded via the moveFromUpgradeToWrite() method)

Definition at line 285 of file Synchronized.h.

References folly::ulock().

285  {
286  return function(*ulock());
287  }
template<class Subclass >
template<class Function >
auto folly::SynchronizedBase< Subclass, detail::MutexLevel::UPGRADE >::withULockPtr ( Function &&  function)
inline

Invoke a function while holding the lock exclusively.

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

This allows scopedUnlock() and getUniqueLock() to be called on the LockedPtr argument.

This also allows you to upgrade the LockedPtr proxy to a write state so that changes can be made to the underlying data

Definition at line 302 of file Synchronized.h.

References folly::ulock().

302  {
303  return function(ulock());
304  }

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