folly::Synchronized pairs a datum with a mutex. The datum can only be reached through a LockedPtr, typically acquired via .rlock() or .wlock(); the mutex is held for the lifetime of the LockedPtr.
Synopsis
Declared in <folly/Synchronized.h>
template<
class T,
class Mutex = SharedMutex>
struct Synchronized
: SynchronizedBase<Synchronized<T, Mutex>, detail::kSynchronizedMutexLevel<Mutex>>
Description
It is recommended to explicitly open a new nested scope when aquiring a LockedPtr object, to help visibly delineate the critical section and to ensure that the LockedPtr is destroyed as soon as it is no longer needed.
refcode folly/docs/examples/folly/Synchronized.cpp
Base Classes
Name |
Description |
|
SynchronizedBase is a helper parent class for Synchronized<T>. |
Type Aliases
Name |
Description |
Pointer type that holds a shared lock on the datum. |
|
The type of the guarded datum. |
|
Pointer type that holds an exclusive lock on the datum. |
|
The type of the mutex guarding the datum. |
Member Functions
Name |
Description |
|
Constructors |
Assignment operators |
|
|
|
|
|
Returns a fresh copy of the datum. |
|
Copies datum to a given target. |
|
Exchange datum. |
|
|
|
|
|
Access underlying mutex_ directly. |
|
|
Friends
Name |
Description |
A LockedPtr keeps a Synchronized<T> object locked for the duration of LockedPtr's existence. |
|
Base class that owns the lock held by a |
Non-Member Functions
Name |
Description |
Make an exclusive locking helper for a const object. |
|
Make an exclusive locking helper. |
|
Make a shared locking helper for a const object. |
|
Swap the data held by two |
|
Make an upgrade locking helper. |
|
Make an exclusive locking helper for a const object. |
|
Helper functions that should be passed to either a lock() or synchronized() invocation, these return implementation defined structs that will be used to lock the synchronized instance appropriately. |
Derived Classes
Name |
Description |
|
Deprecated subclass of Synchronized that provides implicit locking via operator‐>. This is intended to ease migration while preventing accidental use of operator‐> in new code. |
Template Parameters
Name |
Description |
T |
The type of datum to be stored. |
Mutex |
The mutex type that guards the datum. Must be Lockable. |
Created with MrDocs