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>

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<Synchronized<T, Mutex>, detail::kSynchronizedMutexLevel<Mutex>>

SynchronizedBase is a helper parent class for Synchronized<T>.

Type Aliases

Name

Description

ConstLockedPtr

Pointer type that holds a shared lock on the datum.

DataType

The type of the guarded datum.

LockedPtr

Pointer type that holds an exclusive lock on the datum.

MutexType

The type of the mutex guarding the datum.

Member Functions

Name

Description

Synchronized [constructor]

Constructors

operator=

Assignment operators

contextualLock

contextualLock overloads

contextualRLock

contextualRLock overloads

copy

Returns a fresh copy of the datum.

copyInto

Copies datum to a given target.

exchange

Exchange datum.

swap

swap overloads

timedAcquire

timedAcquire overloads

unsafeGetMutex

Access underlying mutex_ directly.

unsafeGetUnlocked

unsafeGetUnlocked overloads

Friends

Name

Description

folly::LockedPtr

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

folly::LockedPtrBase

Base class that owns the lock held by a LockedPtr.

Non-Member Functions

Name

Description

lock

Make an exclusive locking helper for a const object.

lock

Make an exclusive locking helper.

rlock

Make a shared locking helper for a const object.

swap

Swap the data held by two Synchronized objects.

ulock

Make an upgrade locking helper.

wlock

Make an exclusive locking helper for a const object.

wlock

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

ImplicitSynchronized [deprecated]

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