folly::coro::Synchronized

This class is an adaptation of the folly::Synchronized class but is designed to work with coro-compatible mutexes like coro::SharedMutexFair instead.

Synopsis

Declared in <folly/coro/Synchronized.h>

template<
    typename Inner,
    typename CoroMutexType = SharedMutexFair,
    typename CoroMutexTraits = /* implementation-defined */>
class Synchronized
    : public moveonly_::NonCopyableNonMovable

Description

In practice what this means is that we can co_await gaining the read/write lock rather than blocking whilst acquiring it.

The API is not a complete clone of everything that folly::Synchronized supports but is instead the minimum of what we need. Ultimately this classes main job is to abstract away gaining the locks.

Base Classes

NameDescription
moveonly_::NonCopyableNonMovableDisallow copy and move for derived types. This is essentially boost::noncopyable (the implementation is almost identical), except it has public methods, enabling aggregate initialization.

Types

NameDescription
GenericLockedPtr A RAII wrapper around a pointer to the underlying object together with a lock on the underlying mutex.

Type Aliases

NameDescription
CoroMutex The coro-compatible mutex type guarding the object.
ReadLock The lock type used for shared (read) access.
ReadLockedPtr A locked pointer granting read-only access to the guarded object.
Traits The traits describing how to lock and unlock the coro-compatible mutex.
WriteLock The lock type used for exclusive (write) access.
WriteLockedPtr A locked pointer granting read-write access to the guarded object.
rlock_result_t The result of invoking FuncT with a read-locked pointer.
wlock_result_t The result of invoking FuncT with a write-locked pointer.

Member Functions

NameDescription
Synchronized [constructor]Constructors
operator= Assignment operators
copy Returns a copy of the guarded object made while holding the read lock.
rLock Asynchronously acquires the read lock.
swap swap overloads
tryRLock Attempts to acquire the read lock without blocking.
tryWLock Attempts to acquire the write lock without blocking.
wLock Asynchronously acquires the write lock.
withRLock withRLock overloads
withWLock withWLock overloads