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

#include <Synchronized.h>

Public Types

using LockedPtr = ::folly::LockedPtr< Subclass, LockPolicyExclusive >
 
using ConstLockedPtr = ::folly::LockedPtr< const Subclass, LockPolicyExclusive >
 
using TryLockedPtr = ::folly::LockedPtr< Subclass, LockPolicyTryExclusive >
 
using ConstTryLockedPtr = ::folly::LockedPtr< const Subclass, LockPolicyTryExclusive >
 

Public Member Functions

LockedPtr lock ()
 
ConstLockedPtr lock () const
 
TryLockedPtr tryLock ()
 
ConstTryLockedPtr tryLock () const
 
template<class Rep , class Period >
LockedPtr lock (const std::chrono::duration< Rep, Period > &timeout)
 
template<class Rep , class Period >
ConstLockedPtr lock (const std::chrono::duration< Rep, Period > &timeout) const
 
template<class Function >
auto withLock (Function &&function)
 
template<class Function >
auto withLock (Function &&function) const
 
template<class Function >
auto withLockPtr (Function &&function)
 
template<class Function >
auto withLockPtr (Function &&function) const
 

Detailed Description

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

SynchronizedBase specialization for non-shared mutex types.

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

Definition at line 314 of file Synchronized.h.

Member Typedef Documentation

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

Definition at line 318 of file Synchronized.h.

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

Definition at line 322 of file Synchronized.h.

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

Definition at line 316 of file Synchronized.h.

template<class Subclass >
using folly::SynchronizedBase< Subclass, detail::MutexLevel::UNIQUE >::TryLockedPtr = ::folly::LockedPtr<Subclass, LockPolicyTryExclusive>

Definition at line 320 of file Synchronized.h.

Member Function Documentation

template<class Subclass >
LockedPtr folly::SynchronizedBase< Subclass, detail::MutexLevel::UNIQUE >::lock ( )
inline

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

Definition at line 328 of file Synchronized.h.

328  {
329  return LockedPtr(static_cast<Subclass*>(this));
330  }
::folly::LockedPtr< Subclass, LockPolicyExclusive > LockedPtr
Definition: Synchronized.h:316
template<class Subclass >
ConstLockedPtr folly::SynchronizedBase< Subclass, detail::MutexLevel::UNIQUE >::lock ( ) const
inline

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

Definition at line 336 of file Synchronized.h.

336  {
337  return ConstLockedPtr(static_cast<const Subclass*>(this));
338  }
::folly::LockedPtr< const Subclass, LockPolicyExclusive > ConstLockedPtr
Definition: Synchronized.h:318
template<class Subclass >
template<class Rep , class Period >
LockedPtr folly::SynchronizedBase< Subclass, detail::MutexLevel::UNIQUE >::lock ( 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.

Definition at line 359 of file Synchronized.h.

359  {
360  return LockedPtr(static_cast<Subclass*>(this), timeout);
361  }
::folly::LockedPtr< Subclass, LockPolicyExclusive > LockedPtr
Definition: Synchronized.h:316
template<class Subclass >
template<class Rep , class Period >
ConstLockedPtr folly::SynchronizedBase< Subclass, detail::MutexLevel::UNIQUE >::lock ( 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.

Definition at line 368 of file Synchronized.h.

368  {
369  return ConstLockedPtr(static_cast<const Subclass*>(this), timeout);
370  }
::folly::LockedPtr< const Subclass, LockPolicyExclusive > ConstLockedPtr
Definition: Synchronized.h:318
template<class Subclass >
TryLockedPtr folly::SynchronizedBase< Subclass, detail::MutexLevel::UNIQUE >::tryLock ( )
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 347 of file Synchronized.h.

347  {
348  return TryLockedPtr{static_cast<Subclass*>(this)};
349  }
::folly::LockedPtr< Subclass, LockPolicyTryExclusive > TryLockedPtr
Definition: Synchronized.h:320
template<class Subclass >
ConstTryLockedPtr folly::SynchronizedBase< Subclass, detail::MutexLevel::UNIQUE >::tryLock ( ) const
inline

Definition at line 350 of file Synchronized.h.

350  {
351  return ConstTryLockedPtr{static_cast<const Subclass*>(this)};
352  }
::folly::LockedPtr< const Subclass, LockPolicyTryExclusive > ConstTryLockedPtr
Definition: Synchronized.h:322
template<class Subclass >
template<class Function >
auto folly::SynchronizedBase< Subclass, detail::MutexLevel::UNIQUE >::withLock ( 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.withLock([](auto& data) { data.doStuff(); return data.getValue(); });

Definition at line 387 of file Synchronized.h.

References folly::lock().

387  {
388  return function(*lock());
389  }
template<class Subclass >
template<class Function >
auto folly::SynchronizedBase< Subclass, detail::MutexLevel::UNIQUE >::withLock ( Function &&  function) const
inline

Definition at line 391 of file Synchronized.h.

References folly::lock().

391  {
392  return function(*lock());
393  }
template<class Subclass >
template<class Function >
auto folly::SynchronizedBase< Subclass, detail::MutexLevel::UNIQUE >::withLockPtr ( 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() and getUniqueLock() to be called on the LockedPtr argument.

Definition at line 405 of file Synchronized.h.

References folly::lock().

405  {
406  return function(lock());
407  }
template<class Subclass >
template<class Function >
auto folly::SynchronizedBase< Subclass, detail::MutexLevel::UNIQUE >::withLockPtr ( Function &&  function) const
inline

Definition at line 409 of file Synchronized.h.

References folly::lock().

409  {
410  return function(lock());
411  }

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