Template Class Synchronised

Nested Relationships

Nested Types

Class Documentation

template<typename T>
class Synchronised

An object that enforces unique access to the data it contains.

This behaves like a mutex which owns the data it guards, and can give out a smart-pointer-esque handle to lock and access it.

Template Parameters:

T – The type of data contained

Public Types

using Locked = LockedImpl<T>

Smart-pointer-esque accessor for the protected data.

Ensures exclusive access to the referenced data.

Note

Instances of Locked must not outlive the Synchronised they are derived from.

using LockedView = LockedImpl<T const>

Smart-pointer-esque accessor for the protected data.

Provides const access to the protected data, with the guarantee that no changes to the data can be made while this handle is live.

Note

Instances of Locked must not outlive the Synchronised they are derived from.

Public Functions

Synchronised() = default
inline Synchronised(T &&initial_value)
Synchronised(Synchronised const&) = delete
Synchronised &operator=(Synchronised const&) = delete
inline auto lock() -> Locked

Lock the data and return an accessor.

Returns:

A smart-pointer-esque accessor for the contained data. While code has access to a live Locked instance it is guaranteed to have unique access to the contained data.

inline auto lock() const -> LockedView

Lock the data and return an accessor.

Returns:

A smart-pointer-esque accessor for the contained data. While code has access to a live Locked instance it is guaranteed to have unique access to the contained data.

template<typename U>
class LockedImpl

Smart-pointer-esque accessor for the protected data.

Ensures exclusive access to the referenced data.

Note

Instances of Locked must not outlive the Synchronised they are derived from.

Public Functions

inline LockedImpl(LockedImpl &&from) noexcept
~LockedImpl() = default
inline auto operator*() const -> U&
inline auto operator->() const -> U*
inline void drop()

Relinquish access to the data.

This prevents further access to the contained data through this handle, and allows other code to acquire access.

template<typename Cv, typename Predicate>
inline void wait(Cv &cv, Predicate stop_waiting)

Allows waiting for a condition variable.

The protected data may be accessed both in the predicate and after this method completes.